mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
internal/lsp/cache: have NewView create view even if load all packages fails
Even if the packages.Load of the directory the NewView is being created for fails, create and add the view. But also return the error from NewView, just after the new view has been added. Fixes golang/go#35468 Change-Id: I76c2d3cbe1a508ad0794a6fcd3bc67cd48c97e22 Reviewed-on: https://go-review.googlesource.com/c/tools/+/206497 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
8cb0d02132
commit
50fa39b762
4
internal/lsp/cache/load.go
vendored
4
internal/lsp/cache/load.go
vendored
@ -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)
|
||||
|
6
internal/lsp/cache/session.go
vendored
6
internal/lsp/cache/session.go
vendored
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user