gopls/internal/regtest: simplify regtest EditorConfig
WithEditorConfig(fake.EditorConfig{...}) seemed like unnecessary
boilerplate. Simplify the option to just 'EditorConfig'.
Change-Id: I11a3045388f8e642caff78a3f0caa13374b4713a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255124
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/regtest/bench_test.go b/gopls/internal/regtest/bench_test.go
index 9cb8ffd..54ed988 100644
--- a/gopls/internal/regtest/bench_test.go
+++ b/gopls/internal/regtest/bench_test.go
@@ -9,7 +9,6 @@
"fmt"
"testing"
- "golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
)
@@ -56,14 +55,14 @@
t.Skip("-symbol_workdir not configured")
}
opts := stressTestOptions(symbolBench.workdir)
- conf := fake.EditorConfig{}
+ conf := EditorConfig{}
if symbolBench.matcher != "" {
conf.SymbolMatcher = &symbolBench.matcher
}
if symbolBench.style != "" {
conf.SymbolStyle = &symbolBench.style
}
- opts = append(opts, WithEditorConfig(conf))
+ opts = append(opts, conf)
withOptions(opts...).run(t, "", func(t *testing.T, env *Env) {
// We can't Await in this test, since we have disabled hooks. Instead, run
// one symbol request to completion to ensure all necessary cache entries
diff --git a/gopls/internal/regtest/codelens_test.go b/gopls/internal/regtest/codelens_test.go
index 8402e9b..3fcfdce 100644
--- a/gopls/internal/regtest/codelens_test.go
+++ b/gopls/internal/regtest/codelens_test.go
@@ -7,7 +7,6 @@
import (
"testing"
- "golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/lsp/tests"
@@ -48,13 +47,15 @@
}
for _, test := range tests {
t.Run(test.label, func(t *testing.T) {
- runner.Run(t, workspace, func(t *testing.T, env *Env) {
+ withOptions(
+ EditorConfig{CodeLens: test.enabled},
+ ).run(t, workspace, func(t *testing.T, env *Env) {
env.OpenFile("lib.go")
lens := env.CodeLens("lib.go")
if gotCodeLens := len(lens) > 0; gotCodeLens != test.wantCodeLens {
t.Errorf("got codeLens: %t, want %t", gotCodeLens, test.wantCodeLens)
}
- }, WithEditorConfig(fake.EditorConfig{CodeLens: test.enabled}))
+ })
})
}
}
diff --git a/gopls/internal/regtest/diagnostics_test.go b/gopls/internal/regtest/diagnostics_test.go
index 44b3003..d86ff44 100644
--- a/gopls/internal/regtest/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics_test.go
@@ -438,8 +438,8 @@
fmt.Println("Hello World")
}
`
- editorConfig := fake.EditorConfig{Env: map[string]string{"GOPATH": ""}}
- withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
+ editorConfig := EditorConfig{Env: map[string]string{"GOPATH": ""}}
+ withOptions(editorConfig).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.Await(env.DiagnosticAtRegexp("main.go", "fmt"))
env.SaveBuffer("main.go")
@@ -462,8 +462,8 @@
var X = 0
`
- editorConfig := fake.EditorConfig{Env: map[string]string{"GOFLAGS": "-tags=foo"}}
- withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
+ editorConfig := EditorConfig{Env: map[string]string{"GOFLAGS": "-tags=foo"}}
+ withOptions(editorConfig).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.OrganizeImports("main.go")
env.Await(EmptyDiagnostics("main.go"))
@@ -556,9 +556,9 @@
`
for _, go111module := range []string{"on", "off", ""} {
t.Run(fmt.Sprintf("GO111MODULE_%v", go111module), func(t *testing.T) {
- withOptions(WithEditorConfig(fake.EditorConfig{
+ withOptions(EditorConfig{
Env: map[string]string{"GO111MODULE": go111module},
- })).run(t, files, func(t *testing.T, env *Env) {
+ }).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("hello.txt")
env.Await(
OnceMet(
@@ -642,7 +642,9 @@
_ = conf.ErrHelpWanted
}
`
- runner.Run(t, ardanLabs, func(t *testing.T, env *Env) {
+ withOptions(
+ WithProxyFiles(ardanLabsProxy),
+ ).run(t, ardanLabs, func(t *testing.T, env *Env) {
// Expect a diagnostic with a suggested fix to add
// "github.com/ardanlabs/conf" to the go.mod file.
env.OpenFile("go.mod")
@@ -686,7 +688,7 @@
env.Await(
env.DiagnosticAtRegexp("main.go", `"github.com/ardanlabs/conf"`),
)
- }, WithProxyFiles(ardanLabsProxy))
+ })
}
// Test for golang/go#38207.
@@ -699,7 +701,9 @@
go 1.12
-- main.go --
`
- runner.Run(t, emptyFile, func(t *testing.T, env *Env) {
+ withOptions(
+ WithProxyFiles(ardanLabsProxy),
+ ).run(t, emptyFile, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.OpenFile("go.mod")
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, `package main
@@ -722,7 +726,7 @@
env.Await(
EmptyDiagnostics("main.go"),
)
- }, WithProxyFiles(ardanLabsProxy))
+ })
}
// Test for golang/go#36960.
@@ -1263,7 +1267,7 @@
`
withOptions(
- WithEditorConfig(fake.EditorConfig{EnableStaticcheck: true}),
+ EditorConfig{EnableStaticcheck: true},
).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
// Staticcheck should generate a diagnostic to simplify this literal.
diff --git a/gopls/internal/regtest/imports_test.go b/gopls/internal/regtest/imports_test.go
index 79e70d4..f570fa1 100644
--- a/gopls/internal/regtest/imports_test.go
+++ b/gopls/internal/regtest/imports_test.go
@@ -7,7 +7,6 @@
"strings"
"testing"
- "golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/testenv"
)
@@ -143,9 +142,9 @@
t.Fatal(err)
}
defer os.RemoveAll(modcache)
- editorConfig := fake.EditorConfig{Env: map[string]string{"GOMODCACHE": modcache}}
+ editorConfig := EditorConfig{Env: map[string]string{"GOMODCACHE": modcache}}
withOptions(
- WithEditorConfig(editorConfig),
+ editorConfig,
WithProxyFiles(proxy),
).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
diff --git a/gopls/internal/regtest/runner.go b/gopls/internal/regtest/runner.go
index ad38463..10d4bc4 100644
--- a/gopls/internal/regtest/runner.go
+++ b/gopls/internal/regtest/runner.go
@@ -117,11 +117,11 @@
})
}
-// WithEditorConfig configures the editor's LSP session.
-func WithEditorConfig(config fake.EditorConfig) RunOption {
- return optionSetter(func(opts *runConfig) {
- opts.editor = config
- })
+// EditorConfig is a RunOption option that configured the regtest editor.
+type EditorConfig fake.EditorConfig
+
+func (c EditorConfig) set(opts *runConfig) {
+ opts.editor = fake.EditorConfig(c)
}
// WithoutWorkspaceFolders prevents workspace folders from being sent as part
diff --git a/gopls/internal/regtest/symbol_test.go b/gopls/internal/regtest/symbol_test.go
index 68f3de4..af60488 100644
--- a/gopls/internal/regtest/symbol_test.go
+++ b/gopls/internal/regtest/symbol_test.go
@@ -7,7 +7,6 @@
import (
"testing"
- "golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/protocol"
)
@@ -193,10 +192,9 @@
func checkChecks(t *testing.T, matcher string, checks map[string]*expSymbolInformation) {
t.Helper()
- opts := []RunOption{
- WithEditorConfig(fake.EditorConfig{SymbolMatcher: &matcher}),
- }
- runner.Run(t, symbolSetup, func(t *testing.T, env *Env) {
+ withOptions(
+ EditorConfig{SymbolMatcher: &matcher},
+ ).run(t, symbolSetup, func(t *testing.T, env *Env) {
t.Run(matcher, func(t *testing.T) {
for query, exp := range checks {
t.Run(query, func(t *testing.T) {
@@ -207,5 +205,5 @@
})
}
})
- }, opts...)
+ })
}
diff --git a/gopls/internal/regtest/unix_test.go b/gopls/internal/regtest/unix_test.go
index e67de38..cfdf094 100644
--- a/gopls/internal/regtest/unix_test.go
+++ b/gopls/internal/regtest/unix_test.go
@@ -8,8 +8,6 @@
import (
"testing"
-
- "golang.org/x/tools/internal/lsp/fake"
)
func TestBadGOPATH(t *testing.T) {
@@ -21,12 +19,10 @@
fmt.Println("Hello World")
}
`
- editorConfig := fake.EditorConfig{
- Env: map[string]string{"GOPATH": ":/path/to/gopath"},
- }
- // Test the case given in
// https://github.com/fatih/vim-go/issues/2673#issuecomment-622307211.
- withOptions(WithEditorConfig(editorConfig)).run(t, files, func(t *testing.T, env *Env) {
+ withOptions(
+ EditorConfig{Env: map[string]string{"GOPATH": ":/path/to/gopath"}},
+ ).run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
env.Await(env.DiagnosticAtRegexp("main.go", "fmt"))
if err := env.Editor.OrganizeImports(env.Ctx, "main.go"); err != nil {