Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin formatting still not working after installing Preview version #1030

Closed
2 tasks done
mbacchi opened this issue Apr 6, 2022 · 7 comments
Closed
2 tasks done
Labels
bug Something isn't working waiting-response

Comments

@mbacchi
Copy link

mbacchi commented Apr 6, 2022

Versions

This bug is reproducible in:

  • the latest version of the extension (below)
  • the latest version of the language server (below)

Extension

HashiCorp Terraform (Preview) v2022.3.1510

Language Server

Starting terraform-ls 0.26.0-beta1

VS Code

Version: 1.66.0
Commit: e18005f0f1b33c29e81d732535d8c0e47cafb0b5
Date: 2022-03-30T05:50:41.156Z
Electron: 17.2.0
Chromium: 98.0.4758.109
Node.js: 16.13.0
V8: 9.8.177.11-electron.0
OS: Linux x64 5.16.18-200.fc35.x86_64

Operating System

uname -a
Linux HOSTNAME 5.16.18-200.fc35.x86_64 #1 SMP PREEMPT Mon Mar 28 14:10:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
No WSL

Terraform Version

Terraform v1.1.7
on linux_amd64

Steps To Reproduce

Terraform files are not formatted when saved. I chatted with James Pogran on Twitter (https://twitter.com/ender2025/status/1505941271789113349?s=20&t=Lhe0k1qRB3rfNZ0t9i1GqA) and he suggested using the Preview version. I did this and made the other changes to the settings configuration that he recommended from here; https://github.com/hashicorp/vscode-terraform#formatting.

At first this worked, but now after maybe a week or 10 days of using the preview, I no longer have a guarantee of formatting the file when I save it. In fact at the moment it feels like it rarely if ever formats on save.

I have a current file with some resources formatted this way:

  default_cache_behavior {
    allowed_methods  = var.allowed_methods
    cached_methods   = var.cached_methods
    compress         = true
    target_origin_id = local.website_origin_id
    origin_request_policy_id = aws_cloudfront_origin_request_policy.noname_service.id

(Notice the equal signs not lined up.)

I saved the file multiple times and reloaded vscode, and still it doesn't format correctly.

I have to run terraform fmt in order to format it correctly now.

After running terraform fmt it looks like:

  default_cache_behavior {
    allowed_methods          = var.allowed_methods
    cached_methods           = var.cached_methods
    compress                 = true
    target_origin_id         = local.website_origin_id
    origin_request_policy_id = aws_cloudfront_origin_request_policy.noname_service.id

Expected Behavior

Formatting should be applied when the file is saved.

Actual Behavior

Formatting of many/most files is not applied when saved.

Additional context

@mbacchi mbacchi added the bug Something isn't working label Apr 6, 2022
@jpogran jpogran self-assigned this Apr 7, 2022
@jpogran
Copy link
Contributor

jpogran commented Apr 7, 2022

Thanks for the report, sorry you're experiencing this. We have two bug fixes landing soon that may be related to your situation:

But I won't be able to tell until we dig further in what's going on here. Can you print out a simplified and/or redacted folder setup you're using? For example opening /foo/bar, which has X number of sub folders, with /foo/bar/../../../baz.tf being the file you're targeting?

@mbacchi
Copy link
Author

mbacchi commented Apr 7, 2022

Thanks James. Yes the folder structure that I'm experiencing the problem today is (simplified/redacted version):

infrastructure/terraform/foo/bar/baz/main.tf

Let me know if I can provide more info.

@radeksimko
Copy link
Member

@mbacchi Do you mind sharing the whole log, or at least all lines which contain Incoming request for "textDocument/formatting" and Response to "textDocument/formatting" and anything in between them?

You can find it under the Output pane > HashiCorp Terraform

Screenshot 2022-04-11 at 10 36 37

Screenshot 2022-04-11 at 10 35 55

Thanks!

@radeksimko
Copy link
Member

If you're worried about sensitive data, you may encrypt the log using my pubkey before posting it here and/or send it to radek <at> hashicorp.com

@jpogran jpogran removed their assignment Apr 29, 2022
@mbacchi
Copy link
Author

mbacchi commented May 12, 2022

Thank you @radeksimko, I just saw this request and sent you a truncated log to your email. Let me know if you have further questions.

@mbacchi
Copy link
Author

mbacchi commented Jun 23, 2022

I worked with Radek on this via email to troubleshoot further. It boiled down to the fact that I had configured the plugin in settings.json according to this documentation, but when I started using the preview plugin that did not work because the config setting "editor.defaultFormatter": "hashicorp.terraform" did not match the preview plugin, as the normal hashicorp.terraform plugin was not installed.

Once I corrected this to use "editor.defaultFormatter": "hashicorp.terraform-preview" it worked, and then I was able to uninstall the preview plugin, use the standard plugin, and return the settings to use the normal plugin "editor.defaultFormatter": "hashicorp.terraform".

Thanks @radeksimko for your help!

@mbacchi mbacchi closed this as completed Jun 23, 2022
@github-actions
Copy link

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 details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working waiting-response
Projects
None yet
Development

No branches or pull requests

3 participants