From 6822f1ada4f88619453e62599af04f44363982ca Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 10 Feb 2020 23:39:20 -0500 Subject: [PATCH] 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 Reviewed-by: Heschi Kreinick --- gopls/internal/hooks/analysis.go | 6 ++++++ internal/lsp/source/options.go | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) 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, }