terraform-ls
terraform-ls copied to clipboard
formatOnSave not honoured/working on ,tf files
Server Version
$ terraform-ls --version
terraform-ls: command not found
Terraform Version
$ terraform -v
Terraform v1.0.8
on linux_amd64
Client Version
vscode 1.60.2
Expected Behavior
Installing the terraform extension in VS Code should be enough to have it work.
Actual Behavior
No errors were reported by VS Code (in the sense of notification bubbles), but saved files were not formatted.
Steps to Reproduce
- Install vscode in a brand new user - no existing settings.
- Install the terraform extension
- Open a directory with .tf files
- Open a .tf file
- Add a space somewhere that changes the content to be unformatted but still legitimate .tf
- Save the file
Same issue for me I think, output from terraform-ls looks like this, any advice?
❯ terraform-ls -v
0.23.0
❯ terraform -v
Terraform v1.0.9
on linux_amd64
2021/10/19 12:51:02 formatting.go:41: formatting document via "/usr/bin/terraform-ls"
2021/10/19 12:51:02 rpc_logger.go:45: Error for "textDocument/formatting" (ID 59): [-32098] fmt was first introduced in Terraform 0.7.7: unable to parse version "": Malformed version:
2021/10/19 12:51:02 server.go:252: Completed 1 requests [5.759612ms elapsed]
[Error - 12:51:02 PM] Request textDocument/formatting failed.
Message: fmt was first introduced in Terraform 0.7.7: unable to parse version "": Malformed version:
Code: -32098
EDIT: ok this was quick... I solved it by adding this in VSCode settings
"terraform-ls.terraformExecPath": "/usr/bin/terraform",
Hi @rbtcollins It looks like we completely forgot about this older issue! Sorry about that.
Either way, the auto-formatting in VS Code should work, as long as the appropriate settings is in place. We have some documentation available under https://github.com/hashicorp/vscode-terraform#formatting
If you can confirm that these settings are in place and formatting still doesn't work I would encourage you to file a new issue and attach all the relevant settings + ideally the log output.
Thanks!
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.