Skip to content

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

Open
@dbanck

Description

@dbanck

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions