Skip to content

Commit ce28f40

Browse files
committed
gopls/internal/regtest: add a test demonstrating confusion following an
options change Add a test that demonstrates gopls gets confused about file content following an options change. For golang/go#57934 Change-Id: I536245877ef9069613d6e551354b00fc42b3bc5c Reviewed-on: https://go-review.googlesource.com/c/tools/+/462821 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent c4c6aa6 commit ce28f40

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

gopls/internal/lsp/cache/view.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ func (v *View) FileKind(fh source.FileHandle) source.FileKind {
360360
}
361361

362362
func minorOptionsChange(a, b *source.Options) bool {
363-
// Check if any of the settings that modify our understanding of files have been changed
363+
// Check if any of the settings that modify our understanding of files have
364+
// been changed.
364365
if !reflect.DeepEqual(a.Env, b.Env) {
365366
return false
366367
}

gopls/internal/regtest/misc/configuration_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,55 @@ var FooErr = errors.New("foo")
5151
})
5252
}
5353

54+
// TestMajorOptionsChange is like TestChangeConfiguration, but modifies an
55+
// an open buffer before making a major (but inconsequential) change that
56+
// causes gopls to recreate the view.
57+
//
58+
// Gopls should not get confused about buffer content when recreating the view.
59+
func TestMajorOptionsChange(t *testing.T) {
60+
t.Skip("broken due to golang/go#57934")
61+
62+
testenv.NeedsGo1Point(t, 17)
63+
64+
const files = `
65+
-- go.mod --
66+
module mod.com
67+
68+
go 1.12
69+
-- a/a.go --
70+
package a
71+
72+
import "errors"
73+
74+
var ErrFoo = errors.New("foo")
75+
`
76+
Run(t, files, func(t *testing.T, env *Env) {
77+
env.OpenFile("a/a.go")
78+
// Introduce a staticcheck diagnostic. It should be detected when we enable
79+
// staticcheck later.
80+
env.RegexpReplace("a/a.go", "ErrFoo", "FooErr")
81+
env.AfterChange(
82+
NoDiagnostics(ForFile("a/a.go")),
83+
)
84+
cfg := env.Editor.Config()
85+
// Any change to environment recreates the view, but this should not cause
86+
// gopls to get confused about the content of a/a.go: we should get the
87+
// staticcheck diagnostic below.
88+
cfg.Env = map[string]string{
89+
"AN_ARBITRARY_VAR": "FOO",
90+
}
91+
cfg.Settings = map[string]interface{}{
92+
"staticcheck": true,
93+
}
94+
// TODO(rfindley): support waiting on diagnostics following a configuration
95+
// change.
96+
env.ChangeConfiguration(cfg)
97+
env.Await(
98+
Diagnostics(env.AtRegexp("a/a.go", "var (FooErr)")),
99+
)
100+
})
101+
}
102+
54103
func TestStaticcheckWarning(t *testing.T) {
55104
// Note: keep this in sync with TestChangeConfiguration.
56105
testenv.SkipAfterGo1Point(t, 16)

0 commit comments

Comments
 (0)