Skip to content

Commit

Permalink
internal/lsp: check for context cancellation before showing messages
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stamblerre committed Aug 13, 2020
1 parent 1365742 commit 0a73ddc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/lsp/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0a73ddc

Please sign in to comment.