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

internal/lsp: unlabel context, log errors when canceled

Updates golang/go#33678

Change-Id: I844d6599a3e0ae9594dda1abaebe938402b65822
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190601
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-16 17:29:19 -04:00
parent 324b35332a
commit 3aeeb25976
6 changed files with 8 additions and 8 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, errors.Errorf("check: %v", ctx.Err())
return nil, ctx.Err()
}
data := v.(*checkPackageData)
return data.pkg, data.err
@ -255,7 +255,7 @@ func (imp *importer) typeCheck(cph *checkPackageHandle, m *metadata) (*pkg, erro
for _, err := range parseErrors {
if err == context.Canceled {
return nil, err
return nil, errors.Errorf("parsing files for %s: %v", m.pkgPath, err)
}
if err != nil {
imp.view.session.cache.appendPkgError(pkg, 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, errors.Errorf("checkMetadata: %v", ctx.Err())
return nil, ctx.Err()
}
ctx, done := trace.StartSpan(ctx, "packages.Load", telemetry.File.Of(f.filename()))
@ -171,6 +171,7 @@ func (v *view) shouldRunGopackages(ctx context.Context, f *goFile) (result bool)
// Get file content in case we don't already have it.
parsed, err := v.session.cache.ParseGoHandle(f.Handle(ctx), source.ParseHeader).Parse(ctx)
if err == context.Canceled {
log.Error(ctx, "parsing file header", err, tag.Of("file", f.URI()))
return false
}
if parsed == nil {

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, errors.Errorf("Parse: %v", ctx.Err())
return nil, ctx.Err()
}
data := v.(*parseGoData)
return data.ast, data.err

View File

@ -14,7 +14,6 @@ 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.
@ -72,7 +71,7 @@ func (pkg *pkg) GetActionGraph(ctx context.Context, a *analysis.Analyzer) (*sour
return pkg.GetActionGraph(ctx, a)
}
case <-ctx.Done():
return nil, errors.Errorf("GetActionGraph: %v", ctx.Err())
return nil, 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, errors.Errorf("Token: %v", ctx.Err())
return nil, ctx.Err()
}
data := v.(*tokenData)
return data.tok, data.err

View File

@ -28,7 +28,7 @@ func analyze(ctx context.Context, v View, cphs []CheckPackageHandle, analyzers [
defer done()
if ctx.Err() != nil {
return nil, errors.Errorf("analyze: %v", ctx.Err())
return nil, ctx.Err()
}
// Build nodes for initial packages.