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

x/tools/gopls: error "Semantic token with invalid length detected" #65254

Closed
hyangah opened this issue Jan 24, 2024 · 3 comments
Closed

x/tools/gopls: error "Semantic token with invalid length detected" #65254

hyangah opened this issue Jan 24, 2024 · 3 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Jan 24, 2024

Gopls version: Built from head (df2fa1e)

Noticed an error printed in the VS Code developer console (VS Code: "Developer: Toggle Developer Tool")

semanticTokensProviderStyling.ts:115 Semantic token with invalid length detected at lineNumber 4, column 1

Repro:

package foo

const X = `

`

func m() {}
[Trace - 08:41:27.063 AM] Sending request 'textDocument/semanticTokens/full - (5)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/projects/foo/main.go"}}
...

[Trace - 08:41:27.264 AM] Received response 'textDocument/semanticTokens/full - (5)' in 200ms.
Result: {
"resultId":"2024-01-24 08:41:27.264018 -0500 EST m=+2.293108734",
"data":[0,0,7,15,0,0,8,3,0,0,2,0,5,15,0,0,6,1,8,6,0,4,1,18,0,1,0,0,18,0,1,0,1,18,0,2,0,4,15,0,0,5,1,12,2]
}

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 24, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 24, 2024
@suzmue suzmue added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 24, 2024
@suzmue suzmue modified the milestones: Unreleased, gopls/v0.16.0 Jan 24, 2024
@adonovan
Copy link
Member

adonovan commented Feb 1, 2024

xtools$ cat a.go
package foo

const X = `

`

func m() {}

xtools$ go run ./gopls semtok ./a.go 
Log: Loading packages...
Info: Finished loading packages.
/*⇒7,keyword,[]*/package /*⇒3,namespace,[]*/foo

/*⇒5,keyword,[]*/const /*⇒1,variable,[definition readonly]*/X = /*⇒1,string,[]*/`
/*⇒0,string,[]*/
/*⇒1,string,[]*/`

/*⇒4,keyword,[]*/func /*⇒1,function,[definition]*/m() {}

gopls is reporting three annotations for a single multi-line string literal. This is a consequence of the LSP design decision is rationalized in microsoft/vscode#86415 (comment). Apparently clients can opt in to multiline-token support.

If a client can't handle multiline tokens, it really ought to be able to handle zero-length tokens corresponding to blank lines in multiline string literals. I suppose gopls could just suppress them, but I'd rather the fix was in vscode.

@pjweinb
Copy link

pjweinb commented Feb 2, 2024 via email

@gopherbot
Copy link

Change https://go.dev/cl/561155 mentions this issue: gopls/semantic: elide zero-length tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

6 participants