Skip to content

Commit 2077df3

Browse files
committed
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 <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3d91e92 commit 2077df3

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

internal/lsp/cache/analysis.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
errors "golang.org/x/xerrors"
1818
)
1919

20-
func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) (map[*analysis.Analyzer][]*source.Error, error) {
20+
func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) ([]*source.Error, error) {
2121
var roots []*actionHandle
2222

2323
for _, a := range analyzers {
@@ -34,14 +34,14 @@ func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis
3434
return nil, ctx.Err()
3535
}
3636

37-
results := make(map[*analysis.Analyzer][]*source.Error)
37+
var results []*source.Error
3838
for _, ah := range roots {
3939
diagnostics, _, err := ah.analyze(ctx)
4040
if err != nil {
4141
log.Error(ctx, "no results", err)
4242
continue
4343
}
44-
results[ah.analyzer] = diagnostics
44+
results = append(results, diagnostics...)
4545
}
4646
return results, nil
4747
}
@@ -123,7 +123,7 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.P
123123
}
124124
h := s.view.session.cache.store.Bind(buildActionKey(a, cph), func(ctx context.Context) interface{} {
125125
data := &actionData{}
126-
data.diagnostics, data.result, data.err = run(ctx, s.view.session.cache.fset, ah)
126+
data.diagnostics, data.result, data.err = runAnalysis(ctx, s.view.session.cache.fset, ah)
127127
return data
128128
})
129129
ah.handle = h
@@ -186,7 +186,7 @@ func execAll(ctx context.Context, fset *token.FileSet, actions []*actionHandle)
186186
return diagnostics, results, g.Wait()
187187
}
188188

189-
func run(ctx context.Context, fset *token.FileSet, act *actionHandle) ([]*source.Error, interface{}, error) {
189+
func runAnalysis(ctx context.Context, fset *token.FileSet, act *actionHandle) ([]*source.Error, interface{}, error) {
190190
// Analyze dependencies.
191191
_, depResults, err := execAll(ctx, fset, act.deps)
192192
if err != nil {

internal/lsp/code_action.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara
2828
}
2929

3030
snapshot := view.Snapshot()
31-
fh := snapshot.Handle(ctx, f)
3231

3332
// Determine the supported actions for this file kind.
34-
fileKind := fh.Identity().Kind
33+
fileKind := snapshot.Handle(ctx, f).Identity().Kind
3534
supportedCodeActions, ok := view.Options().SupportedCodeActions[fileKind]
3635
if !ok {
3736
return nil, fmt.Errorf("no supported code actions for %v file kind", fileKind)

internal/lsp/source/diagnostics.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,24 @@ func analyses(ctx context.Context, snapshot Snapshot, cph CheckPackageHandle, di
172172
}
173173

174174
// Report diagnostics and errors from root analyzers.
175-
for _, diags := range diagnostics {
176-
for _, e := range diags {
177-
// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
178-
// If we are deleting code as part of all of our suggested fixes, assume that this is dead code.
179-
// TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
180-
var tags []protocol.DiagnosticTag
181-
if onlyDeletions(e.SuggestedFixes) {
182-
tags = append(tags, protocol.Unnecessary)
183-
}
184-
addReport(snapshot.View(), reports, Diagnostic{
185-
URI: e.URI,
186-
Range: e.Range,
187-
Message: e.Message,
188-
Source: e.Category,
189-
Severity: protocol.SeverityWarning,
190-
Tags: tags,
191-
SuggestedFixes: e.SuggestedFixes,
192-
Related: e.Related,
193-
})
175+
for _, e := range diagnostics {
176+
// This is a bit of a hack, but clients > 3.15 will be able to grey out unnecessary code.
177+
// If we are deleting code as part of all of our suggested fixes, assume that this is dead code.
178+
// TODO(golang/go/#34508): Return these codes from the diagnostics themselves.
179+
var tags []protocol.DiagnosticTag
180+
if onlyDeletions(e.SuggestedFixes) {
181+
tags = append(tags, protocol.Unnecessary)
194182
}
183+
addReport(snapshot.View(), reports, Diagnostic{
184+
URI: e.URI,
185+
Range: e.Range,
186+
Message: e.Message,
187+
Source: e.Category,
188+
Severity: protocol.SeverityWarning,
189+
Tags: tags,
190+
SuggestedFixes: e.SuggestedFixes,
191+
Related: e.Related,
192+
})
195193
}
196194
return nil
197195
}

internal/lsp/source/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ type Snapshot interface {
262262
View() View
263263

264264
// Analyze runs the analyses for the given package at this snapshot.
265-
Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) (map[*analysis.Analyzer][]*Error, error)
265+
Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) ([]*Error, error)
266266

267267
// FindAnalysisError returns the analysis error represented by the diagnostic.
268268
// This is used to get the SuggestedFixes associated with that error.

0 commit comments

Comments
 (0)