From 0a73ddcff9b871d42548539fe3ec3ebd25fa4e69 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 13 Aug 2020 18:30:45 -0400 Subject: [PATCH] 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 Reviewed-by: Heschi Kreinick TryBot-Result: Gobot Gobot --- internal/lsp/diagnostics.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index 3c16f08d62..5fe9e0694c 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -19,7 +19,7 @@ import ( "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 @@ func (s *Server) diagnose(ctx context.Context, snapshot source.Snapshot, alwaysA // 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 @@ See https://github.com/golang/go/issues/39164 for more detail on this issue.`, 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