diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 48b89f82c4..4c3b7d8650 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -39,8 +39,14 @@ func (s *snapshot) load(ctx context.Context, uri span.URI) ([]*metadata, error) cfg := s.view.Config(ctx) pkgs, err := packages.Load(cfg, fmt.Sprintf("file=%s", uri.Filename())) - log.Print(ctx, "go/packages.Load", tag.Of("packages", len(pkgs))) + // If the context was canceled, return early. + // Otherwise, we might be type-checking an incomplete result. + if err == context.Canceled { + return nil, errors.Errorf("no metadata for %s: %v", uri.Filename(), err) + } + + log.Print(ctx, "go/packages.Load", tag.Of("packages", len(pkgs))) if len(pkgs) == 0 { if err == nil { err = errors.Errorf("go/packages.Load: no packages found for %s", uri)