mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
internal/lsp: parse filenames only out of go list errors
This changes the packageErrorSpan function into the listErrorSpan. Previously, this was causing the gopls-generated errors to get parsed, which would result in attempts to send diagnostics for invalid filenames. Fixes golang/go#32603 Change-Id: I7a54ed8884b78beb3f894598f18a24ed232f7412 Reviewed-on: https://go-review.googlesource.com/c/tools/+/182460 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
61e0f78580
commit
9a3b5d688f
4
internal/lsp/cache/load.go
vendored
4
internal/lsp/cache/load.go
vendored
@ -83,13 +83,13 @@ func (v *view) checkMetadata(ctx context.Context, f *goFile) ([]packages.Error,
|
||||
pkgs, err := packages.Load(v.buildConfig(), fmt.Sprintf("file=%s", f.filename()))
|
||||
if len(pkgs) == 0 {
|
||||
if err == nil {
|
||||
err = fmt.Errorf("no packages found for %s", f.filename())
|
||||
err = fmt.Errorf("go/packages.Load: no packages found for %s", f.filename())
|
||||
}
|
||||
// Return this error as a diagnostic to the user.
|
||||
return []packages.Error{
|
||||
{
|
||||
Msg: err.Error(),
|
||||
Kind: packages.ListError,
|
||||
Kind: packages.UnknownError,
|
||||
},
|
||||
}, err
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ func (s *Server) Diagnostics(ctx context.Context, v source.View, uri span.URI) {
|
||||
if s.undelivered == nil {
|
||||
s.undelivered = make(map[span.URI][]source.Diagnostic)
|
||||
}
|
||||
s.session.Logger().Errorf(ctx, "failed to deliver diagnostic for %s (will retry): %v", uri, err)
|
||||
s.undelivered[uri] = diagnostics
|
||||
continue
|
||||
}
|
||||
@ -51,9 +52,8 @@ func (s *Server) Diagnostics(ctx context.Context, v source.View, uri span.URI) {
|
||||
// Anytime we compute diagnostics, make sure to also send along any
|
||||
// undelivered ones (only for remaining URIs).
|
||||
for uri, diagnostics := range s.undelivered {
|
||||
err := s.publishDiagnostics(ctx, v, uri, diagnostics)
|
||||
if err != nil {
|
||||
s.session.Logger().Errorf(ctx, "failed to deliver diagnostic for %s: %v", uri, err)
|
||||
if err := s.publishDiagnostics(ctx, v, uri, diagnostics); err != nil {
|
||||
s.session.Logger().Errorf(ctx, "failed to deliver diagnostic for %s (will not retry): %v", uri, err)
|
||||
}
|
||||
// If we fail to deliver the same diagnostics twice, just give up.
|
||||
delete(s.undelivered, uri)
|
||||
|
@ -63,8 +63,11 @@ func Diagnostics(ctx context.Context, v View, f GoFile, disabledAnalyses map[str
|
||||
}
|
||||
|
||||
// Prepare any additional reports for the errors in this package.
|
||||
for _, pkgErr := range pkg.GetErrors() {
|
||||
addReport(v, reports, packageErrorSpan(pkgErr).URI(), nil)
|
||||
for _, err := range pkg.GetErrors() {
|
||||
if err.Kind != packages.ListError {
|
||||
continue
|
||||
}
|
||||
addReport(v, reports, listErrorSpan(err).URI(), nil)
|
||||
}
|
||||
|
||||
// Run diagnostics for the package that this URI belongs to.
|
||||
@ -108,7 +111,7 @@ func diagnostics(ctx context.Context, v View, pkg Package, reports map[span.URI]
|
||||
diags = listErrors
|
||||
}
|
||||
for _, diag := range diags {
|
||||
spn := packageErrorSpan(diag)
|
||||
spn := listErrorSpan(diag)
|
||||
if spn.IsPoint() && diag.Kind == packages.TypeError {
|
||||
spn = pointToSpan(ctx, v, spn)
|
||||
}
|
||||
@ -178,7 +181,7 @@ func parseDiagnosticMessage(input string) span.Span {
|
||||
return span.Parse(input[:msgIndex])
|
||||
}
|
||||
|
||||
func packageErrorSpan(pkgErr packages.Error) span.Span {
|
||||
func listErrorSpan(pkgErr packages.Error) span.Span {
|
||||
if pkgErr.Pos == "" {
|
||||
return parseDiagnosticMessage(pkgErr.Msg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user