Giter Club home page Giter Club logo

Comments (19)

jacobwgillespie avatar jacobwgillespie commented on July 26, 2024 10

It looks like the terraform.formatOnSave setting was removed in favor of using the built-in editor.formatOnSave setting. If you want to enable format-on-save only for Terraform files, you can add the following to your user settings or workspace settings:

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

from vscode-terraform.

tommynsong avatar tommynsong commented on July 26, 2024 2

Still doesn't work for me, i have re-installed the plugins several time and also set both "editor.formatOnSave": true and "terraform.format.enable": true

from vscode-terraform.

cludden avatar cludden commented on July 26, 2024 1

@mauve I wasn't aware of the editor.formatOnSave setting.. that fixed it. thanks for clearing it up!

from vscode-terraform.

jgrossmac avatar jgrossmac commented on July 26, 2024 1

broken for me as well...

EDIT: I reinstalled the extension and enabled both: "editor.formatOnSave": true & "terraform.format.enable": true.

That seems to work.

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

Also getting this behavior under 0.0.20. VScode details:

screen shot 2017-12-18 at 16 52 34

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

As a workaround, I figured out how to install the previous version:

This stackoverflow answer guides you through the process. The link to download the previous version is here.

I needed to rename the file with a proper vsix file extension and restart vscode afterward. Use the previous config values (now deprecated) and it should work again.

from vscode-terraform.

jacobwgillespie avatar jacobwgillespie commented on July 26, 2024

Actually the changelog mentions this: https://github.com/mauve/vscode-terraform/blob/master/CHANGELOG.md#0020.

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

I should have been more clear, @jacobwgillespie . That config was tried, the old style config was removed (no problems in settings.json), and under the new extension version the Terraform output console shows terraform fmt successfully running against files that continue to not get formatted. I think there's still a bug here unless there's something I've overlooked.

terraform.format: running 'terraform fmt' on '/Users/brandonoconnor/Development/git/foo/variables.tf'
terraform.format: Successful.

from vscode-terraform.

jacobwgillespie avatar jacobwgillespie commented on July 26, 2024

Ah, I see, gotcha. Well in that case, I can confirm that format-on-save is working for me with the above settings, vscode-terraform version 0.0.20, and VS Code 1.19.0. Do you have any other settings or extensions that might influence file formatting?

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

I just tried to reproduce this but cannot reproduce for editor.formatOnSave. Format on save works for me with the following setting:

"editor.formatOnSave": true

or

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

However format on save does not work with editor.autoSave which I think is by design in VSCode, at least this is what the settings documentation says:

// Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down.
"editor.formatOnSave": false,

The formatter does not even seem to be invoked when editor.autoSave is true, however manually invoking save by Cmd+S or Ctrl+S.

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

@cludden: just a quick fyi: tflint is for linting, it has nothing with formatting to do. Formatting is done by terraform fmt, you should see the following output in the Output tab:

terraform.format: running 'terraform fmt' on '/Users/olenfalk/projects/vscode-terraform/templates/template.tf'
terraform.format: Successful.

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

@brandoconnor @cludden just to be clear do you have problems with the formatOnSave in general or is it the removal/breakage of the formatOnAutoSave feature which you are referring to?

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

Format on save is disabled when the save reason is auto:

https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/api/electron-browser/mainThreadSaveParticipant.ts#L190-L193

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

@cludden - Nope still not fixed here. Please reopen.

@mauve - I've verified that "editor.formatOnSave": true, editor.autoSave is non-existent (not even a valid configuration), and formatting is working on other file types. As mentioned in my previous comment, terraform.format shows the expected output on the correct file but nothing happens to the file. If I go to the terminal and terraform fmt manually, the file is formatted, but the extension is still not doing what it claims to be doing in the output. Any other settings to try or debugging that can be turned up?

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

@brandoconnor ok I will take another look tonight, sorry for breaking your setup, if you can think of any other info which might narrow this down for me please keep commenting here.

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

Just tried once more with both settings as suggested on #46 and that wasn't successful.

from vscode-terraform.

taganaka avatar taganaka commented on July 26, 2024

Seems like uninstalling and re-installing the extension helps

from vscode-terraform.

brandonjbjelland avatar brandonjbjelland commented on July 26, 2024

Wish I could have that same story @mspaulding06 🤷‍♀️ . I've probably uninstalled and reinstalled the new version 10x in the course of troubleshooting.

from vscode-terraform.

mauve avatar mauve commented on July 26, 2024

Hi guys, thanks for being patient:

Please test the new version and tell me if it still doesn't work for you:

0.0.21

What's New

  • Auto completion support @ranga543
  • Format on save is back (closes #45, #47)
  • Tools can now be installed in directories which have spaces @xeres

Format on save

The last version introduced usage of the correct extension APIs for registering formatting
providers. VSCode then automatically invokes the formatting provider on save if editor.formatOnSave has been specified. VSCode however does never invoke the formatting
provider if the save operation came from an auto-save event.

0.0.21 reintroduces the manual code which handled format on autosave instead of relying on
VSCode to perform those operations. The following configuration options have changes as result
of that:

  • terraform.format.enable: needs to be true
  • terraform.format.formatOnSave: needs to be true
  • terraform.format.ignoreExtensionsOnSave: can be used to exclude .tfvars for example from autosave formatting

The global setting: editor.formatOnSave should be false for Terraform files and the
extension contributes that default configuration. Please verify that you do not have
conflicting configuration, by removing the following setting if you have it:

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

The configuration editor.formatOnSave will have the correct setting contributed by Terraform.

from vscode-terraform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.