Formatting Issue with YAML Code in Visual Studio Text Editor

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 :

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

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: