Formatting Issue with YAML Code in Visual Studio Text Editor

4,177 views
Skip to first unread message

Leon Khan

unread,
Aug 12, 2023, 10:45:18 AM8/12/23
to ansible...@googlegroups.com
Greetings everyone,

I hope you're doing well. I'm encountering an issue with formatting YAML source code in the Visual Studio text editor, and I'm seeking some assistance from the community.

I have installed the YAML extension in Visual Studio, and while it's expected to automatically correct the formatting of YAML code upon pasting, I'm finding that this feature isn't working as intended. Despite having the YAML extension installed, the automatic formatting does not kick in when I paste YAML source code into the text editor.

I've followed the recommended steps which include selecting the entire YAML file, right-clicking, and then choosing the "Format Document" option provided by the YAML extension. However, even after performing this action, the code formatting remains unchanged.

I'm eager to streamline my workflow and ensure consistent formatting within my YAML files, so this issue is causing a bit of a hurdle for me. I would greatly appreciate any insights, suggestions, or solutions that the community might be able to provide regarding this matter. Perhaps there's a configuration step or an additional setting that I'm missing?

Here is the screenshot of the YAML file in my VS code editor : 
Screenshot from 2023-08-12 11-43-58.png



--
Leon 
Fedora Open Source Volunteer
IRC Handle : leonkhan
"Contributing to open source, one line of code at a time."

Felix Fontein

unread,
Aug 12, 2023, 10:57:30 AM8/12/23
to ansible...@googlegroups.com
Hi,

what you are showing in the screenshot is not valid YAML. I guess the
reformatting feature of that YAML extension only reformats valid YAML.

So you first have to convert it to valid YAML, and then you can
reformat it.

Cheers,
Felix

Will McDonald

unread,
Aug 12, 2023, 7:59:54 PM8/12/23
to ansible...@googlegroups.com
I presume this is a 'Vscode being weird with ALL YAML' rather than Vscode being weird specifically with Ansible YAML. You might want to check something like a Vscode Stackoverflow and/or playing with your Vscode plugins and config? If you take a completely clean portable mode vscode, does is display the same problem? If not, it's your config, plugs or some lingering settings _somewhere_.

I can take some dummy YAML and paste into a completely vanilla Vscode install and it doesn't mess with the indentation at all:

---
- hosts: all
  become: yes

  tasks:
  - name: do some things
    dnf:
      name: packagename
      state: present

Can you run Vscode with all its plugins disabled and a completely default config just in case you have plugins and config trampling on one another's behaviours? (See: https://code.visualstudio.com/docs/editor/extension-marketplace#_disable-an-extension)



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFUWKdXPdY7dCxm7EiRrLKySwgOi7S19grzFajD60aAJw3w8gQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages