1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00

internal/lsp: label context cancellation errors

This change will just make it a bit easier to debug the context
cancellation errors.

Change-Id: I580751ac04e3357031678eb31914828029c96e4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190412
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-08-15 16:03:47 -04:00
parent 922a4ee32d
commit 3100af0b0e
6 changed files with 8 additions and 10 deletions

View File

@ -128,7 +128,7 @@ func (cph *checkPackageHandle) Check(ctx context.Context) (source.Package, error
func (cph *checkPackageHandle) check(ctx context.Context) (*pkg, error) {
v := cph.handle.Get(ctx)
if v == nil {
return nil, ctx.Err()
return nil, errors.Errorf("check: %v", ctx.Err())
}
data := v.(*checkPackageData)
return data.pkg, data.err

View File

@ -80,7 +80,7 @@ func (v *view) checkMetadata(ctx context.Context, f *goFile) (map[packageID]*met
// Check if the context has been canceled before calling packages.Load.
if ctx.Err() != nil {
return nil, ctx.Err()
return nil, errors.Errorf("checkMetadata: %v", ctx.Err())
}
ctx, done := trace.StartSpan(ctx, "packages.Load", telemetry.File.Of(f.filename()))

View File

@ -70,7 +70,7 @@ func (h *parseGoHandle) Mode() source.ParseMode {
func (h *parseGoHandle) Parse(ctx context.Context) (*ast.File, error) {
v := h.handle.Get(ctx)
if v == nil {
return nil, ctx.Err()
return nil, errors.Errorf("Parse: %v", ctx.Err())
}
data := v.(*parseGoData)
return data.ast, data.err

View File

@ -14,6 +14,7 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/lsp/source"
errors "golang.org/x/xerrors"
)
// pkg contains the type information needed by the source package.
@ -55,10 +56,6 @@ type analysisEntry struct {
}
func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*source.Action, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
pkg.mu.Lock()
e, ok := pkg.analyses[a]
if ok {
@ -75,7 +72,7 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
return pkg.GetActionGraph(ctx, a)
}
case <-ctx.Done():
return nil, ctx.Err()
return nil, errors.Errorf("GetActionGraph: %v", ctx.Err())
}
} else {
// cache miss

View File

@ -51,7 +51,7 @@ func (h *tokenHandle) File() source.FileHandle {
func (h *tokenHandle) Token(ctx context.Context) (*token.File, error) {
v := h.handle.Get(ctx)
if v == nil {
return nil, ctx.Err()
return nil, errors.Errorf("Token: %v", ctx.Err())
}
data := v.(*tokenData)
return data.tok, data.err

View File

@ -26,8 +26,9 @@ import (
func analyze(ctx context.Context, v View, cphs []CheckPackageHandle, analyzers []*analysis.Analyzer) ([]*Action, error) {
ctx, done := trace.StartSpan(ctx, "source.analyze")
defer done()
if ctx.Err() != nil {
return nil, ctx.Err()
return nil, errors.Errorf("analyze: %v", ctx.Err())
}
// Build nodes for initial packages.