aws-toolkit-vscode icon indicating copy to clipboard operation
aws-toolkit-vscode copied to clipboard

CloudFormation formatter does not respect chosen indentation

Open lionello opened this issue 1 month ago • 6 comments

https://github.com/aws/aws-toolkit-vscode/blob/22be93735bb20c22cefaef407ecfef7d7b7f72b9/packages/core/src/awsService/cloudformation/commands/cfnCommands.ts#L343

This is hardcoded to 2 regardless of the indentation chosen in the VSCode editor.

Expected

When I pick a certain indentation in VSCode, I expect the formatter to respect it.

Image

Actual

When formatting CloudFormation YAML file, the items are reindented using a "tab" size of 2, even when I selected indentation size 4. When I have all my CloudFormation YAMLs with a certain indentation size, enabling this VSCode extension suddenly changes the entire file, forcing me to enable/disable the extension to avoid unnecessary churn on files.

lionello avatar Nov 21 '25 23:11 lionello

Thanks for opening this issue @lionello . What is/was the value of your editor.detectIndentation setting?

Unfortunately the document level indentation setting (your screenshot), isn't conveyed to our language server via LSP, so we make do with our own dectection mechanism, but only if the editor.detectIdentation setting is set to true.

atennak1 avatar Nov 23 '25 17:11 atennak1

Thanks for opening this issue @lionello . What is/was the value of your editor.detectIndentation setting?

Unfortunately the document level indentation setting (your screenshot), isn't conveyed to our language server via LSP, so we make do with our own dectection mechanism, but only if the editor.detectIdentation setting is set to true.

Thanks @atennak1, it is set to true for me, but "format" still changed the indentation from 4 to 2:

Image

lionello avatar Nov 24 '25 21:11 lionello

Thanks @lionello . We'll try to reproduce this. Can you provide specifics about the actions you took? For example:

  1. Are these existing non-empty files?
  2. Is the indentation tabs or spaces?
  3. Did you run the format command? Or was the wrong indentation coming from autocomplete or code actions?

atennak1 avatar Nov 25 '25 00:11 atennak1

Steps:

  • Open a CloudFormation YAML file. This defaults to using the RedHat YAML LSP. My indention is set to 4 spaces.
  • Changing the language from generic YAML to CloudFormation updates the syntax highlighting. Image
  • Now, when I choose "Format Document" (or save w/ "Format on Save" set), the file gets reformatted with indentation set to 2 spaces, regardless of my setting.

lionello avatar Nov 25 '25 02:11 lionello

Interesting. When I change the language to CloudFormation, and run the Format Document (from the command palette), I get a There is no formatter for 'cloudformation' files installed. error. Which makes sense since our language server does not handle formatting yet.

@lionello , can you provide your VSCode version, AWS Toolkit version, and operating system?

atennak1 avatar Nov 25 '25 17:11 atennak1

Version: 1.107.0-insider Commit: b1018f0c37cb5dc62bba1665f6d2821fff098646 Date: 2025-11-25T14:17:19.499Z Electron: 39.2.3 ElectronBuildId: 12825439 Chromium: 142.0.7444.175 Node.js: 22.21.1 V8: 14.2.231.21-electron.0 OS: Darwin arm64 25.1.0

lionello avatar Nov 26 '25 14:11 lionello