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 <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/gopls/internal/lsp/cache/view.go b/gopls/internal/lsp/cache/view.go
index fe1479d..d8eb82e 100644
--- a/gopls/internal/lsp/cache/view.go
+++ b/gopls/internal/lsp/cache/view.go
@@ -360,7 +360,8 @@
}
func minorOptionsChange(a, b *source.Options) bool {
- // Check if any of the settings that modify our understanding of files have been changed
+ // Check if any of the settings that modify our understanding of files have
+ // been changed.
if !reflect.DeepEqual(a.Env, b.Env) {
return false
}
diff --git a/gopls/internal/regtest/misc/configuration_test.go b/gopls/internal/regtest/misc/configuration_test.go
index 5af1311..6e6d9d7 100644
--- a/gopls/internal/regtest/misc/configuration_test.go
+++ b/gopls/internal/regtest/misc/configuration_test.go
@@ -51,6 +51,55 @@
})
}
+// TestMajorOptionsChange is like TestChangeConfiguration, but modifies an
+// an open buffer before making a major (but inconsequential) change that
+// causes gopls to recreate the view.
+//
+// Gopls should not get confused about buffer content when recreating the view.
+func TestMajorOptionsChange(t *testing.T) {
+ t.Skip("broken due to golang/go#57934")
+
+ testenv.NeedsGo1Point(t, 17)
+
+ const files = `
+-- go.mod --
+module mod.com
+
+go 1.12
+-- a/a.go --
+package a
+
+import "errors"
+
+var ErrFoo = errors.New("foo")
+`
+ Run(t, files, func(t *testing.T, env *Env) {
+ env.OpenFile("a/a.go")
+ // Introduce a staticcheck diagnostic. It should be detected when we enable
+ // staticcheck later.
+ env.RegexpReplace("a/a.go", "ErrFoo", "FooErr")
+ env.AfterChange(
+ NoDiagnostics(ForFile("a/a.go")),
+ )
+ cfg := env.Editor.Config()
+ // Any change to environment recreates the view, but this should not cause
+ // gopls to get confused about the content of a/a.go: we should get the
+ // staticcheck diagnostic below.
+ cfg.Env = map[string]string{
+ "AN_ARBITRARY_VAR": "FOO",
+ }
+ cfg.Settings = map[string]interface{}{
+ "staticcheck": true,
+ }
+ // TODO(rfindley): support waiting on diagnostics following a configuration
+ // change.
+ env.ChangeConfiguration(cfg)
+ env.Await(
+ Diagnostics(env.AtRegexp("a/a.go", "var (FooErr)")),
+ )
+ })
+}
+
func TestStaticcheckWarning(t *testing.T) {
// Note: keep this in sync with TestChangeConfiguration.
testenv.SkipAfterGo1Point(t, 16)