1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07: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" 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 var roots []*actionHandle
for _, a := range analyzers { for _, a := range analyzers {
@ -34,14 +34,14 @@ func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis
return nil, ctx.Err() return nil, ctx.Err()
} }
results := make(map[*analysis.Analyzer][]*source.Error) var results []*source.Error
for _, ah := range roots { for _, ah := range roots {
diagnostics, _, err := ah.analyze(ctx) diagnostics, _, err := ah.analyze(ctx)
if err != nil { if err != nil {
log.Error(ctx, "no results", err) log.Error(ctx, "no results", err)
continue continue
} }
results[ah.analyzer] = diagnostics results = append(results, diagnostics...)
} }
return results, nil 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{} { h := s.view.session.cache.store.Bind(buildActionKey(a, cph), func(ctx context.Context) interface{} {
data := &actionData{} 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 return data
}) })
ah.handle = h ah.handle = h
@ -186,7 +186,7 @@ func execAll(ctx context.Context, fset *token.FileSet, actions []*actionHandle)
return diagnostics, results, g.Wait() 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. // Analyze dependencies.
_, depResults, err := execAll(ctx, fset, act.deps) _, depResults, err := execAll(ctx, fset, act.deps)
if err != nil { if err != nil {

View File

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

View File

@ -172,8 +172,7 @@ func analyses(ctx context.Context, snapshot Snapshot, cph CheckPackageHandle, di
} }
// Report diagnostics and errors from root analyzers. // Report diagnostics and errors from root analyzers.
for _, diags := range diagnostics { for _, e := 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. // 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. // 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. // TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
@ -192,7 +191,6 @@ func analyses(ctx context.Context, snapshot Snapshot, cph CheckPackageHandle, di
Related: e.Related, Related: e.Related,
}) })
} }
}
return nil return nil
} }

View File

@ -262,7 +262,7 @@ type Snapshot interface {
View() View View() View
// Analyze runs the analyses for the given package at this snapshot. // 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. // FindAnalysisError returns the analysis error represented by the diagnostic.
// This is used to get the SuggestedFixes associated with that error. // This is used to get the SuggestedFixes associated with that error.