mirror of
https://github.com/golang/go
synced 2024-11-19 04:34:39 -07:00
8fd459516a
As we improve support for cgo we'll need to reference GoFiles, not just CompiledGoFiles. "Files" is right out. I think I got everything that needs renaming but please let me know if not. Updates golang/go#35720. Change-Id: I97a6ebf5b395535de0d5f4f8b3f84b46ca34643f Reviewed-on: https://go-review.googlesource.com/c/tools/+/208101 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"go/ast"
|
|
|
|
"golang.org/x/tools/go/packages"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
type builtinPkg struct {
|
|
pkg *ast.Package
|
|
files []source.ParseGoHandle
|
|
}
|
|
|
|
func (b *builtinPkg) Lookup(name string) *ast.Object {
|
|
if b == nil || b.pkg == nil || b.pkg.Scope == nil {
|
|
return nil
|
|
}
|
|
return b.pkg.Scope.Lookup(name)
|
|
}
|
|
|
|
func (b *builtinPkg) CompiledGoFiles() []source.ParseGoHandle {
|
|
return b.files
|
|
}
|
|
|
|
// buildBuiltinPkg builds the view's builtin package.
|
|
// It assumes that the view is not active yet,
|
|
// i.e. it has not been added to the session's list of views.
|
|
func (v *view) buildBuiltinPackage(ctx context.Context) error {
|
|
cfg := v.Config(ctx)
|
|
pkgs, err := packages.Load(cfg, "builtin")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(pkgs) != 1 {
|
|
return err
|
|
}
|
|
pkg := pkgs[0]
|
|
files := make(map[string]*ast.File)
|
|
for _, filename := range pkg.GoFiles {
|
|
fh := v.session.GetFile(span.FileURI(filename), source.Go)
|
|
ph := v.session.cache.ParseGoHandle(fh, source.ParseFull)
|
|
v.builtin.files = append(v.builtin.files, ph)
|
|
file, _, _, err := ph.Parse(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
files[filename] = file
|
|
|
|
v.ignoredURIsMu.Lock()
|
|
v.ignoredURIs[span.NewURI(filename)] = struct{}{}
|
|
v.ignoredURIsMu.Unlock()
|
|
}
|
|
v.builtin.pkg, err = ast.NewPackage(cfg.Fset, files, nil, nil)
|
|
return err
|
|
}
|