internal/lsp/cache: avoid returning errors when building source.Errors
We don't want to return an error for the whole package when we are just
building out error positions.
Change-Id: I56b5b88ff2b4b44da8a372ade81cd9b1534235c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206597
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
(cherry picked from commit 52adfe5cb642c4a8e4fdc4fd5e33c0f4f1e41cfd)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206877
diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go
index fb7772e..41ed042 100644
--- a/internal/lsp/cache/check.go
+++ b/internal/lsp/cache/check.go
@@ -310,7 +310,8 @@
for _, e := range rawErrors {
srcErr, err := sourceError(ctx, fset, pkg, e)
if err != nil {
- return nil, err
+ log.Error(ctx, "unable to compute error positions", err, telemetry.Package.Of(pkg.ID()))
+ continue
}
pkg.errors = append(pkg.errors, srcErr)
}
diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go
index 57740ff..984a8f4 100644
--- a/internal/lsp/cache/errors.go
+++ b/internal/lsp/cache/errors.go
@@ -12,7 +12,9 @@
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
+ "golang.org/x/tools/internal/lsp/telemetry"
"golang.org/x/tools/internal/span"
+ "golang.org/x/tools/internal/telemetry/log"
errors "golang.org/x/xerrors"
)
@@ -40,7 +42,8 @@
kind = source.ParseError
spn, err = scannerErrorRange(ctx, fset, pkg, e.Pos)
if err != nil {
- return nil, err
+ log.Error(ctx, "no span for scanner.Error pos", err, telemetry.Package.Of(pkg.ID()))
+ spn = span.Parse(e.Pos.String())
}
case scanner.ErrorList:
@@ -52,9 +55,9 @@
kind = source.ParseError
spn, err = scannerErrorRange(ctx, fset, pkg, e[0].Pos)
if err != nil {
- return nil, err
+ log.Error(ctx, "no span for scanner.Error pos", err, telemetry.Package.Of(pkg.ID()))
+ spn = span.Parse(e[0].Pos.String())
}
-
case types.Error:
msg = e.Msg
kind = source.TypeError