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

Files starting with a multiline comment lead to out of range errors in LSP #1052

Open
dbanck opened this issue Aug 26, 2022 · 3 comments
Open
Labels
bug Something isn't working textDocument/documentLink textDocument/semanticTokens Semantic syntax highlighting upstream/hcl

Comments

@dbanck
Copy link
Member

dbanck commented Aug 26, 2022

We discovered in #1050 (unrelated to the bug reported in #1050) that having a file start with a multiline comment results in out of range errors for all kinds of LSP requests.

Server Version

0.29.1

Terraform Configuration Files

/********************************
 Some comment
********************************/

data "google_project" "project" {
  project_id = var.project_id
}

Log Output

2022/08/26 15:34:17 rpc_logger.go:29: Incoming request for "textDocument/documentLink" (ID 2): {"textDocument":{"uri":"file:///Users/dbanck/tmp/issue1050/main.tf"}}
2022/08/26 15:34:17 rpc_logger.go:29: Incoming request for "textDocument/documentSymbol" (ID 1): {"textDocument":{"uri":"file:///Users/dbanck/tmp/issue1050/main.tf"}}
2022/08/26 15:34:17 provider_schema.go:256: PSS: getting provider schema (/Users/dbanck/tmp/issue1050, registry.terraform.io/-/google, )
2022/08/26 15:34:17 provider_schema.go:256: PSS: getting provider schema (/Users/dbanck/tmp/issue1050, registry.terraform.io/-/google, )
2022/08/26 15:34:17 opts.go:218: Received response for callback "2"
2022/08/26 15:34:17 opts.go:218: Posting server call "client.refreshModuleCalls" 
2022/08/26 15:34:17 opts.go:218: Received response for callback "3"
2022/08/26 15:34:17 opts.go:218: Posting server call "workspace/semanticTokens/refresh" 
2022/08/26 15:34:17 opts.go:218: Received response for callback "4"
2022/08/26 15:34:17 rpc_logger.go:50: Response to "textDocument/documentSymbol" (ID 1): [{"name":"data \"google_project\" \"project\"","kind":5,"range":{"start":{"line":4,"character":0},"end":{"line":6,"character":1}},"selectionRange":{"start":{"line":4,"character":0},"end":{"line":6,"character":1}},"children":[{"name":"project_id","kind":14,"range":{"start":{"line":5,"character":2},"end":{"line":5,"character":29}},"selectionRange":{"start":{"line":5,"character":2},"end":{"line":5,"character":29}}}]}]
2022/08/26 15:34:17 opts.go:218: Completed 1 requests [50.012484ms elapsed]
2022/08/26 15:34:17 rpc_logger.go:45: Error for "textDocument/documentLink" (ID 2): [-32098] main.tf: position 1,1 is out of range main.tf:3,34-8,1
2022/08/26 15:34:17 opts.go:218: Completed 1 requests [3.859428ms elapsed]
[Error - 3:34:17 PM] Request textDocument/documentLink failed.
  Message: main.tf: position 1,1 is out of range main.tf:3,34-8,1
  Code: -32098 
2022/08/26 15:34:17 opts.go:218: Received request batch of size 1 (qlen=0)
2022/08/26 15:34:17 opts.go:218: Dequeued request batch of length 1 (qlen=0)
2022/08/26 15:34:17 rpc_logger.go:29: Incoming request for "textDocument/semanticTokens/full" (ID 3): {"textDocument":{"uri":"file:///Users/dbanck/tmp/issue1050/main.tf"}}
2022/08/26 15:34:17 provider_schema.go:256: PSS: getting provider schema (/Users/dbanck/tmp/issue1050, registry.terraform.io/-/google, )
2022/08/26 15:34:17 rpc_logger.go:45: Error for "textDocument/semanticTokens/full" (ID 3): [-32098] main.tf: position 1,1 is out of range main.tf:3,34-8,1
2022/08/26 15:34:17 opts.go:218: Completed 1 requests [3.050845ms elapsed]
[Error - 3:34:17 PM] Request textDocument/semanticTokens/full failed.
  Message: main.tf: position 1,1 is out of range main.tf:3,34-8,1
  Code: -32098

Expected Behavior

No errors, usual responses to all requests.

Actual Behavior

Out of range errors for requests with a position lower than line 3.

Degraded DX, because of broken features like semantic tokens.

Proposal

Raise this issue upstream in HCL

@dbanck dbanck added the bug Something isn't working label Aug 26, 2022
@dbanck dbanck changed the title Files starting with a comment lead to out of range errors in LSP Files starting with a multiline comment lead to out of range errors in LSP Aug 26, 2022
@dbanck
Copy link
Member Author

dbanck commented Aug 29, 2022

Filed this as an upstream bug in HCL: hashicorp/hcl#551

@radeksimko
Copy link
Member

This is somewhat related to #105 - if we implement region folding, comment blocks are likely one of those things which users will want to fold, so having them parsed correctly by HCL (currently they're ignored) would be necessary there too.

I believe HCL parser(s) currently ignore comments, which the described bug may be side effect of.

@radeksimko
Copy link
Member

@dbanck came up with an idea for a local fix (without having to touch upstream), which involves changing the logic for textDocument/documentLink and relevant semantic tokens method to avoid lookup with position as that's not necessary:

https://github.com/hashicorp/hcl-lang/blob/c6076d3b6a2868550b601d4ac7c23f8c395f7dc1/decoder/links.go#L21-L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working textDocument/documentLink textDocument/semanticTokens Semantic syntax highlighting upstream/hcl
Projects
None yet
Development

No branches or pull requests

2 participants