diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 1675cfc4b5..52b04dab59 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -64,10 +64,12 @@ func (s *snapshot) load(ctx context.Context, scope source.Scope) ([]*metadata, e return nil, errors.Errorf("no metadata for %s: %v", uri, err) } log.Print(ctx, "go/packages.Load", tag.Of("packages", len(pkgs))) - if _, ok := scope.(source.FileURI); len(pkgs) == 0 && ok { + if len(pkgs) == 0 { if err == nil { err = errNoPackagesFound } + } + if err != nil { return nil, err } m, prevMissingImports, err := s.updateMetadata(ctx, scope, pkgs, cfg) diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 24e945be4d..573ebc8e54 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -6,6 +6,7 @@ package cache import ( "context" + "fmt" "path/filepath" "sort" "strconv" @@ -126,8 +127,9 @@ func (s *session) NewView(ctx context.Context, name string, folder span.URI, opt v.snapshotMu.Lock() defer v.snapshotMu.Unlock() // The code after the snapshot is used isn't expensive. m, err := v.snapshot.load(ctx, source.DirectoryURI(folder)) + var loadErr error if err != nil && err != errNoPackagesFound { - return nil, err + loadErr = fmt.Errorf("Error loading packages: %v", err) } // Prepare CheckPackageHandles for every package that's been loaded. @@ -144,7 +146,7 @@ func (s *session) NewView(ctx context.Context, name string, folder span.URI, opt // we always need to drop the view map s.viewMap = make(map[span.URI]source.View) debug.AddView(debugView{v}) - return v, nil + return v, loadErr } // View returns the view by name.