mirror of
https://github.com/golang/go
synced 2024-11-18 16:54:43 -07:00
go/packages: ignore no packages error from (*snapshot).load in (*session).NewView
Treat it as okay if no packages are found when loading all the packages in a workspace. Users may open workspaces that don't have any Go files, either because they are workspaces for other languages, or because no Go files have been created yet. Fixes golang/go#35455 Change-Id: I60912472ec8930649996edc150d1d19cd74a0a2e Reviewed-on: https://go-review.googlesource.com/c/tools/+/206140 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
b93886dd8b
commit
46f5a7f28b
7
internal/lsp/cache/load.go
vendored
7
internal/lsp/cache/load.go
vendored
@ -33,6 +33,8 @@ type metadata struct {
|
||||
config *packages.Config
|
||||
}
|
||||
|
||||
var errNoPackagesFound = errors.New("no packages found for query")
|
||||
|
||||
func (s *snapshot) load(ctx context.Context, scope source.Scope) ([]*metadata, error) {
|
||||
uri := scope.URI()
|
||||
var query string
|
||||
@ -62,11 +64,10 @@ 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 len(pkgs) == 0 {
|
||||
if _, ok := scope.(source.FileURI); len(pkgs) == 0 && ok {
|
||||
if err == nil {
|
||||
err = errors.Errorf("go/packages.Load: no packages found for %s", query)
|
||||
err = errNoPackagesFound
|
||||
}
|
||||
// Return this error as a diagnostic to the user.
|
||||
return nil, err
|
||||
}
|
||||
m, prevMissingImports, err := s.updateMetadata(ctx, scope, pkgs, cfg)
|
||||
|
3
internal/lsp/cache/session.go
vendored
3
internal/lsp/cache/session.go
vendored
@ -126,9 +126,10 @@ 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))
|
||||
if err != nil {
|
||||
if err != nil && err != errNoPackagesFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Prepare CheckPackageHandles for every package that's been loaded.
|
||||
// (*snapshot).CheckPackageHandle makes the assumption that every package that's
|
||||
// been loaded has an existing checkPackageHandle.
|
||||
|
Loading…
Reference in New Issue
Block a user