golang.org/x/tools/gopls@v0.15.3/internal/settings/analyzer.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package settings 6 7 import ( 8 "golang.org/x/tools/go/analysis" 9 "golang.org/x/tools/gopls/internal/protocol" 10 ) 11 12 // Analyzer augments a go/analysis analyzer with additional LSP configuration. 13 type Analyzer struct { 14 Analyzer *analysis.Analyzer 15 16 // Enabled reports whether the analyzer is enabled. This value can be 17 // configured per-analysis in user settings. For staticcheck analyzers, 18 // the value of the Staticcheck setting overrides this field. 19 // 20 // Most clients should use the IsEnabled method. 21 Enabled bool 22 23 // ActionKinds is the set of kinds of code action this analyzer produces. 24 // If empty, the set is just QuickFix. 25 ActionKinds []protocol.CodeActionKind 26 27 // Severity is the severity set for diagnostics reported by this 28 // analyzer. If left unset it defaults to Warning. 29 // 30 // Note: diagnostics with severity protocol.SeverityHint do not show up in 31 // the VS Code "problems" tab. 32 Severity protocol.DiagnosticSeverity 33 34 // Tag is extra tags (unnecessary, deprecated, etc) for diagnostics 35 // reported by this analyzer. 36 Tag []protocol.DiagnosticTag 37 } 38 39 func (a *Analyzer) String() string { return a.Analyzer.String() } 40 41 // IsEnabled reports whether this analyzer is enabled by the given options. 42 func (a Analyzer) IsEnabled(options *Options) bool { 43 // Staticcheck analyzers can only be enabled when staticcheck is on. 44 if _, ok := options.StaticcheckAnalyzers[a.Analyzer.Name]; ok { 45 if !options.Staticcheck { 46 return false 47 } 48 } 49 if enabled, ok := options.Analyses[a.Analyzer.Name]; ok { 50 return enabled 51 } 52 return a.Enabled 53 }