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: Semantic Highlighting for builtin true and false broken in 0.17.0 #70934

Closed
ndbeals opened this issue Dec 19, 2024 · 6 comments
Closed
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@ndbeals
Copy link

ndbeals commented Dec 19, 2024

gopls version

Build info

golang.org/x/tools/gopls v0.17.0
golang.org/x/tools/gopls@v0.17.0 h1:yiwvxZX6lAQzZtJyDhKbGUiCepoGOEVw7E/i31JUcLE=
github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=
golang.org/x/mod@v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/sync@v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/telemetry@v0.0.0-20241106142447-58a1122356f5 h1:TCDqnvbBsFapViksHcHySl/sW4+rTGNIAoJJesHRuMM=
golang.org/x/text@v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/tools@v0.27.1-0.20241211153006-a83c4ee29a47 h1:dFDhAo0DFSbmpMYZcvCfIQK9q/wH3fMI8V18Gbcnm9E=
golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/tools@v0.5.1 h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=
mvdan.cc/gofumpt@v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.4

go env

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/nathan/Library/Caches/go-build'
GOENV='/Users/nathan/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/nathan/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/nathan/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/nathan/.go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/nathan/.go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.4'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/nathan/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/q8/31w49dfx19b4nj9t0qk33wsm0000gp/T/go-build2081165816=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I updated gopls from v0.16.2 to v0.17.0

What did you see happen?

Semantic token highlighting for the builtin true and false keywords no longer worked. This is what I saw:

image

What did you expect to see?

This is what I expected to see:

image

Editor and settings

    "gopls": {
        "ui.semanticTokens": true,
        "ui.documentation.hoverKind": "FullDocumentation",
        "ui.navigation.symbolScope": "workspace",
    },

    "go.useLanguageServer": true,

Logs

No response

@ndbeals ndbeals 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 Dec 19, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 19, 2024
@findleyr
Copy link
Member

CC @pjweinb

@adonovan
Copy link
Member

I can reproduce this, but I don't understand it. Inpsecting the token using VS Code's "Developer: inspect editor tokens and scopes" command, I see:

gopls@v0.16.0

language | go
standard token type | Other
foreground | #569CD6
background | #1F1F1F
contrast ratio | 5.59

textmate scopes | constant.language.boolean.go source.go
foreground | constant.language{ "foreground": "#569CD6" }

Using gopls semtok CLI:
/*⇒4,variable,[readonly]*/true

The VS Code panel doesn't show any semantics at all, though the CLI output clearly shows "variable, readonly".

gopls@v0.17.0

language | go
standard token type | Other
foreground | #9CDCFE
background | #1F1F1F
contrast ratio | 11.05

semantic token type | variable
modifiers | readonly defaultLibrary
foreground | support.variable variable meta.definition.variable.name support.variable entity.name.variable constant.other.placeholder { "foreground": "#9CDCFE" }

textmate scopes | constant.language.boolean.go source.go
foreground | ~~constant.language { "foreground": "#569CD6" }~~ [strikethrough]

Using gopls semtok CLI:
/*⇒4,variable,[readonly defaultLibrary]*/true

Observe the addition of defaultLibrary, probably due to https://go.dev/cl/625895. The only other change is https://go.dev/cl/626279, but as can be seen from file gopls/internal/test/marker/testdata/token/builtin_constant.txt, the semantics of true and false should have remained unchanged (token=variable modifiers=readonly defaultLibrary).

So my guess is that gopls has started reporting "defaultLibrary" for true and false (which is correct), but that the client-side (VS Code) style rules don't know what to make of that.

@adonovan
Copy link
Member

Paging @hyangah for VS Code expertise...

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.18.0 Dec 20, 2024
@xzbdmw
Copy link

xzbdmw commented Dec 20, 2024

I think modifiers with defaultLibrary has higher priority than readonly, and the vscode dark theme paint defaultLibrary as bright blue; readonly as deep blue. So you can see x has the same color as true and false in gopls 0.16.

image image

Add those settings mimic the origin color:

	"editor.semanticTokenColorCustomizations": {
		"[Default Dark+]": {
			"rules": {
				"variable.defaultLibrary": "#4FC1FF"
			}
		}
       }

@adonovan
Copy link
Member

Thanks for the explanation and the workaround.

Since this seems to be entirely a client-side configuration issue, not a bug in gopls, I'm going close it.

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

6 participants