Skip to content

Commit 7cc24c2

Browse files
committed
gopls: upgrade staticcheck to v0.3.0
Upgrade staticcheck to v0.3.0 to pick up support for generics. Since this version only supports Go 1.17+, increase the version at which we install staticcheck to 1.17 (from 1.15). This change is likely to cause confusion for users on Go 1.16, so show a warning when setting the "staticcheck" option to an unsupported value. Slightly refactor our setting of options along the way. Fixes golang/go#52159 Change-Id: Id9b4cee340e31988c64ca712d98573343aaf5848 Reviewed-on: https://go-review.googlesource.com/c/tools/+/396974 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Trust: Peter Weinberger <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent 1f763df commit 7cc24c2

File tree

12 files changed

+143
-85
lines changed

12 files changed

+143
-85
lines changed

gopls/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ require (
99
github.com/sergi/go-diff v1.1.0
1010
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
1111
golang.org/x/sys v0.0.0-20220209214540-3681064d5158
12-
golang.org/x/tools v0.1.9
12+
golang.org/x/tools v0.1.11-0.20220330174940-8e193c2ba95e
1313
golang.org/x/vuln v0.0.0-20220324005316-18fd808f5c7f
14-
honnef.co/go/tools v0.2.2
14+
honnef.co/go/tools v0.3.0
1515
mvdan.cc/gofumpt v0.3.0
1616
mvdan.cc/xurls/v2 v2.4.0
1717
)
1818

