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: Labels are treated as parameters when assigning semantic tokens #65494

Closed
anthony-S93 opened this issue Feb 3, 2024 · 5 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@anthony-S93
Copy link

gopls version

0.14.2-1

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/anthony93/.cache/go-build'
GOENV='/home/anthony93/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/anthony93/Devfiles/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/anthony93/Devfiles/.go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/anthony93/Devfiles/testing/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build410492386=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Create a label called mylabel and then inspect the semantic token assigned to it using an inspection tool.

What did you see happen?

The language server treats mylabel as function parameters rather than a keyword or a variable.

On Neovim:

2024-02-03-21-05-49

On VsCode:

2024-02-03-20-56-53

What did you expect to see?

I'm not sure if it's because I'm misinterpreting the language, but I don't think labels and function parameters are semantically equivalent. I would expect a more appropriate semantic token to be assigned to labels. Either that, or don't assign any semantic tokens to labels at all—a syntax highlighter like Treesitter can detect labels just fine since labels require a special syntax.

Editor and settings

No response

Logs

No response

@anthony-S93 anthony-S93 added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Feb 3, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 3, 2024
@pjweinb
Copy link

pjweinb commented Feb 3, 2024 via email

@anthony-S93
Copy link
Author

anthony-S93 commented Feb 3, 2024

The first choice for Go might be to do whatever vscode does for semantic tokens of labels in Typescript.

Is there a workaround for this? I don't want to turn off semantic highlighting because I actually find it useful.

@pjweinb
Copy link

pjweinb commented Feb 3, 2024 via email

@anthony-S93
Copy link
Author

anthony-S93 commented Feb 4, 2024

there is nothing at the moment. (You can turn off semantic tokens for strings and numbers.) Is it the color that you don't like?

I use LSP semantic tokens to visually differentiate between function parameters and normal variables inside function bodies. This is one feature of semantic tokens that I find particularly useful. The problem now is that labels are assigned the same semantic tokens as function parameters, causing the highlighting rules that apply to function parameters to also apply to labels. This defeats my original use case, which is to visually differentiate function parameters.

And then there is also the issue with inconsistency. The current implementation of gopls only treats labels as parameters at the places where those labels are defined, not at the places where they are used (in a continue statement, for example).
2024-02-04-09-34-21

In this screenshot, you can see different highlighting rules being applied to mylabel depending on where it is used. The two mylabels in this case are semantically the same even though they are not syntactically equivalent. My suggestion is to avoid assigning semantic tokens to labels altogether and just let the syntax highlighter take care of it.

@adonovan adonovan self-assigned this Feb 7, 2024
@gopherbot
Copy link

Change https://go.dev/cl/562244 mentions this issue: gopls/internal/golang: add semantic tokens for control labels

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants