Skip to content

Commit 8fd4595

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 328c41b commit 8fd4595

18 files changed

+65
-65
lines changed

internal/lsp/cache/builtin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (b *builtinPkg) Lookup(name string) *ast.Object {
2121
return b.pkg.Scope.Lookup(name)
2222
}
2323

24-
func (b *builtinPkg) Files() []source.ParseGoHandle {
24+
func (b *builtinPkg) CompiledGoFiles() []source.ParseGoHandle {
2525
return b.files
2626
}
2727

internal/lsp/cache/check.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
type checkPackageHandle struct {
2828
handle *memoize.Handle
2929

30-
// files are the ParseGoHandles that compose the package.
31-
files []source.ParseGoHandle
30+
// compiledGoFiles are the ParseGoHandles that compose the package.
31+
compiledGoFiles []source.ParseGoHandle
3232

3333
// mode is the mode the the files were parsed in.
3434
mode source.ParseMode
@@ -77,7 +77,7 @@ func (s *snapshot) checkPackageHandle(ctx context.Context, id packageID, mode so
7777
//
7878

7979
m := cph.m
80-
files := cph.files
80+
files := cph.compiledGoFiles
8181
key := cph.key
8282
fset := s.view.session.cache.fset
8383

@@ -106,14 +106,14 @@ func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.Parse
106106
if m == nil {
107107
return nil, nil, errors.Errorf("no metadata for %s", id)
108108
}
109-
phs, err := s.parseGoHandles(ctx, m, mode)
109+
phs, err := s.compiledParseGoHandles(ctx, m, mode)
110110
if err != nil {
111111
return nil, nil, err
112112
}
113113
cph := &checkPackageHandle{
114-
m: m,
115-
files: phs,
116-
mode: mode,
114+
m: m,
115+
compiledGoFiles: phs,
116+
mode: mode,
117117
}
118118

119119
// Make sure all of the depList are sorted.
@@ -139,7 +139,7 @@ func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.Parse
139139
deps[depHandle.m.pkgPath] = depHandle
140140
depKeys = append(depKeys, depHandle.key)
141141
}
142-
cph.key = checkPackageKey(cph.m.id, cph.files, m.config, depKeys)
142+
cph.key = checkPackageKey(cph.m.id, cph.compiledGoFiles, m.config, depKeys)
143143
return cph, deps, nil
144144
}
145145

@@ -177,8 +177,8 @@ func (cph *checkPackageHandle) check(ctx context.Context) (*pkg, error) {
177177
return data.pkg, data.err
178178
}
179179

180-
func (cph *checkPackageHandle) Files() []source.ParseGoHandle {
181-
return cph.files
180+
func (cph *checkPackageHandle) CompiledGoFiles() []source.ParseGoHandle {
181+
return cph.compiledGoFiles
182182
}
183183

184184
func (cph *checkPackageHandle) ID() string {
@@ -206,9 +206,9 @@ func (cph *checkPackageHandle) cached() (*pkg, error) {
206206
return data.pkg, data.err
207207
}
208208

209-
func (s *snapshot) parseGoHandles(ctx context.Context, m *metadata, mode source.ParseMode) ([]source.ParseGoHandle, error) {
210-
phs := make([]source.ParseGoHandle, 0, len(m.files))
211-
for _, uri := range m.files {
209+
func (s *snapshot) compiledParseGoHandles(ctx context.Context, m *metadata, mode source.ParseMode) ([]source.ParseGoHandle, error) {
210+
phs := make([]source.ParseGoHandle, 0, len(m.compiledGoFiles))
211+
for _, uri := range m.compiledGoFiles {
212212
f, err := s.view.GetFile(ctx, uri)
213213
if err != nil {
214214
return nil, err
@@ -229,12 +229,12 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
229229
}
230230

231231
pkg := &pkg{
232-
id: m.id,
233-
pkgPath: m.pkgPath,
234-
mode: mode,
235-
files: phs,
236-
imports: make(map[packagePath]*pkg),
237-
typesSizes: m.typesSizes,
232+
id: m.id,
233+
pkgPath: m.pkgPath,
234+
mode: mode,
235+
compiledGoFiles: phs,
236+
imports: make(map[packagePath]*pkg),
237+
typesSizes: m.typesSizes,
238238
typesInfo: &types.Info{
239239
Types: make(map[ast.Expr]types.TypeAndValue),
240240
Defs: make(map[*ast.Ident]types.Object),
@@ -245,11 +245,11 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
245245
},
246246
}
247247
var (
248-
files = make([]*ast.File, len(pkg.files))
249-
parseErrors = make([]error, len(pkg.files))
248+
files = make([]*ast.File, len(pkg.compiledGoFiles))
249+
parseErrors = make([]error, len(pkg.compiledGoFiles))
250250
wg sync.WaitGroup
251251
)
252-
for i, ph := range pkg.files {
252+
for i, ph := range pkg.compiledGoFiles {
253253
wg.Add(1)
254254
go func(i int, ph source.ParseGoHandle) {
255255
defer wg.Done()

internal/lsp/cache/gofile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (v *view) GetActiveReverseDeps(ctx context.Context, f source.File) (results
117117
if err != nil {
118118
continue
119119
}
120-
for _, ph := range cph.Files() {
120+
for _, ph := range cph.CompiledGoFiles() {
121121
seen[ph.File().Identity().URI] = struct{}{}
122122
}
123123
results = append(results, cph)
@@ -135,7 +135,7 @@ func transitiveReverseDependencies(ctx context.Context, uri span.URI, s *snapsho
135135
metadata := s.getMetadataForURI(uri)
136136

137137
for _, m := range metadata {
138-
for _, uri := range m.files {
138+
for _, uri := range m.compiledGoFiles {
139139
topLevelURIs[uri] = struct{}{}
140140
}
141141
s.reverseDependencies(m.id, uris, seen)

internal/lsp/cache/load.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020
)
2121

2222
type metadata struct {
23-
id packageID
24-
pkgPath packagePath
25-
name string
26-
files []span.URI
27-
typesSizes types.Sizes
28-
errors []packages.Error
29-
deps []packageID
30-
missingDeps map[packagePath]struct{}
23+
id packageID
24+
pkgPath packagePath
25+
name string
26+
compiledGoFiles []span.URI
27+
typesSizes types.Sizes
28+
errors []packages.Error
29+
deps []packageID
30+
missingDeps map[packagePath]struct{}
3131

3232
// config is the *packages.Config associated with the loaded package.
3333
config *packages.Config
@@ -213,7 +213,7 @@ func (s *snapshot) updateImports(ctx context.Context, pkgPath packagePath, pkg *
213213
seen[id] = struct{}{}
214214
for _, filename := range pkg.CompiledGoFiles {
215215
uri := span.FileURI(filename)
216-
m.files = append(m.files, uri)
216+
m.compiledGoFiles = append(m.compiledGoFiles, uri)
217217

218218
s.addID(uri, m.id)
219219
}

internal/lsp/cache/pkg.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ type pkg struct {
2222
pkgPath packagePath
2323
mode source.ParseMode
2424

25-
files []source.ParseGoHandle
26-
errors []*source.Error
27-
imports map[packagePath]*pkg
28-
types *types.Package
29-
typesInfo *types.Info
30-
typesSizes types.Sizes
25+
compiledGoFiles []source.ParseGoHandle
26+
errors []*source.Error
27+
imports map[packagePath]*pkg
28+
types *types.Package
29+
typesInfo *types.Info
30+
typesSizes types.Sizes
3131
}
3232

3333
// Declare explicit types for package paths and IDs to ensure that we never use
@@ -44,12 +44,12 @@ func (p *pkg) PkgPath() string {
4444
return string(p.pkgPath)
4545
}
4646

47-
func (p *pkg) Files() []source.ParseGoHandle {
48-
return p.files
47+
func (p *pkg) CompiledGoFiles() []source.ParseGoHandle {
48+
return p.compiledGoFiles
4949
}
5050

5151
func (p *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
52-
for _, ph := range p.Files() {
52+
for _, ph := range p.CompiledGoFiles() {
5353
if ph.File().Identity().URI == uri {
5454
return ph, nil
5555
}
@@ -59,7 +59,7 @@ func (p *pkg) File(uri span.URI) (source.ParseGoHandle, error) {
5959

6060
func (p *pkg) GetSyntax() []*ast.File {
6161
var syntax []*ast.File
62-
for _, ph := range p.files {
62+
for _, ph := range p.compiledGoFiles {
6363
file, _, _, err := ph.Cached()
6464
if err == nil {
6565
syntax = append(syntax, file)

internal/lsp/cache/snapshot.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (s *snapshot) KnownImportPaths() map[string]source.Package {
175175
for importPath, newPkg := range cachedPkg.imports {
176176
if oldPkg, ok := results[string(importPath)]; ok {
177177
// Using the same trick as NarrowestPackageHandle, prefer non-variants.
178-
if len(newPkg.files) < len(oldPkg.(*pkg).files) {
178+
if len(newPkg.compiledGoFiles) < len(oldPkg.(*pkg).compiledGoFiles) {
179179
results[string(importPath)] = newPkg
180180
}
181181
} else {
@@ -491,7 +491,7 @@ func (s *snapshot) reverseDependencies(id packageID, uris map[span.URI]struct{},
491491
for _, parentID := range importedBy {
492492
s.reverseDependencies(parentID, uris, seen)
493493
}
494-
for _, uri := range m.files {
494+
for _, uri := range m.compiledGoFiles {
495495
uris[uri] = struct{}{}
496496
}
497497
}

internal/lsp/cache/view.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (v *view) FindPosInPackage(searchpkg source.Package, pos token.Pos) (*ast.F
478478

479479
func (v *view) findIgnoredFile(uri span.URI) (source.ParseGoHandle, source.Package, error) {
480480
// Check the builtin package.
481-
for _, h := range v.BuiltinPackage().Files() {
481+
for _, h := range v.BuiltinPackage().CompiledGoFiles() {
482482
if h.File().Identity().URI == uri {
483483
return h, nil, nil
484484
}
@@ -495,7 +495,7 @@ func findFileInPackage(pkg source.Package, uri span.URI) (source.ParseGoHandle,
495495
queue = queue[1:]
496496
seen[pkg.ID()] = true
497497

498-
for _, ph := range pkg.Files() {
498+
for _, ph := range pkg.CompiledGoFiles() {
499499
if ph.File().Identity().URI == uri {
500500
return ph, pkg, nil
501501
}

internal/lsp/diagnostics.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818

1919
func (s *Server) diagnoseView(view source.View, cphs []source.CheckPackageHandle) {
2020
for _, cph := range cphs {
21-
if len(cph.Files()) == 0 {
21+
if len(cph.CompiledGoFiles()) == 0 {
2222
continue
2323
}
24-
f := cph.Files()[0]
24+
f := cph.CompiledGoFiles()[0]
2525

2626
// Run diagnostics on the workspace package.
2727
go func(view source.View, uri span.URI) {

internal/lsp/source/completion_format.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (c *completer) importEdits(imp *importInfo) ([]protocol.TextEdit, error) {
184184

185185
uri := span.FileURI(c.filename)
186186
var ph ParseGoHandle
187-
for _, h := range c.pkg.Files() {
187+
for _, h := range c.pkg.CompiledGoFiles() {
188188
if h.File().Identity().URI == uri {
189189
ph = h
190190
}

internal/lsp/source/diagnostics.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func Diagnostics(ctx context.Context, view View, f File, disabledAnalyses map[st
6969

7070
// Prepare the reports we will send for the files in this package.
7171
reports := make(map[span.URI][]Diagnostic)
72-
for _, fh := range pkg.Files() {
72+
for _, fh := range pkg.CompiledGoFiles() {
7373
clearReports(view, reports, fh.File().Identity().URI)
7474
}
7575

@@ -95,7 +95,7 @@ func Diagnostics(ctx context.Context, view View, f File, disabledAnalyses map[st
9595
if err != nil {
9696
return nil, warningMsg, err
9797
}
98-
for _, fh := range pkg.Files() {
98+
for _, fh := range pkg.CompiledGoFiles() {
9999
clearReports(view, reports, fh.File().Identity().URI)
100100
}
101101
diagnostics(ctx, view, pkg, reports)

internal/lsp/source/format.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func AllImportsFixes(ctx context.Context, view View, f File) (allFixEdits []prot
117117
return nil, nil, errors.Errorf("%s has list errors, not running goimports", f.URI())
118118
}
119119
var ph ParseGoHandle
120-
for _, h := range pkg.Files() {
120+
for _, h := range pkg.CompiledGoFiles() {
121121
if h.File().Identity().URI == f.URI() {
122122
ph = h
123123
}

internal/lsp/source/highlight.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Highlight(ctx context.Context, view View, uri span.URI, pos protocol.Positi
3636
return nil, err
3737
}
3838
var ph ParseGoHandle
39-
for _, file := range pkg.Files() {
39+
for _, file := range pkg.CompiledGoFiles() {
4040
if file.File().Identity().URI == f.URI() {
4141
ph = file
4242
}

internal/lsp/source/identifier.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func identifier(ctx context.Context, snapshot Snapshot, pkg Package, file *ast.F
110110
view := snapshot.View()
111111
uri := span.FileURI(view.Session().Cache().FileSet().Position(pos).Filename)
112112
var ph ParseGoHandle
113-
for _, h := range pkg.Files() {
113+
for _, h := range pkg.CompiledGoFiles() {
114114
if h.File().Identity().URI == uri {
115115
ph = h
116116
}
@@ -285,7 +285,7 @@ func importSpec(ctx context.Context, snapshot Snapshot, pkg Package, file *ast.F
285285
}
286286
uri := span.FileURI(snapshot.View().Session().Cache().FileSet().Position(pos).Filename)
287287
var ph ParseGoHandle
288-
for _, h := range pkg.Files() {
288+
for _, h := range pkg.CompiledGoFiles() {
289289
if h.File().Identity().URI == uri {
290290
ph = h
291291
}

internal/lsp/source/implementation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (i *IdentifierInfo) Implementation(ctx context.Context) ([]protocol.Locatio
6262

6363
for _, obj := range objs {
6464
pkg := pkgs[obj]
65-
if pkgs[obj] == nil || len(pkg.Files()) == 0 {
65+
if pkgs[obj] == nil || len(pkg.CompiledGoFiles()) == 0 {
6666
continue
6767
}
6868
file, _, _, err := i.Snapshot.View().FindPosInPackage(pkgs[obj], obj.Pos())

internal/lsp/source/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NarrowestCheckPackageHandle(handles []CheckPackageHandle) (CheckPackageHand
6262
}
6363
result := handles[0]
6464
for _, handle := range handles[1:] {
65-
if result == nil || len(handle.Files()) < len(result.Files()) {
65+
if result == nil || len(handle.CompiledGoFiles()) < len(result.CompiledGoFiles()) {
6666
result = handle
6767
}
6868
}
@@ -82,7 +82,7 @@ func WidestCheckPackageHandle(handles []CheckPackageHandle) (CheckPackageHandle,
8282
}
8383
result := handles[0]
8484
for _, handle := range handles[1:] {
85-
if result == nil || len(handle.Files()) > len(result.Files()) {
85+
if result == nil || len(handle.CompiledGoFiles()) > len(result.CompiledGoFiles()) {
8686
result = handle
8787
}
8888
}

internal/lsp/source/view.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ type CheckPackageHandle interface {
117117
ID() string
118118

119119
// ParseGoHandle returns a ParseGoHandle for which to get the package.
120-
Files() []ParseGoHandle
120+
CompiledGoFiles() []ParseGoHandle
121121

122122
// Check returns the type-checked Package for the CheckPackageHandle.
123123
Check(ctx context.Context) (Package, error)
@@ -333,7 +333,7 @@ type Scope interface {
333333
type Package interface {
334334
ID() string
335335
PkgPath() string
336-
Files() []ParseGoHandle
336+
CompiledGoFiles() []ParseGoHandle
337337
File(uri span.URI) (ParseGoHandle, error)
338338
GetSyntax() []*ast.File
339339
GetErrors() []*Error
@@ -371,5 +371,5 @@ func (e *Error) Error() string {
371371

372372
type BuiltinPackage interface {
373373
Lookup(name string) *ast.Object
374-
Files() []ParseGoHandle
374+
CompiledGoFiles() []ParseGoHandle
375375
}

internal/lsp/text_synchronization.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (s *Server) didClose(ctx context.Context, params *protocol.DidCloseTextDocu
175175
return nil
176176
}
177177
for _, cph := range cphs {
178-
for _, ph := range cph.Files() {
178+
for _, ph := range cph.CompiledGoFiles() {
179179
// If other files from this package are open, don't clear.
180180
if s.session.IsOpen(ph.File().Identity().URI) {
181181
clear = nil

internal/lsp/watched_files.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *Server) didChangeWatchedFiles(ctx context.Context, params *protocol.Did
5555
// Find a different file in the same package we can use to trigger diagnostics.
5656
// TODO(rstambler): Allow diagnostics to be called per-package to avoid this.
5757
var otherFile source.File
58-
for _, ph := range cph.Files() {
58+
for _, ph := range cph.CompiledGoFiles() {
5959
if ph.File().Identity().URI == f.URI() {
6060
continue
6161
}

0 commit comments

Comments
 (0)