mirror of https://github.com/golang/go.git
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:
parent
041a08a54a
commit
145a1e401f
|
|
@ -184,7 +184,7 @@ func (ph *packageHandle) Check(ctx context.Context) (source.Package, error) {
|
||||||
func (ph *packageHandle) check(ctx context.Context) (*pkg, error) {
|
func (ph *packageHandle) check(ctx context.Context) (*pkg, error) {
|
||||||
v := ph.handle.Get(ctx)
|
v := ph.handle.Get(ctx)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return nil, errors.Errorf("no package for %s", ph.m.id)
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
data := v.(*packageData)
|
data := v.(*packageData)
|
||||||
return data.pkg, data.err
|
return data.pkg, data.err
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"golang.org/x/tools/internal/span"
|
"golang.org/x/tools/internal/span"
|
||||||
"golang.org/x/tools/internal/telemetry/log"
|
"golang.org/x/tools/internal/telemetry/log"
|
||||||
"golang.org/x/tools/internal/telemetry/tag"
|
"golang.org/x/tools/internal/telemetry/tag"
|
||||||
|
"golang.org/x/tools/internal/xcontext"
|
||||||
errors "golang.org/x/xerrors"
|
errors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -349,6 +350,9 @@ func (v *view) getSnapshot() *snapshot {
|
||||||
// including any position and type information that depends on it.
|
// including any position and type information that depends on it.
|
||||||
// It returns true if we were already tracking the given file, false otherwise.
|
// 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 {
|
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
|
// Cancel all still-running previous requests, since they would be
|
||||||
// operating on stale data.
|
// operating on stale data.
|
||||||
switch action {
|
switch action {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue