1
0
mirror of https://github.com/golang/go synced 2024-11-18 06:14:46 -07:00

internal/lsp: add options to control which details gc_details shows

The gc_details command, which shows the gc compiler's decisions, can
produce thousands of diagnostics for a package. New gopls options
'noBounds', 'noEscape', 'noInline', 'noNilcheck' will suppress diagnostics
of less interest to the user. These are in a new 'annotations' section
parallel to 'codelens' or 'analyses'.

Change-Id: Ica75de25b14f38b67ddfa9f997f581674f45221d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/246477
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Peter Weinbergr 2020-08-03 13:09:45 -04:00 committed by Peter Weinberger
parent f29cbc7105
commit 0b898c9289
3 changed files with 63 additions and 5 deletions

View File

@ -147,10 +147,6 @@ If true, this enables server side fuzzy matching of completion candidates.
Default: `true`.
### **staticcheck** *boolean*
If true, it enables the use of the staticcheck.io analyzers.
### **matcher** *string*
Defines the algorithm that is used when calculating completion candidates. Must be one of:
@ -159,7 +155,21 @@ Defines the algorithm that is used when calculating completion candidates. Must
* `"caseSensitive"`
* `"caseInsensitive"`
Default: `"caseInsensitive"`.
Default: `"caseInsensitive"`
### **annotations** *map[string]bool*
**noBounds** suppresses gc_details diagnostics about bounds checking.
**noEscape** suppresses gc_details diagnostics about escape analysis.
**noInline** suppresses gc_details diagnostics about inlining.
**noNilcheck** suppresses gc_details diagnostics about generated nil checks.
### **staticcheck** *boolean*
If true, it enables the use of the staticcheck.io analyzers.
### **symbolMatcher** *string*

View File

@ -33,6 +33,7 @@ func GCOptimizationDetails(ctx context.Context, snapshot Snapshot, pkgDir span.U
return nil, err
}
reports := make(map[VersionedFileIdentity][]*Diagnostic)
opts := snapshot.View().Options()
var parseError error
for _, fn := range files {
fname, v, err := parseDetailsFile(fn)
@ -48,11 +49,38 @@ func GCOptimizationDetails(ctx context.Context, snapshot Snapshot, pkgDir span.U
if x == nil {
continue
}
v = filterDiagnostics(v, &opts)
reports[x.VersionedFileIdentity()] = v
}
return reports, parseError
}
func filterDiagnostics(v []*Diagnostic, o *Options) []*Diagnostic {
var ans []*Diagnostic
for _, x := range v {
if x.Source != "go compiler" {
continue
}
if o.Annotations["noInline"] &&
(strings.HasPrefix(x.Message, "canInline") ||
strings.HasPrefix(x.Message, "cannotInline") ||
strings.HasPrefix(x.Message, "inlineCall")) {
continue
} else if o.Annotations["noEscape"] &&
(strings.HasPrefix(x.Message, "escape") || x.Message == "leak") {
continue
} else if o.Annotations["noNilcheck"] && strings.HasPrefix(x.Message, "nilcheck") {
continue
} else if o.Annotations["noBounds"] &&
(strings.HasPrefix(x.Message, "isInBounds") ||
strings.HasPrefix(x.Message, "isSliceInBounds")) {
continue
}
ans = append(ans, x)
}
return ans
}
func parseDetailsFile(fn string) (string, []*Diagnostic, error) {
buf, err := ioutil.ReadFile(fn)
if err != nil {

View File

@ -281,6 +281,14 @@ type ExperimentalOptions struct {
// VerboseWorkDoneProgress controls whether the LSP server should send
// progress reports for all work done outside the scope of an RPC.
VerboseWorkDoneProgress bool
// Annotations suppress various kinds of optimization diagnostics
// that would be reported by the gc_details command.
// noNilcheck suppresses display of nilchecks.
// noEscape suppresses escape choices.
// noInline suppresses inlining choices.
// noBounds suppresses bounds checking diagnositcs.
Annotations map[string]bool
}
// DebuggingOptions should not affect the logical execution of Gopls, but may
@ -526,6 +534,18 @@ func (o *Options) set(name string, value interface{}) OptionResult {
case "analyses":
result.setBoolMap(&o.UserEnabledAnalyses)
case "annotations":
result.setBoolMap(&o.Annotations)
for k := range o.Annotations {
switch k {
case "noEscape", "noNilcheck", "noInline", "noBounds":
continue
default:
result.Name += ":" + k // put mistake(s) in the message
result.State = OptionUnexpected
}
}
case "codelens":
var lensOverrides map[string]bool
result.setBoolMap(&lensOverrides)