internal/lsp: check for context cancellation before showing messages
Noticed this as part of investigating golang/go#40567.
Change-Id: I977b1b0a6ceb139e35e087c16b6ab88d66af69a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248400
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go
index 3c16f08..5fe9e06 100644
--- a/internal/lsp/diagnostics.go
+++ b/internal/lsp/diagnostics.go
@@ -19,7 +19,7 @@
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/span"
"golang.org/x/tools/internal/xcontext"
- "golang.org/x/xerrors"
+ errors "golang.org/x/xerrors"
)
// idWithAnalysis is used to track if the diagnostics for a given file were
@@ -93,6 +93,9 @@
// Diagnose all of the packages in the workspace.
wsPkgs, err := snapshot.WorkspacePackages(ctx)
if err != nil {
+ if errors.Is(err, context.Canceled) {
+ return nil, nil
+ }
// Try constructing a more helpful error message out of this error.
if s.handleFatalErrors(ctx, snapshot, modErr, err) {
return nil, nil
@@ -355,7 +358,7 @@
if modErr == nil {
return false
}
- if xerrors.Is(loadErr, source.PackagesLoadError) {
+ if errors.Is(loadErr, source.PackagesLoadError) {
fh, err := snapshot.GetFile(ctx, modURI)
if err != nil {
return false