Skip to content

Commit 3b28f2c

Browse files
committed
internal/lsp: disable nilness analyzer, unless staticcheck enabled
Users with staticcheck enabled will be more tolerant of increased RAM usage. We might be able to disable this check entirely once the next version of staticcheck is released with a similar analysis (https://staticcheck.io/docs/checks#SA5011). Change-Id: I1a844cc226e34e0f62222f12912797a6cc9d06e2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/219018 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> (cherry picked from commit 6822f1a) Reviewed-on: https://go-review.googlesource.com/c/tools/+/219198 Reviewed-by: Robert Findley <[email protected]>
1 parent c6d828b commit 3b28f2c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

gopls/internal/hooks/analysis.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package hooks
66

77
import (
8+
"golang.org/x/tools/go/analysis/passes/nilness"
89
"golang.org/x/tools/internal/lsp/source"
910
"honnef.co/go/tools/simple"
1011
"honnef.co/go/tools/staticcheck"
@@ -26,5 +27,10 @@ func updateAnalyzers(options *source.Options) {
2627
for _, a := range stylecheck.Analyzers {
2728
options.Analyzers[a.Name] = a
2829
}
30+
// Add the nilness analyzer only for users who have enabled staticcheck.
31+
// The assumption here is that a user who has enabled staticcheck will
32+
// be fine with gopls using significantly more memory. nilness requires
33+
// SSA, which makes it expensive.
34+
options.Analyzers[nilness.Analyzer.Name] = nilness.Analyzer
2935
}
3036
}

internal/lsp/source/options.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"golang.org/x/tools/go/analysis/passes/loopclosure"
2727
"golang.org/x/tools/go/analysis/passes/lostcancel"
2828
"golang.org/x/tools/go/analysis/passes/nilfunc"
29-
"golang.org/x/tools/go/analysis/passes/nilness"
3029
"golang.org/x/tools/go/analysis/passes/printf"
3130
"golang.org/x/tools/go/analysis/passes/shift"
3231
"golang.org/x/tools/go/analysis/passes/sortslice"
@@ -493,7 +492,6 @@ var defaultAnalyzers = map[string]*analysis.Analyzer{
493492

494493
// Non-vet analyzers
495494
deepequalerrors.Analyzer.Name: deepequalerrors.Analyzer,
496-
nilness.Analyzer.Name: nilness.Analyzer,
497495
sortslice.Analyzer.Name: sortslice.Analyzer,
498496
testinggoroutine.Analyzer.Name: testinggoroutine.Analyzer,
499497
}

0 commit comments

Comments
 (0)