diff --git a/gopls/internal/hooks/analysis.go b/gopls/internal/hooks/analysis.go index 629bdc8669..8e300f3991 100644 --- a/gopls/internal/hooks/analysis.go +++ b/gopls/internal/hooks/analysis.go @@ -5,6 +5,7 @@ package hooks import ( + "golang.org/x/tools/go/analysis/passes/nilness" "golang.org/x/tools/internal/lsp/source" "honnef.co/go/tools/simple" "honnef.co/go/tools/staticcheck" @@ -26,5 +27,10 @@ func updateAnalyzers(options *source.Options) { for _, a := range stylecheck.Analyzers { options.Analyzers[a.Name] = a } + // Add the nilness analyzer only for users who have enabled staticcheck. + // The assumption here is that a user who has enabled staticcheck will + // be fine with gopls using significantly more memory. nilness requires + // SSA, which makes it expensive. + options.Analyzers[nilness.Analyzer.Name] = nilness.Analyzer } } diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index b32c49cffb..088e9d816f 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -26,7 +26,6 @@ import ( "golang.org/x/tools/go/analysis/passes/loopclosure" "golang.org/x/tools/go/analysis/passes/lostcancel" "golang.org/x/tools/go/analysis/passes/nilfunc" - "golang.org/x/tools/go/analysis/passes/nilness" "golang.org/x/tools/go/analysis/passes/printf" "golang.org/x/tools/go/analysis/passes/shift" "golang.org/x/tools/go/analysis/passes/sortslice" @@ -488,7 +487,6 @@ func defaultAnalyzers() map[string]*analysis.Analyzer { // Non-vet analyzers deepequalerrors.Analyzer.Name: deepequalerrors.Analyzer, - nilness.Analyzer.Name: nilness.Analyzer, sortslice.Analyzer.Name: sortslice.Analyzer, testinggoroutine.Analyzer.Name: testinggoroutine.Analyzer, }