question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

editor.formatOnSave is not working as expected

See original GitHub issue

Hey buddy!

First of all, congratulations for the extension! There’s only one thing that I suggest you to check, it’s the editor.formatOnSave. It’s not working as expected.

The file changed is ignored when saved. On the other hand, when we use Format Document command on VSCode, the file is correctly formatted.

vscode-terraform version: 1.3.12 Terraform version: 0.12.3 VSCode version 1.36.0

settings.json on VSCode

    "files.associations": {
        "*.ctmpl": "hcl",
        "*.tf": "terraform",
        "*.tfvars": "terraform"
    },

    "[terraform]": {
        "editor.formatOnSave": true
    }

Save file log:

2019-07-10 14:44:26:223 [INFO ] formatting-provider: running 'terraform fmt' on 'c:\Users\MyUser\Desktop\terraform_folder\terraformfile.tf'
2019-07-10 14:44:26:223 [INFO ] runner: Running terraform cwd='C:\Users\MyUser\AppData\Local\Programs\Microsoft VS Code' path='terraform' (version: 0.12.3) args=[fmt, -]
2019-07-10 14:44:27:041 [DEBUG] index-adapter: Ignoring document: file:///c%3A/Users/MyUser/Desktop/terraform_folder/terraformfile.tf
2019-07-10 14:44:32:349 [INFO ] runner: Running terraform succeeded.

Manual Alt Shift F (Format Document):

2019-07-10 14:54:50:445 [INFO ] formatting-provider: running 'terraform fmt' on 'c:\Users\MyUser\Desktop\terraform_folder\terraformfile.tf'
2019-07-10 14:54:50:445 [INFO ] runner: Running terraform cwd='C:\Users\MyUser\AppData\Local\Programs\Microsoft VS Code' path='terraform' (version: 0.12.3) args=[fmt, -]
2019-07-10 14:54:56:071 [INFO ] runner: Running terraform succeeded.
2019-07-10 14:54:56:089 [DEBUG] index-adapter: Ignoring document: file:///c%3A/Users/MyUser/Desktop/terraform_folder/terraformfile.tf

Could you kindly check this please?

Thank you.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
carlosescuracommented, Nov 28, 2019

I was experiencing the same issue starting with the latest update in vscode in which they changed the integration with prettier formater. My proposed solution assumes you also have prettier plugin istalled or any other formater as default.

My settings.json is configured as follows:

"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
  "[terraform]": {
    "editor.defaultFormatter": "mauve.terraform"
  }

With the last part, which overrides the formater for terraform language, my formating started to work again 😃

0reactions
ghostcommented, Jul 4, 2020

I’m going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the context necessary to investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Format on Save (prettier) stopped working with latest update
Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default...
Read more >
Why does Prettier not format code in VS Code? - Stack Overflow
Click on Preferences: Open Settings (JSON) from the suggestion dropdown. Inside the settings.json file, Check if "[html]" key exists. If the key ...
Read more >
How to enable auto format on save with prettier in VS Code ...
Explainer video about How to enable auto format on save in VS Code (Visual Studio Code) editor with prettier code formatter extension on...
Read more >
How to fix Prettier Extension not working issue in VS CODE
How to fix Prettier Extension not working issue in VS CODE. ... How to enable auto format on save with prettier in VS...
Read more >
prettier not working vscode Code Example
check "format on Save": Setting >> User >> Text Editor >> Formatting choose prettier as "default ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found