Skip to content

Commit d857e85

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/settings: enable semantic tokens by default
Whether or not semantic tokens are enabled should be a client-side setting. Clients that don't want semantic tokens should not ask for them, and if clients send textDocument/semanticTokens requests, gopls should handle them by default. Unfortunately, as described in golang/vscode-go#3338, this is not how semantic tokens were configured in the past. This CL changes the default value of the "semanticTokens" setting to true. We should not release a gopls version with this change until addressing golang/vscode-go#3338, but by making this change in master now it is easier to test the fix in vscode-go. For golang/vscode-go#3338 Change-Id: I05d7084436cd4dfe312460cfe08e3b1777f190ed Reviewed-on: https://go-review.googlesource.com/c/tools/+/579337 Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 3f74dc5 commit d857e85

File tree

9 files changed

+16
-22
lines changed

9 files changed

+16
-22
lines changed

gopls/doc/release/v0.16.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ gopls/v0.16.0
44
go install golang.org/x/tools/[email protected]
55
```
66

7+
## Configuration Changes
8+
9+
- The default value of the "semanticTokens" setting is now "true". This means
10+
that if your LSP client is able and configured to request semantic tokens,
11+
gopls will provide them. The default was previously false because VS Code
12+
historically provided no client-side way for users to disable the feature.
13+
714
## New features
815

916
### Integrated documentation viewer

gopls/doc/settings.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ Default: `{"gc_details":false,"generate":true,"regenerate_cgo":true,"tidy":true,
196196
**This setting is experimental and may be deleted.**
197197

198198
semanticTokens controls whether the LSP server will send
199-
semantic tokens to the client.
199+
semantic tokens to the client. If false, gopls will send empty semantic
200+
tokens.
200201

201-
Default: `false`.
202+
Default: `true`.
202203

203204
#### **noSemanticString** *bool*
204205

gopls/internal/settings/api_json.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gopls/internal/settings/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func DefaultOptions(overrides ...func(*Options)) *Options {
106106
string(command.Vendor): true,
107107
// TODO(hyangah): enable command.RunGovulncheck.
108108
},
109+
SemanticTokens: true,
109110
},
110111
},
111112
InternalOptions: InternalOptions{

gopls/internal/settings/settings.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ type UIOptions struct {
181181
Codelenses map[string]bool
182182

183183
// SemanticTokens controls whether the LSP server will send
184-
// semantic tokens to the client.
184+
// semantic tokens to the client. If false, gopls will send empty semantic
185+
// tokens.
185186
SemanticTokens bool `status:"experimental"`
186187

187188
// NoSemanticString turns off the sending of the semantic token 'string'

gopls/internal/test/integration/misc/semantictokens_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func Add[T int](target T, l []T) []T {
9090
`
9191
WithOptions(
9292
Modes(Default),
93-
Settings{"semanticTokens": true},
9493
).Run(t, src, func(t *testing.T, env *Env) {
9594
env.OpenFile("main.go")
9695
env.AfterChange(
@@ -127,7 +126,6 @@ func New[K int, V any]() Smap[K, V] {
127126
`
128127
WithOptions(
129128
Modes(Default),
130-
Settings{"semanticTokens": true},
131129
).Run(t, src, func(t *testing.T, env *Env) {
132130
env.OpenFile("main.go")
133131
seen := env.SemanticTokensFull("main.go")
@@ -183,7 +181,6 @@ func bar() {}
183181

184182
WithOptions(
185183
Modes(Default),
186-
Settings{"semanticTokens": true},
187184
).Run(t, src, func(t *testing.T, env *Env) {
188185
env.OpenFile("main.go")
189186
seen := env.SemanticTokensFull("main.go")
@@ -198,7 +195,7 @@ func TestSemantic_65254(t *testing.T) {
198195
src := `
199196
-- go.mod --
200197
module example.com
201-
198+
202199
go 1.21
203200
-- main.go --
204201
package main
@@ -227,7 +224,6 @@ const bad = `
227224
}
228225
WithOptions(
229226
Modes(Default),
230-
Settings{"semanticTokens": true},
231227
).Run(t, src, func(t *testing.T, env *Env) {
232228
env.OpenFile("main.go")
233229
seen := env.SemanticTokensFull("main.go")

gopls/internal/test/integration/template/template_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ go 1.17
3636
WithOptions(
3737
Settings{
3838
"templateExtensions": []string{"tmpl"},
39-
"semanticTokens": true,
4039
},
4140
).Run(t, files, func(t *testing.T, env *Env) {
4241
var p protocol.SemanticTokensParams
@@ -65,7 +64,6 @@ Hello {{}} <-- missing body
6564
WithOptions(
6665
Settings{
6766
"templateExtensions": []string{"tmpl"},
68-
"semanticTokens": true,
6967
},
7068
).Run(t, files, func(t *testing.T, env *Env) {
7169
// TODO: can we move this diagnostic onto {{}}?

gopls/internal/test/marker/testdata/token/comment.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ links and output tokens according to the referenced object types, so that the
55
editor can highlight them. This will help in checking the doc link errors and
66
reading comments in the code.
77

8-
-- settings.json --
9-
{
10-
"semanticTokens": true
11-
}
12-
138
-- a.go --
149
package p
1510

gopls/internal/test/marker/testdata/token/range.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ This test checks the output of textDocument/semanticTokens/range.
22

33
TODO: add more assertions.
44

5-
-- settings.json --
6-
{
7-
"semanticTokens": true
8-
}
9-
105
-- a.go --
116
package p //@token("package", "keyword", "")
127

0 commit comments

Comments
 (0)