mirror of
https://github.com/golang/go
synced 2024-11-18 18:14:43 -07:00
internal/lsp: rename Files to CompiledGoFiles
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>
This commit is contained in:
parent
328c41bf04
commit
8fd459516a
2
internal/lsp/cache/builtin.go
vendored
2
internal/lsp/cache/builtin.go
vendored
@ -21,7 +21,7 @@ func (b *builtinPkg) Lookup(name string) *ast.Object {
|
||||
return b.pkg.Scope.Lookup(name)
|
||||
}
|
||||
|
||||
func (b *builtinPkg) Files() []source.ParseGoHandle {
|
||||
func (b *builtinPkg) CompiledGoFiles() []source.ParseGoHandle {
|
||||
return b.files
|
||||
}
|
||||
|
||||
|
44
internal/lsp/cache/check.go
vendored
44
internal/lsp/cache/check.go
vendored
@ -27,8 +27,8 @@ import (
|
||||
type checkPackageHandle struct {
|
||||
handle *memoize.Handle
|
||||
|
||||
// files are the ParseGoHandles that compose the package.
|
||||
files []source.ParseGoHandle
|
||||
// compiledGoFiles are the ParseGoHandles that compose the package.
|
||||
compiledGoFiles []source.ParseGoHandle
|
||||
|
||||
// mode is the mode the the files were parsed in.
|
||||
mode source.ParseMode
|
||||
@ -77,7 +77,7 @@ func (s *snapshot) checkPackageHandle(ctx context.Context, id packageID, mode so
|
||||
//
|
||||
|
||||
m := cph.m
|
||||
files := cph.files
|
||||
files := cph.compiledGoFiles
|
||||
key := cph.key
|
||||
fset := s.view.session.cache.fset
|
||||
|
||||
@ -106,14 +106,14 @@ func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.Parse
|
||||
if m == nil {
|
||||
return nil, nil, errors.Errorf("no metadata for %s", id)
|
||||
}
|
||||
phs, err := s.parseGoHandles(ctx, m, mode)
|
||||
phs, err := s.compiledParseGoHandles(ctx, m, mode)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
cph := &checkPackageHandle{
|
||||
m: m,
|
||||
files: phs,
|
||||
mode: mode,
|
||||
m: m,
|
||||
compiledGoFiles: phs,
|
||||
mode: mode,
|
||||
}
|
||||
|
||||
// Make sure all of the depList are sorted.
|
||||
@ -139,7 +139,7 @@ func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.Parse
|
||||
deps[depHandle.m.pkgPath] = depHandle
|
||||
depKeys = append(depKeys, depHandle.key)
|
||||
}
|
||||
cph.key = checkPackageKey(cph.m.id, cph.files, m.config, depKeys)
|
||||
cph.key = checkPackageKey(cph.m.id, cph.compiledGoFiles, m.config, depKeys)
|
||||
return cph, deps, nil
|
||||
}
|
||||
|
||||
@ -177,8 +177,8 @@ func (cph *checkPackageHandle) check(ctx context.Context) (*pkg, error) {
|
||||
return data.pkg, data.err
|
||||
}
|
||||
|
||||
func (cph *checkPackageHandle) Files() []source.ParseGoHandle {
|
||||
return cph.files
|
||||
func (cph *checkPackageHandle) CompiledGoFiles() []source.ParseGoHandle {
|
||||
return cph.compiledGoFiles
|
||||
}
|
||||
|
||||
func (cph *checkPackageHandle) ID() string {
|
||||
@ -206,9 +206,9 @@ func (cph *checkPackageHandle) cached() (*pkg, error) {
|
||||
return data.pkg, data.err
|
||||
}
|
||||
|
||||
func (s *snapshot) parseGoHandles(ctx context.Context, m *metadata, mode source.ParseMode) ([]source.ParseGoHandle, error) {
|
||||
phs := make([]source.ParseGoHandle, 0, len(m.files))
|
||||
for _, uri := range m.files {
|
||||
func (s *snapshot) compiledParseGoHandles(ctx context.Context, m *metadata, mode source.ParseMode) ([]source.ParseGoHandle, error) {
|
||||
phs := make([]source.ParseGoHandle, 0, len(m.compiledGoFiles))
|
||||
for _, uri := range m.compiledGoFiles {
|
||||
f, err := s.view.GetFile(ctx, uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -229,12 +229,12 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
|
||||
}
|
||||
|
||||
pkg := &pkg{
|
||||
id: m.id,
|
||||
pkgPath: m.pkgPath,
|
||||
mode: mode,
|
||||
files: phs,
|
||||
imports: make(map[packagePath]*pkg),
|
||||
typesSizes: m.typesSizes,
|
||||
id: m.id,
|
||||
pkgPath: m.pkgPath,
|
||||
mode: mode,
|
||||
compiledGoFiles: phs,
|
||||
imports: make(map[packagePath]*pkg),
|
||||
typesSizes: m.typesSizes,
|
||||
typesInfo: &types.Info{
|
||||
Types: make(map[ast.Expr]types.TypeAndValue),
|
||||
Defs: make(map[*ast.Ident]types.Object),
|
||||
@ -245,11 +245,11 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
|
||||
},
|
||||
}
|
||||
var (
|
||||
files = make([]*ast.File, len(pkg.files))
|
||||
parseErrors = make([]error, len(pkg.files))
|
||||
files = make([]*ast.File, len(pkg.compiledGoFiles))
|
||||
parseErrors = make([]error, len(pkg.compiledGoFiles))
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
for i, ph := range pkg.files {
|
||||
for i, ph := range pkg.compiledGoFiles {
|
||||
wg.Add(1)
|
||||
go func(i int, ph source.ParseGoHandle) {
|
||||
defer wg.Done()
|
||||
|
4
internal/lsp/cache/gofile.go
vendored
4
internal/lsp/cache/gofile.go
vendored
@ -117,7 +117,7 @@ func (v *view) GetActiveReverseDeps(ctx context.Context, f source.File) (results
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, ph := range cph.Files() {
|
||||
for _, ph := range cph.CompiledGoFiles() {
|
||||
seen[ph.File().Identity().URI] = struct{}{}
|
||||
}
|
||||
results = append(results, cph)
|
||||
@ -135,7 +135,7 @@ func transitiveReverseDependencies(ctx context.Context, uri span.URI, s *snapsho
|
||||
metadata := s.getMetadataForURI(uri)
|
||||
|
||||
for _, m := range metadata {
|
||||
for _, uri := range m.files {
|
||||
for _, uri := range m.compiledGoFiles {
|
||||
topLevelURIs[uri] = struct{}{}
|
||||
}
|
||||
s.reverseDependencies(m.id, uris, seen)
|
||||
|
18
internal/lsp/cache/load.go
vendored
18
internal/lsp/cache/load.go
vendored
@ -20,14 +20,14 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
id packageID
|
||||
pkgPath packagePath
|
||||
name string
|
||||
files []span.URI
|
||||
typesSizes types.Sizes
|
||||
errors []packages.Error
|
||||
deps []packageID
|
||||
missingDeps map[packagePath]struct{}
|
||||
id packageID
|
||||
pkgPath packagePath
|
||||
name string
|
||||
compiledGoFiles []span.URI
|
||||
typesSizes types.Sizes
|
||||
errors []packages.Error
|
||||
deps []packageID
|
||||
missingDeps map[packagePath]struct{}
|
||||
|
||||
// config is the *packages.Config associated with the loaded package.
|
||||
config *packages.Config
|
||||
@ -213,7 +213,7 @@ func (s *snapshot) updateImports(ctx context.Context, pkgPath packagePath, pkg *
|
||||
seen[id] = struct{}{}
|
||||
for _, filename := range pkg.CompiledGoFiles {
|
||||
uri := span.FileURI(filename)
|
||||
m.files = append(m.files, uri)
|
||||
m.compiledGoFiles = append(m.compiledGoFiles, uri)
|
||||
|
||||
s.addID(uri, m.id)
|
||||
}
|
||||
|
20
internal/lsp/cache/pkg.go
vendored
20
internal/lsp/cache/pkg.go
vendored
@ -22,12 +22,12 @@ type pkg struct {
|
||||
pkgPath packagePath
|
||||
mode source.ParseMode
|
||||
|
||||
files []source.ParseGoHandle
|
||||
errors []*source.Error
|
||||
imports map[packagePath]*pkg
|
||||
types *types.Package
|
||||
typesInfo *types.Info
|
||||
typesSizes types.Sizes
|
||||
compiledGoFiles []source.ParseGoHandle
|
||||
errors []*source.Error
|
||||
imports map[packagePath]*pkg
|
||||
types *types.Package
|
||||
typesInfo *types.Info
|
||||
typesSizes types.Sizes
|
||||
}
|
||||
|
||||
// Declare explicit types for package paths and IDs to ensure that we never use
|
||||
@ -44,12 +44,12 @@ func (p *pkg) PkgPath() string {
|
||||
return string(p.pkgPath)
|
||||
}
|
||||
|
||||
func (p *pkg) Files() []source.ParseGoHandle {
|
||||
return p.files
|
||||
func (p *pkg) CompiledGoFiles() []source.ParseGoHandle {
|
||||
return p.compiledGoFiles
|
||||
}
|
||||
|
||||
func (p *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
|
||||
for _, ph := range p.Files() {
|
||||
for _, ph := range p.CompiledGoFiles() {
|
||||
if ph.File().Identity().URI == uri {
|
||||
return ph, nil
|
||||
}
|
||||
@ -59,7 +59,7 @@ func (p *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
|
||||
|
||||
func (p *pkg) GetSyntax() []*ast.File {
|
||||
var syntax []*ast.File
|
||||
for _, ph := range p.files {
|
||||
for _, ph := range p.compiledGoFiles {
|
||||
file, _, _, err := ph.Cached()
|
||||
if err == nil {
|
||||
syntax = append(syntax, file)
|
||||
|
4
internal/lsp/cache/snapshot.go
vendored
4
internal/lsp/cache/snapshot.go
vendored
@ -175,7 +175,7 @@ func (s *snapshot) KnownImportPaths() map[string]source.Package {
|
||||
for importPath, newPkg := range cachedPkg.imports {
|
||||
if oldPkg, ok := results[string(importPath)]; ok {
|
||||
// Using the same trick as NarrowestPackageHandle, prefer non-variants.
|
||||
if len(newPkg.files) < len(oldPkg.(*pkg).files) {
|
||||
if len(newPkg.compiledGoFiles) < len(oldPkg.(*pkg).compiledGoFiles) {
|
||||
results[string(importPath)] = newPkg
|
||||
}
|
||||
} else {
|
||||
@ -491,7 +491,7 @@ func (s *snapshot) reverseDependencies(id packageID, uris map[span.URI]struct{},
|
||||
for _, parentID := range importedBy {
|
||||
s.reverseDependencies(parentID, uris, seen)
|
||||
}
|
||||
for _, uri := range m.files {
|
||||
for _, uri := range m.compiledGoFiles {
|
||||
uris[uri] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
4
internal/lsp/cache/view.go
vendored
4
internal/lsp/cache/view.go
vendored
@ -478,7 +478,7 @@ func (v *view) FindPosInPackage(searchpkg source.Package, pos token.Pos) (*ast.F
|
||||
|
||||
func (v *view) findIgnoredFile(uri span.URI) (source.ParseGoHandle, source.Package, error) {
|
||||
// Check the builtin package.
|
||||
for _, h := range v.BuiltinPackage().Files() {
|
||||
for _, h := range v.BuiltinPackage().CompiledGoFiles() {
|
||||
if h.File().Identity().URI == uri {
|
||||
return h, nil, nil
|
||||
}
|
||||
@ -495,7 +495,7 @@ func findFileInPackage(pkg source.Package, uri span.URI) (source.ParseGoHandle,
|
||||
queue = queue[1:]
|
||||
seen[pkg.ID()] = true
|
||||
|
||||
for _, ph := range pkg.Files() {
|
||||
for _, ph := range pkg.CompiledGoFiles() {
|
||||
if ph.File().Identity().URI == uri {
|
||||
return ph, pkg, nil
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
|
||||
func (s *Server) diagnoseView(view source.View, cphs []source.CheckPackageHandle) {
|
||||
for _, cph := range cphs {
|
||||
if len(cph.Files()) == 0 {
|
||||
if len(cph.CompiledGoFiles()) == 0 {
|
||||
continue
|
||||
}
|
||||
f := cph.Files()[0]
|
||||
f := cph.CompiledGoFiles()[0]
|
||||
|
||||
// Run diagnostics on the workspace package.
|
||||
go func(view source.View, uri span.URI) {
|
||||
|
@ -184,7 +184,7 @@ func (c *completer) importEdits(imp *importInfo) ([]protocol.TextEdit, error) {
|
||||
|
||||
uri := span.FileURI(c.filename)
|
||||
var ph ParseGoHandle
|
||||
for _, h := range c.pkg.Files() {
|
||||
for _, h := range c.pkg.CompiledGoFiles() {
|
||||
if h.File().Identity().URI == uri {
|
||||
ph = h
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func Diagnostics(ctx context.Context, view View, f File, disabledAnalyses map[st
|
||||
|
||||
// Prepare the reports we will send for the files in this package.
|
||||
reports := make(map[span.URI][]Diagnostic)
|
||||
for _, fh := range pkg.Files() {
|
||||
for _, fh := range pkg.CompiledGoFiles() {
|
||||
clearReports(view, reports, fh.File().Identity().URI)
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func Diagnostics(ctx context.Context, view View, f File, disabledAnalyses map[st
|
||||
if err != nil {
|
||||
return nil, warningMsg, err
|
||||
}
|
||||
for _, fh := range pkg.Files() {
|
||||
for _, fh := range pkg.CompiledGoFiles() {
|
||||
clearReports(view, reports, fh.File().Identity().URI)
|
||||
}
|
||||
diagnostics(ctx, view, pkg, reports)
|
||||
|
@ -117,7 +117,7 @@ func AllImportsFixes(ctx context.Context, view View, f File) (allFixEdits []prot
|
||||
return nil, nil, errors.Errorf("%s has list errors, not running goimports", f.URI())
|
||||
}
|
||||
var ph ParseGoHandle
|
||||
for _, h := range pkg.Files() {
|
||||
for _, h := range pkg.CompiledGoFiles() {
|
||||
if h.File().Identity().URI == f.URI() {
|
||||
ph = h
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func Highlight(ctx context.Context, view View, uri span.URI, pos protocol.Positi
|
||||
return nil, err
|
||||
}
|
||||
var ph ParseGoHandle
|
||||
for _, file := range pkg.Files() {
|
||||
for _, file := range pkg.CompiledGoFiles() {
|
||||
if file.File().Identity().URI == f.URI() {
|
||||
ph = file
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func identifier(ctx context.Context, snapshot Snapshot, pkg Package, file *ast.F
|
||||
view := snapshot.View()
|
||||
uri := span.FileURI(view.Session().Cache().FileSet().Position(pos).Filename)
|
||||
var ph ParseGoHandle
|
||||
for _, h := range pkg.Files() {
|
||||
for _, h := range pkg.CompiledGoFiles() {
|
||||
if h.File().Identity().URI == uri {
|
||||
ph = h
|
||||
}
|
||||
@ -285,7 +285,7 @@ func importSpec(ctx context.Context, snapshot Snapshot, pkg Package, file *ast.F
|
||||
}
|
||||
uri := span.FileURI(snapshot.View().Session().Cache().FileSet().Position(pos).Filename)
|
||||
var ph ParseGoHandle
|
||||
for _, h := range pkg.Files() {
|
||||
for _, h := range pkg.CompiledGoFiles() {
|
||||
if h.File().Identity().URI == uri {
|
||||
ph = h
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func (i *IdentifierInfo) Implementation(ctx context.Context) ([]protocol.Locatio
|
||||
|
||||
for _, obj := range objs {
|
||||
pkg := pkgs[obj]
|
||||
if pkgs[obj] == nil || len(pkg.Files()) == 0 {
|
||||
if pkgs[obj] == nil || len(pkg.CompiledGoFiles()) == 0 {
|
||||
continue
|
||||
}
|
||||
file, _, _, err := i.Snapshot.View().FindPosInPackage(pkgs[obj], obj.Pos())
|
||||
|
@ -62,7 +62,7 @@ func NarrowestCheckPackageHandle(handles []CheckPackageHandle) (CheckPackageHand
|
||||
}
|
||||
result := handles[0]
|
||||
for _, handle := range handles[1:] {
|
||||
if result == nil || len(handle.Files()) < len(result.Files()) {
|
||||
if result == nil || len(handle.CompiledGoFiles()) < len(result.CompiledGoFiles()) {
|
||||
result = handle
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ func WidestCheckPackageHandle(handles []CheckPackageHandle) (CheckPackageHandle,
|
||||
}
|
||||
result := handles[0]
|
||||
for _, handle := range handles[1:] {
|
||||
if result == nil || len(handle.Files()) > len(result.Files()) {
|
||||
if result == nil || len(handle.CompiledGoFiles()) > len(result.CompiledGoFiles()) {
|
||||
result = handle
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ type CheckPackageHandle interface {
|
||||
ID() string
|
||||
|
||||
// ParseGoHandle returns a ParseGoHandle for which to get the package.
|
||||
Files() []ParseGoHandle
|
||||
CompiledGoFiles() []ParseGoHandle
|
||||
|
||||
// Check returns the type-checked Package for the CheckPackageHandle.
|
||||
Check(ctx context.Context) (Package, error)
|
||||
@ -333,7 +333,7 @@ type Scope interface {
|
||||
type Package interface {
|
||||
ID() string
|
||||
PkgPath() string
|
||||
Files() []ParseGoHandle
|
||||
CompiledGoFiles() []ParseGoHandle
|
||||
File(uri span.URI) (ParseGoHandle, error)
|
||||
GetSyntax() []*ast.File
|
||||
GetErrors() []*Error
|
||||
@ -371,5 +371,5 @@ func (e *Error) Error() string {
|
||||
|
||||
type BuiltinPackage interface {
|
||||
Lookup(name string) *ast.Object
|
||||
Files() []ParseGoHandle
|
||||
CompiledGoFiles() []ParseGoHandle
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ func (s *Server) didClose(ctx context.Context, params *protocol.DidCloseTextDocu
|
||||
return nil
|
||||
}
|
||||
for _, cph := range cphs {
|
||||
for _, ph := range cph.Files() {
|
||||
for _, ph := range cph.CompiledGoFiles() {
|
||||
// If other files from this package are open, don't clear.
|
||||
if s.session.IsOpen(ph.File().Identity().URI) {
|
||||
clear = nil
|
||||
|
@ -55,7 +55,7 @@ func (s *Server) didChangeWatchedFiles(ctx context.Context, params *protocol.Did
|
||||
// Find a different file in the same package we can use to trigger diagnostics.
|
||||
// TODO(rstambler): Allow diagnostics to be called per-package to avoid this.
|
||||
var otherFile source.File
|
||||
for _, ph := range cph.Files() {
|
||||
for _, ph := range cph.CompiledGoFiles() {
|
||||
if ph.File().Identity().URI == f.URI() {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user