1
0
mirror of https://github.com/golang/go synced 2024-09-30 18:28:32 -06:00

internal/lsp: remove analyzers from Analyze result

Also, address minor comments that I ignored from Heschi because I am
obnoxious.

Change-Id: I99dcac38578585af2cdd951dd2b9755732ef945f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203281
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2019-10-24 18:15:23 -04:00
parent 3d91e92cde
commit 2077df3685
4 changed files with 24 additions and 27 deletions

View File

@ -17,7 +17,7 @@ import (
errors "golang.org/x/xerrors"
)
func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) (map[*analysis.Analyzer][]*source.Error, error) {
func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) ([]*source.Error, error) {
var roots []*actionHandle
for _, a := range analyzers {
@ -34,14 +34,14 @@ func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis
return nil, ctx.Err()
}
results := make(map[*analysis.Analyzer][]*source.Error)
var results []*source.Error
for _, ah := range roots {
diagnostics, _, err := ah.analyze(ctx)
if err != nil {
log.Error(ctx, "no results", err)
continue
}
results[ah.analyzer] = diagnostics
results = append(results, diagnostics...)
}
return results, nil
}
@ -123,7 +123,7 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.P
}
h := s.view.session.cache.store.Bind(buildActionKey(a, cph), func(ctx context.Context) interface{} {
data := &actionData{}
data.diagnostics, data.result, data.err = run(ctx, s.view.session.cache.fset, ah)
data.diagnostics, data.result, data.err = runAnalysis(ctx, s.view.session.cache.fset, ah)
return data
})
ah.handle = h
@ -186,7 +186,7 @@ func execAll(ctx context.Context, fset *token.FileSet, actions []*actionHandle)
return diagnostics, results, g.Wait()
}
func run(ctx context.Context, fset *token.FileSet, act *actionHandle) ([]*source.Error, interface{}, error) {
func runAnalysis(ctx context.Context, fset *token.FileSet, act *actionHandle) ([]*source.Error, interface{}, error) {
// Analyze dependencies.
_, depResults, err := execAll(ctx, fset, act.deps)
if err != nil {

View File

@ -28,10 +28,9 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara
}
snapshot := view.Snapshot()
fh := snapshot.Handle(ctx, f)
// Determine the supported actions for this file kind.
fileKind := fh.Identity().Kind
fileKind := snapshot.Handle(ctx, f).Identity().Kind
supportedCodeActions, ok := view.Options().SupportedCodeActions[fileKind]
if !ok {
return nil, fmt.Errorf("no supported code actions for %v file kind", fileKind)

View File

@ -172,26 +172,24 @@ func analyses(ctx context.Context, snapshot Snapshot, cph CheckPackageHandle, di
}
// Report diagnostics and errors from root analyzers.
for _, diags := range diagnostics {
for _, e := range diags {
// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
// If we are deleting code as part of all of our suggested fixes, assume that this is dead code.
// TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
var tags []protocol.DiagnosticTag
if onlyDeletions(e.SuggestedFixes) {
tags = append(tags, protocol.Unnecessary)
}
addReport(snapshot.View(), reports, Diagnostic{
URI: e.URI,
Range: e.Range,
Message: e.Message,
Source: e.Category,
Severity: protocol.SeverityWarning,
Tags: tags,
SuggestedFixes: e.SuggestedFixes,
Related: e.Related,
})
for _, e := range diagnostics {
// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
// If we are deleting code as part of all of our suggested fixes, assume that this is dead code.
// TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
var tags []protocol.DiagnosticTag
if onlyDeletions(e.SuggestedFixes) {
tags = append(tags, protocol.Unnecessary)
}
addReport(snapshot.View(), reports, Diagnostic{
URI: e.URI,
Range: e.Range,
Message: e.Message,
Source: e.Category,
Severity: protocol.SeverityWarning,
Tags: tags,
SuggestedFixes: e.SuggestedFixes,
Related: e.Related,
})
}
return nil
}

View File

@ -262,7 +262,7 @@ type Snapshot interface {
View() View
// Analyze runs the analyses for the given package at this snapshot.
Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) (map[*analysis.Analyzer][]*Error, error)
Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) ([]*Error, error)
// FindAnalysisError returns the analysis error represented by the diagnostic.
// This is used to get the SuggestedFixes associated with that error.