mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
internal/lsp: continue diagnostics if diagnosing go.mod fails
This change ensures that diagnostics for .go files get calculated and published regardless of whether or not the go.mod file diagnostics fail. This change also updates lsp_test.SuggestedFix to make use of the snapshot.Diagnose function vs the source.FileDiagnostics. Change-Id: I54c35106b1701b54cca9a413edfb253f3c4c5ab7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/217839 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
4abfd4a162
commit
9e60d4e5b9
@ -55,7 +55,6 @@ func (s *Server) diagnose(ctx context.Context, snapshot source.Snapshot, alwaysA
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, "diagnose: could not generate diagnostics for go.mod file", err)
|
log.Error(ctx, "diagnose: could not generate diagnostics for go.mod file", err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
// Ensure that the reports returned from mod.Diagnostics are only related to the
|
// Ensure that the reports returned from mod.Diagnostics are only related to the
|
||||||
// go.mod file for the module.
|
// go.mod file for the module.
|
||||||
|
@ -343,18 +343,25 @@ func (r *runner) SuggestedFix(t *testing.T, spn span.Span) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
snapshot := view.Snapshot()
|
|
||||||
_, diagnostics, err := source.FileDiagnostics(r.ctx, snapshot, uri)
|
// Get the diagnostics for this view if we have not done it before.
|
||||||
if err != nil {
|
if r.diagnostics == nil {
|
||||||
t.Fatal(err)
|
r.diagnostics = make(map[span.URI][]source.Diagnostic)
|
||||||
|
// Always run diagnostics with analysis.
|
||||||
|
reports := r.server.diagnose(r.ctx, view.Snapshot(), true)
|
||||||
|
for key, diags := range reports {
|
||||||
|
r.diagnostics[key.id.URI] = diags
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
diags := r.diagnostics[uri]
|
||||||
|
|
||||||
actions, err := r.server.CodeAction(r.ctx, &protocol.CodeActionParams{
|
actions, err := r.server.CodeAction(r.ctx, &protocol.CodeActionParams{
|
||||||
TextDocument: protocol.TextDocumentIdentifier{
|
TextDocument: protocol.TextDocumentIdentifier{
|
||||||
URI: protocol.NewURI(uri),
|
URI: protocol.NewURI(uri),
|
||||||
},
|
},
|
||||||
Context: protocol.CodeActionContext{
|
Context: protocol.CodeActionContext{
|
||||||
Only: []protocol.CodeActionKind{protocol.QuickFix},
|
Only: []protocol.CodeActionKind{protocol.QuickFix},
|
||||||
Diagnostics: toProtocolDiagnostics(diagnostics),
|
Diagnostics: toProtocolDiagnostics(diags),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -376,7 +383,7 @@ func (r *runner) SuggestedFix(t *testing.T, spn span.Span) {
|
|||||||
return []byte(got), nil
|
return []byte(got), nil
|
||||||
}))
|
}))
|
||||||
if fixed != got {
|
if fixed != got {
|
||||||
t.Errorf("suggested fixes failed for %s, expected:\n%v\ngot:\n%v", filename, fixed, got)
|
t.Errorf("suggested fixes failed for %s, expected:\n%#v\ngot:\n%#v", filename, fixed, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user