1919
require (
2020
github.com/BurntSushi/toml v1.0.0 // indirect
2121
github.com/google/safehtml v0.0.2 // indirect
22+
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
2223
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
2324
golang.org/x/text v0.3.7 // indirect
2425
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect

gopls/go.sum

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2+
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
23
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
34
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
45
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
@@ -40,6 +41,8 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
4041
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4142
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
4243
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
44+
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
45+
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
4346
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
4447
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
4548
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
@@ -77,8 +80,9 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
7780
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
7881
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
7982
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
80-
honnef.co/go/tools v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
8183
honnef.co/go/tools v0.2.2/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY=
84+
honnef.co/go/tools v0.3.0 h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
85+
honnef.co/go/tools v0.3.0/go.mod h1:vlRD9XErLMGT+mDuofSr0mMMquscM/1nQqtRSsh6m70=
8286
mvdan.cc/gofumpt v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
8387
mvdan.cc/gofumpt v0.3.0/go.mod h1:0+VyGZWleeIj5oostkOex+nDBA0eyavuDnDusAJ8ylo=
8488
mvdan.cc/unparam v0.0.0-20211214103731-d0ef000c54e5 h1:Jh3LAeMt1eGpxomyu3jVkmVZWW2MxZ1qIIV2TZ/nRio=

gopls/internal/hooks/analysis.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build go1.15
6-
// +build go1.15
5+
//go:build go1.17
6+
// +build go1.17
77

88
package hooks
99

@@ -18,6 +18,8 @@ import (
1818
)
1919

2020
func updateAnalyzers(options *source.Options) {
21+
options.StaticcheckSupported = true
22+
2123
mapSeverity := func(severity lint.Severity) protocol.DiagnosticSeverity {
2224
switch severity {
2325
case lint.SeverityError:

gopls/internal/hooks/analysis_115.go renamed to gopls/internal/hooks/analysis_117.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !go1.15
6-
// +build !go1.15
5+
//go:build !go1.17
6+
// +build !go1.17
77

88
package hooks
99

1010
import "golang.org/x/tools/internal/lsp/source"
1111

12-
func updateAnalyzers(_ *source.Options) {}
12+
func updateAnalyzers(options *source.Options) {
13+
options.StaticcheckSupported = false
14+
}

gopls/internal/hooks/licenses_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func TestLicenses(t *testing.T) {
1818
// License text differs for older Go versions because staticcheck isn't
1919
// supported for those versions.
20-
testenv.NeedsGo1Point(t, 15)
20+
testenv.NeedsGo1Point(t, 17)
2121

2222
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
2323
t.Skip("generating licenses only works on Unixes")

gopls/internal/regtest/diagnostics/diagnostics_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,11 @@ func main() {
12651265
`
12661266

12671267
WithOptions(
1268-
EditorConfig{EnableStaticcheck: true},
1268+
EditorConfig{
1269+
Settings: map[string]interface{}{
1270+
"staticcheck": true,
1271+
},
1272+
},
12691273
).Run(t, files, func(t *testing.T, env *Env) {
12701274
env.OpenFile("main.go")
12711275
var d protocol.PublishDiagnosticsParams

gopls/internal/regtest/misc/configuration_test.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
// Test that enabling and disabling produces the expected results of showing
1717
// and hiding staticcheck analysis results.
1818
func TestChangeConfiguration(t *testing.T) {
19-
// Staticcheck only supports Go versions > 1.14.
20-
testenv.NeedsGo1Point(t, 15)
19+
// Staticcheck only supports Go versions >= 1.17.
20+
// Note: keep this in sync with TestStaticcheckWarning. Below this version we
21+
// should get an error when setting staticcheck configuration.
22+
testenv.NeedsGo1Point(t, 17)
2123

2224
const files = `
2325
-- go.mod --
@@ -40,10 +42,39 @@ var FooErr = errors.New("foo")
4042
)
4143
cfg := &fake.EditorConfig{}
4244
*cfg = env.Editor.Config
43-
cfg.EnableStaticcheck = true
45+
cfg.Settings = map[string]interface{}{
46+
"staticcheck": true,
47+
}
4448
env.ChangeConfiguration(t, cfg)
4549
env.Await(
4650
DiagnosticAt("a/a.go", 5, 4),
4751
)
4852
})
4953
}
54+
55+
func TestStaticcheckWarning(t *testing.T) {
56+
// Note: keep this in sync with TestChangeConfiguration.
57+
testenv.SkipAfterGo1Point(t, 16)
58+
59+
const files = `
60+
-- go.mod --
61+
module mod.com
62+
63+
go 1.12
64+
-- a/a.go --
65+
package a
66+
67+
import "errors"
68+
69+
// FooErr should be called ErrFoo (ST1012)
70+
var FooErr = errors.New("foo")
71+
`
72+
73+
WithOptions(EditorConfig{
74+
Settings: map[string]interface{}{
75+
"staticcheck": true,
76+
},
77+
}).Run(t, files, func(t *testing.T, env *Env) {
78+
env.Await(ShownMessage("staticcheck is not supported"))
79+
})
80+
}

internal/lsp/fake/editor.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ type EditorConfig struct {
101101
// To explicitly send no workspace folders, use an empty (non-nil) slice.
102102
WorkspaceFolders []string
103103

104-
// EnableStaticcheck enables staticcheck analyzers.
105-
EnableStaticcheck bool
106-
107104
// AllExperiments sets the "allExperiments" configuration, which enables
108105
// all of gopls's opt-in settings.
109106
AllExperiments bool
@@ -258,9 +255,6 @@ func (e *Editor) configuration() map[string]interface{} {
258255
if e.Config.SymbolStyle != nil {
259256
config["symbolStyle"] = *e.Config.SymbolStyle
260257
}
261-
if e.Config.EnableStaticcheck {
262-
config["staticcheck"] = true
263-
}
264258
if e.Config.AllExperiments {
265259
config["allExperiments"] = true
266260
}

internal/lsp/general.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -412,35 +412,25 @@ func (s *Server) eventuallyShowMessage(ctx context.Context, msg *protocol.ShowMe
412412

413413
func (s *Server) handleOptionResults(ctx context.Context, results source.OptionResults) error {
414414
for _, result := range results {
415-
if result.Error != nil {
416-
msg := &protocol.ShowMessageParams{
417-
Type: protocol.Error,
415+
var msg *protocol.ShowMessageParams
416+
switch result.Error.(type) {
417+
case nil:
418+
// nothing to do
419+
case *source.SoftError:
420+
msg = &protocol.ShowMessageParams{
421+
Type: protocol.Warning,
418422
Message: result.Error.Error(),
419423
}
420-
if err := s.eventuallyShowMessage(ctx, msg); err != nil {
421-
return err
422-
}
423-
}
424-
switch result.State {
425-
case source.OptionUnexpected:
426-
msg := &protocol.ShowMessageParams{
424+
default:
425+
msg = &protocol.ShowMessageParams{
427426
Type: protocol.Error,
428-
Message: fmt.Sprintf("unexpected gopls setting %q", result.Name),
427+
Message: result.Error.Error(),
429428
}
429+
}
430+
if msg != nil {
430431
if err := s.eventuallyShowMessage(ctx, msg); err != nil {
431432
return err
432433
}
433-
case source.OptionDeprecated:
434-
msg := fmt.Sprintf("gopls setting %q is deprecated", result.Name)
435-
if result.Replacement != "" {
436-
msg = fmt.Sprintf("%s, use %q instead", msg, result.Replacement)
437-
}
438-
if err := s.eventuallyShowMessage(ctx, &protocol.ShowMessageParams{
439-
Type: protocol.Warning,
440-
Message: msg,
441-
}); err != nil {
442-
return err
443-
}
444434
}
445435
}
446436
return nil

internal/lsp/regtest/expectation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ func NoShowMessage() SimpleExpectation {
152152
}
153153
}
154154

155-
// ShownMessage asserts that the editor has received a ShownMessage with the
156-
// given title.
157-
func ShownMessage(title string) SimpleExpectation {
155+
// ShownMessage asserts that the editor has received a ShowMessageRequest
156+
// containing the given substring.
157+
func ShownMessage(containing string) SimpleExpectation {
158158
check := func(s State) Verdict {
159159
for _, m := range s.showMessage {
160-
if strings.Contains(m.Message, title) {
160+
if strings.Contains(m.Message, containing) {
161161
return Met
162162
}
163163
}

0 commit comments

Comments
 (0)