vscode-terraform icon indicating copy to clipboard operation
vscode-terraform copied to clipboard

Document is Open - Ignoring Event

Open gadgetmerc opened this issue 1 year ago • 3 comments

Extension Version

v2.30.2024022914

VS Code Version

Version: 1.87.0 (Universal) Commit: 019f4d1419fbc8219a181fab7892ebccf7ee29a2 Date: 2024-02-27T23:42:56.944Z (1 day ago) Electron: 27.3.2 ElectronBuildId: 26836302 Chromium: 118.0.5993.159 Node.js: 18.17.1 V8: 11.8.172.18-electron.0 OS: Darwin arm64 23.3.0

Operating System

14.3.1 (23D60)

Terraform Version

Terraform v1.5.4 on darwin_amd64

Steps to Reproduce

  1. update a terraform file
  2. save it.

Expected Behavior

The expected behavior is that the file will be formatted. I reference one file in this example but its across any TF projects I have.

Actual Behavior

No formatting is done. Looking at the output of "hashicorp terraform" i see messages like the one below. I have verified that i don't have the files open in another vscode project/window or even open in vi. lsof doesn't show it opened by anything. Not sure why its skipping the file. Running terraform fmt from the command line formats the file as expected by the vs-code plugin.

I have tried disabling all other plugins and restarting my laptop. Running out of things to try.

2024/02/29 11:30:43 rpc_logger.go:32: Incoming notification for "workspace/didChangeWatchedFiles": {"changes":[{"uri":"file:///Users/user.name/git/terraform-pmr/terraform-vp-user-profile/aurora.tf","type":2}]} 2024/02/29 11:30:43 did_change_watched_files.go:159: document is open - ignoring event for "file:///Users/user.name/git/terraform-pmr/terraform-vp-user-profile/aurora.tf"

Terraform Configuration

It doesn't matter which resources or modules are being referenced.

VSCode Settings.json
    "terraform": {
        "editor.defaultFormatter": "hashicorp.terraform",
        "editor.formatOnSave": true,
        "editor.formatOnSaveMode": "file",
        "codelens.referenceCount": true,
        "experimentalFeatures.validateOnSave": true,
    },
    "terraform-vars": {
        "editor.defaultFormatter": "hashicorp.terraform",
        "editor.formatOnSave": true,
        "editor.formatOnSaveMode": "file"
    },

Project Structure

| - variables.tf
| - aurora.tf

Gist

No response

Anything Else?

No response

Workarounds

No response

References

No response

Help Wanted

  • [ ] I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

gadgetmerc avatar Feb 29 '24 17:02 gadgetmerc

Hi @gadgetmerc, thanks for the report and your initial investigation.

Can you please share the full log? Saving the file should trigger a "textDocument/formatting" message and some more log output that might shed some light on the issue.

dbanck avatar Mar 01 '24 09:03 dbanck

Sorry for the delay. The file saved was variables.tf and I added whitespace that it should format for me.

2024/03/04 09:21:28 opts.go:215: Received request batch of size 1 (qlen=0)
2024/03/04 09:21:28 opts.go:215: Dequeued request batch of length 1 (qlen=0)
2024/03/04 09:21:28 rpc_logger.go:32: Incoming notification for "textDocument/didSave": {"textDocument":{"uri":"file:///Users/user.name/git/terraform-pmr/terraform-vpcore-cidrs/variables.tf"}}
2024/03/04 09:21:28 opts.go:215: Received request batch of size 1 (qlen=0)
2024/03/04 09:21:28 opts.go:215: Dequeued request batch of length 1 (qlen=0)
2024/03/04 09:21:28 rpc_logger.go:32: Incoming notification for "workspace/didChangeWatchedFiles": {"changes":[{"uri":"file:///Users/user.name/git/terraform-pmr/terraform-vpcore-cidrs/variables.tf","type":2}]}
2024/03/04 09:21:28 did_change_watched_files.go:159: document is open - ignoring event for "file:///Users/user.name/git/terraform-pmr/terraform-vpcore-cidrs/variables.tf"
2024/03/04 09:21:32 opts.go:215: Received request batch of size 1 (qlen=0)
2024/03/04 09:21:32 opts.go:215: Received request batch of size 1 (qlen=1)
2024/03/04 09:21:32 opts.go:215: Dequeued request batch of length 1 (qlen=1)
2024/03/04 09:21:32 opts.go:215: Dequeued request batch of length 1 (qlen=0)
2024/03/04 09:21:32 rpc_logger.go:32: Incoming request for "textDocument/codeLens" (ID 2397): {"textDocument":{"uri":"file:///Users/user.name/git/terraform-pmr/terraform-vpcore-cidrs/cidrs.tf"}}
2024/03/04 09:21:32 rpc_logger.go:32: Incoming request for "textDocument/codeLens" (ID 2398): {"textDocument":{"uri":"file:///Users/user.name/git/terraform-pmr/terraform-vpcore-cidrs/variables.tf"}}
2024/03/04 09:21:32 rpc_logger.go:53: Response to "textDocument/codeLens" (ID 2397): []
2024/03/04 09:21:32 opts.go:215: Completed 1 requests [2.157959ms elapsed]
2024/03/04 09:21:32 rpc_logger.go:53: Response to "textDocument/codeLens" (ID 2398): []
2024/03/04 09:21:32 opts.go:215: Completed 1 requests [2.529792ms elapsed]

gadgetmerc avatar Mar 04 '24 15:03 gadgetmerc

It's hard to tell without the full log, but it looks like your editor is not sending a formatting request.

Are the settings in your original post copied directly from your settings.json? To reference a language ID, you need to use [] brackets. Can you check if your settings have an entry for formatting Terraform files, like this

  "[terraform]": {
    "editor.defaultFormatter": "hashicorp.terraform",
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file"
  },
  "[terraform-vars]": {
    "editor.defaultFormatter": "hashicorp.terraform",
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file"
  },

dbanck avatar Mar 07 '24 08:03 dbanck

Marking this issue as stale due to inactivity over the last 30 days. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

Thank you for understanding.

github-actions[bot] avatar Aug 12 '24 03:08 github-actions[bot]