From d6d1b0d85358d89bbcc8ec54529aaa4ce6984462 Mon Sep 17 00:00:00 2001 From: Rohan Challa Date: Fri, 31 Jan 2020 13:15:27 -0500 Subject: [PATCH] internal/lsp/cache: add context cancellation check inside importerFunc This change adds a check inside of the types.ImporterFunc to see if the context has been cancelled. Updates golang/go#34683 Change-Id: I0f12da0f8158ecda0eec00150ed6ff772c2f89c3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/217257 Run-TryBot: Rohan Challa Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cache/check.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index b578bae2a0..35edec1fb7 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -309,6 +309,10 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc rawErrors = append(rawErrors, e) }, Importer: importerFunc(func(pkgPath string) (*types.Package, error) { + // If the context was cancelled, we should abort. + if ctx.Err() != nil { + return nil, ctx.Err() + } dep := deps[packagePath(pkgPath)] if dep == nil { // We may be in GOPATH mode, in which case we need to check vendor dirs.