1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:54:45 -07:00

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>
This commit is contained in:
Rebecca Stambler 2020-08-13 18:30:45 -04:00
parent 1365742343
commit 0a73ddcff9

View File

@ -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