ansible / vscode-ansible

vscode/vscodium extension for providing Ansible auto-completion and integrating quality assurance tools like ansible-lint, ansible syntax check, yamllint, molecule and ansible-test.
https://ansible.readthedocs.io/projects/vscode-ansible/
MIT License
362 stars 90 forks source link

Add document formatting feature OR set YAML extension's formatter on ansible playbooks. #1114

Open tabish-javed opened 8 months ago

tabish-javed commented 8 months ago

Problem

No formatter support on ansible playbooks in VS-Code.

Solution

Add formatter support to ansible's extension.

Alternatives

Tweak ansible extension to use YAML extension as default formatter.

Additional context

No response

priyamsahoo commented 8 months ago

This is a compatible issue with the YAML extension. We have default formatting set up in our extension, and we do not want to rely on the YAML extension to do it.

Having said that, you can always set up a default extension for ansible language and point it to the YAML extension or prettier. prettier seems to work well with the ansible language. If the YAML extension is not formatting it, you might have to raise an issue with their extension to support formatting for ansible language.

Here's how you can set up the formator. Add these to your settings configuration:

"[ansible]": {
    "editor.autoIndent": "advanced",
    "editor.defaultFormatter": "redhat.vscode-yaml",
    "editor.formatOnSave": true
  }
tabish-javed commented 7 months ago

@priyamsahoo - Thanks for the note!

Thanks!