Repository navigation
Expand file tree
/
Copy pathconfiguration_test.go
More file actions
executable file
·199 lines (168 loc) · 4.4 KB
/
Copy pathconfiguration_test.go
File metadata and controls
executable file
·199 lines (168 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package misc
import (
"testing"
. "golang.org/x/tools/gopls/internal/test/integration"
"golang.org/x/tools/internal/testenv"
)
// Test that enabling and disabling produces the expected results of showing
// and hiding staticcheck analysis results.
func TestChangeConfiguration(t *testing.T) {
// Staticcheck only supports Go versions >= 1.19.
// Note: keep this in sync with TestStaticcheckWarning. Below this version we
// should get an error when setting staticcheck configuration.
testenv.NeedsGo1Point(t, 20)
const files = `
-- go.mod --
module mod.com
go 1.12
-- a/a.go --
package a
import "errors"
// FooErr should be called ErrFoo (ST1012)
var FooErr = errors.New("foo")
`
Run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("a/a.go")
env.AfterChange(
NoDiagnostics(ForFile("a/a.go")),
)
cfg := env.Editor.Config()
cfg.Settings = map[string]interface{}{
"staticcheck": true,
}
env.ChangeConfiguration(cfg)
env.AfterChange(
Diagnostics(env.AtRegexp("a/a.go", "var (FooErr)")),
)
})
}
// Test that clients can configure per-workspace configuration, which is
// queried via the scopeURI of a workspace/configuration request.
// (this was broken in golang/go#65519).
func TestWorkspaceConfiguration(t *testing.T) {
const files = `
-- go.mod --
module example.com/config
go 1.18
-- a/a.go --
package a
import "example.com/config/b"
func _() {
_ = b.B{2}
}
-- b/b.go --
package b
type B struct {
F int
}
`
WithOptions(
WorkspaceFolders("a"),
FolderSettings{
"a": {
"analyses": map[string]bool{
"composites": false,
},
},
},
).Run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("a/a.go")
env.AfterChange(NoDiagnostics())
})
}
// 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) {
testenv.NeedsGo1Point(t, 20) // needs staticcheck
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,
}
env.ChangeConfiguration(cfg)
env.AfterChange(
Diagnostics(env.AtRegexp("a/a.go", "var (FooErr)")),
)
})
}
func TestStaticcheckWarning(t *testing.T) {
// Note: keep this in sync with TestChangeConfiguration.
testenv.SkipAfterGo1Point(t, 19)
const files = `
-- go.mod --
module mod.com
go 1.12
-- a/a.go --
package a
import "errors"
// FooErr should be called ErrFoo (ST1012)
var FooErr = errors.New("foo")
`
WithOptions(
Settings{"staticcheck": true},
).Run(t, files, func(t *testing.T, env *Env) {
env.OnceMet(
InitialWorkspaceLoad,
ShownMessage("staticcheck is not supported"),
)
})
}
func TestGofumptWarning(t *testing.T) {
testenv.SkipAfterGo1Point(t, 17)
WithOptions(
Settings{"gofumpt": true},
).Run(t, "", func(t *testing.T, env *Env) {
env.OnceMet(
InitialWorkspaceLoad,
ShownMessage("gofumpt is not supported"),
)
})
}
func TestDeprecatedSettings(t *testing.T) {
WithOptions(
Settings{
"experimentalUseInvalidMetadata": true,
"experimentalWatchedFileDelay": "1s",
"experimentalWorkspaceModule": true,
"tempModfile": true,
"allowModfileModifications": true,
},
).Run(t, "", func(t *testing.T, env *Env) {
env.OnceMet(
InitialWorkspaceLoad,
ShownMessage("experimentalWorkspaceModule"),
ShownMessage("experimentalUseInvalidMetadata"),
ShownMessage("experimentalWatchedFileDelay"),
ShownMessage("tempModfile"),
ShownMessage("allowModfileModifications"),
)
})
}