diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 24136170c6..2298fab4b0 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -184,7 +184,7 @@ func (ph *packageHandle) Check(ctx context.Context) (source.Package, error) { func (ph *packageHandle) check(ctx context.Context) (*pkg, error) { v := ph.handle.Get(ctx) if v == nil { - return nil, errors.Errorf("no package for %s", ph.m.id) + return nil, ctx.Err() } data := v.(*packageData) return data.pkg, data.err diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 8825e63007..b9cd3007d2 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -26,6 +26,7 @@ import ( "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/telemetry/log" "golang.org/x/tools/internal/telemetry/tag" + "golang.org/x/tools/internal/xcontext" errors "golang.org/x/xerrors" ) @@ -349,6 +350,9 @@ func (v *view) getSnapshot() *snapshot { // including any position and type information that depends on it. // It returns true if we were already tracking the given file, false otherwise. func (v *view) invalidateContent(ctx context.Context, uri span.URI, kind source.FileKind, action source.FileAction) source.Snapshot { + // Detach the context so that content invalidation cannot be canceled. + ctx = xcontext.Detach(ctx) + // Cancel all still-running previous requests, since they would be // operating on stale data. switch action {