Skip to content

Commit 2e5e03c

Browse files
ethanalee-workgopherbot
authored andcommitted
internal/mod: disable legacy CodeLensRunGovulncheck conditionally
- If CodeLensVulncheck is enabled, then disable CodeLensRunGovulncheck, otherwise two identical "Run govulncheck" codelenses will appear in the IDE, which makes for an unpleasant UX. Change-Id: I3921490965a4e1b3086adf6695f10e0dca2b2b2d Reviewed-on: https://go-review.googlesource.com/c/tools/+/706898 Reviewed-by: Hongxiang Jiang <hxjiang@golang.org> Auto-Submit: Ethan Lee <ethanalee@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 9f84208 commit 2e5e03c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

gopls/internal/mod/code_lens.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func vulncheckLenses(ctx context.Context, snapshot *cache.Snapshot, fh file.Hand
173173
}
174174

175175
func runGovulncheckLenses(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle) ([]protocol.CodeLens, error) {
176+
// If CodeLensVulncheck is enabled, do not use the legacy CodeLensRunGovulncheck.
177+
if snapshot.Options().UserOptions.UIOptions.Codelenses[settings.CodeLensVulncheck] {
178+
return nil, nil
179+
}
180+
176181
pm, err := snapshot.ParseMod(ctx, fh)
177182
if err != nil || pm.File == nil {
178183
return nil, err

gopls/internal/settings/settings.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,15 @@ func (o *Options) setOne(name string, value any) (applied []CounterPath, _ error
12391239
counts = append(counts, CounterPath{string(k), fmt.Sprint(v)})
12401240
}
12411241

1242+
var errs []string
12421243
if name == "codelens" {
1243-
return counts, deprecatedError("codelenses")
1244+
errs = append(errs, deprecatedError("codelenses").Error())
1245+
}
1246+
if lensOverrides[CodeLensRunGovulncheck] && lensOverrides[CodeLensVulncheck] {
1247+
errs = append(errs, "The 'run_govulncheck' codelens is superseded by the 'vulncheck' codelens. Only 'vulncheck' should be set.")
1248+
}
1249+
if len(errs) > 0 {
1250+
return counts, &SoftError{msg: strings.Join(errs, "\n")}
12441251
}
12451252
return counts, nil
12461253

gopls/internal/test/integration/misc/vuln_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func main() {
193193

194194
for _, legacy := range []bool{false, true} {
195195
t.Run(fmt.Sprintf("legacy=%v", legacy), func(t *testing.T) {
196+
lenses := map[string]bool{"vulncheck": !legacy, "run_govulncheck": legacy}
196197
WithOptions(
197198
EnvVars{
198199
// Let the analyzer read vulnerabilities data from the testdata/vulndb.
@@ -204,10 +205,7 @@ func main() {
204205
"_GOPLS_TEST_BINARY_RUN_AS_GOPLS": "true", // needed to run `gopls vulncheck`.
205206
},
206207
Settings{
207-
"codelenses": map[string]bool{
208-
"run_govulncheck": true,
209-
"vulncheck": true,
210-
},
208+
"codelenses": lenses,
211209
},
212210
).Run(t, files, func(t *testing.T, env *Env) {
213211
env.OpenFile("go.mod")

0 commit comments

Comments
 (0)