1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:44:49 -07:00

internal/lsp/cache: detach context before invalidation

In one of my previous refactoring changes, I lost the fact that the
context should be detached before invalidating a file's contents. If
this function is canceled, we will be in a bad state.

Also, small change to return ctx.Err() instead of a custom error message
from (*packageHandle).check.

Change-Id: I19e513e09e438feee105fdd89cb7364a0c3c5e7f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212104
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2019-12-19 15:47:07 -05:00
parent 041a08a54a
commit 145a1e401f
2 changed files with 5 additions and 1 deletions

View File

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

View File

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