From 7ae403b6b5894e0633fab4d0f8ddaeda408f9a0e Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Tue, 14 Jan 2020 18:29:21 -0500 Subject: [PATCH] internal/lsp: finish renaming CheckPackageHandle to PackageHandle In golang.org/cl/209419, CheckPackageHandle was renamed to PackageHandle, but a number of references to CheckPackageHandle remained in function names and comments. This CL cleans up most of these, though there was at least one case (internal/lsp/cache.checkPackageKey) where the obvious renaming conflicted with another function, so I skipped it. Change-Id: I517324279ff05bd5b1cab4eeb212a0090ca3e3ad Reviewed-on: https://go-review.googlesource.com/c/tools/+/214800 Reviewed-by: Rebecca Stambler Run-TryBot: Robert Findley TryBot-Result: Gobot Gobot --- internal/lsp/cache/analysis.go | 4 ++-- internal/lsp/cache/check.go | 12 ++++++------ internal/lsp/cache/snapshot.go | 6 +++--- internal/lsp/code_action.go | 2 +- internal/lsp/definition.go | 4 ++-- internal/lsp/hover.go | 2 +- internal/lsp/rename.go | 4 ++-- internal/lsp/source/completion.go | 2 +- internal/lsp/source/diagnostics.go | 2 +- internal/lsp/source/format.go | 2 +- internal/lsp/source/highlight.go | 2 +- internal/lsp/source/signature_help.go | 2 +- internal/lsp/source/source_test.go | 8 ++++---- internal/lsp/source/symbols.go | 2 +- internal/lsp/source/util.go | 18 +++++++++--------- internal/lsp/source/view.go | 10 +++++----- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index f54f3c8afc..c33f9e23e6 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -85,10 +85,10 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.P } ph := s.getPackage(id, mode) if ph == nil { - return nil, errors.Errorf("no CheckPackageHandle for %s:%v", id, mode == source.ParseExported) + return nil, errors.Errorf("no PackageHandle for %s:%v", id, mode == source.ParseExported) } if len(ph.key) == 0 { - return nil, errors.Errorf("no key for CheckPackageHandle %s", id) + return nil, errors.Errorf("no key for PackageHandle %s", id) } pkg, err := ph.check(ctx) if err != nil { diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 00042dd26c..b3e9e04df1 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -24,7 +24,7 @@ import ( errors "golang.org/x/xerrors" ) -// packageHandle implements source.CheckPackageHandle. +// packageHandle implements source.PackageHandle. type packageHandle struct { handle *memoize.Handle @@ -58,14 +58,14 @@ type packageData struct { err error } -// buildPackageHandle returns a source.CheckPackageHandle for a given package and config. +// buildPackageHandle returns a source.PackageHandle for a given package and config. func (s *snapshot) buildPackageHandle(ctx context.Context, id packageID, mode source.ParseMode) (*packageHandle, error) { - // Check if we already have this CheckPackageHandle cached. + // Check if we already have this PackageHandle cached. if ph := s.getPackage(id, mode); ph != nil { return ph, nil } - // Build the CheckPackageHandle for this ID and its dependencies. + // Build the PackageHandle for this ID and its dependencies. ph, deps, err := s.buildKey(ctx, id, mode) if err != nil { return nil, err @@ -98,13 +98,13 @@ func (s *snapshot) buildPackageHandle(ctx context.Context, id packageID, mode so }) ph.handle = h - // Cache the CheckPackageHandle in the snapshot. + // Cache the PackageHandle in the snapshot. s.addPackage(ph) return ph, nil } -// buildKey computes the checkPackageKey for a given checkPackageHandle. +// buildKey computes the key for a given packageHandle. func (s *snapshot) buildKey(ctx context.Context, id packageID, mode source.ParseMode) (*packageHandle, map[packagePath]*packageHandle, error) { m := s.getMetadata(id) if m == nil { diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 0bd0fee384..4f7f3df7a8 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -41,7 +41,7 @@ type snapshot struct { // It may invalidated when a file's content changes. files map[span.URI]source.FileHandle - // packages maps a packageKey to a set of CheckPackageHandles to which that file belongs. + // packages maps a packageKey to a set of packageHandles to which that file belongs. // It may be invalidated when a file's content changes. packages map[packageKey]*packageHandle @@ -215,7 +215,7 @@ func (s *snapshot) shouldCheck(m []*metadata) (phs []*packageHandle, load, check } // We expect to see a checked package for each package ID, // and it should be parsed in full mode. - // If a single CheckPackageHandle is missing, re-check all of them. + // If a single PackageHandle is missing, re-check all of them. // TODO: Optimize this by only checking the necessary packages. for _, metadata := range m { ph := s.getPackage(metadata.id, source.ParseFull) @@ -309,7 +309,7 @@ func (s *snapshot) addPackage(ph *packageHandle) { s.mu.Lock() defer s.mu.Unlock() - // TODO: We should make sure not to compute duplicate CheckPackageHandles, + // TODO: We should make sure not to compute duplicate packageHandles, // and instead panic here. This will be hard to do because we may encounter // the same package multiple times in the dependency tree. if _, ok := s.packages[ph.packageKey()]; ok { diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index d78e53fd83..bdf6e46bd5 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -209,7 +209,7 @@ func quickFixes(ctx context.Context, snapshot source.Snapshot, fh source.FileHan } // We get the package that source.Diagnostics would've used. This is hack. // TODO(golang/go#32443): The correct solution will be to cache diagnostics per-file per-snapshot. - ph, err := source.WidestCheckPackageHandle(phs) + ph, err := source.WidestPackageHandle(phs) if err != nil { return nil, err } diff --git a/internal/lsp/definition.go b/internal/lsp/definition.go index a328800cc0..e8b8b540d3 100644 --- a/internal/lsp/definition.go +++ b/internal/lsp/definition.go @@ -26,7 +26,7 @@ func (s *Server) definition(ctx context.Context, params *protocol.DefinitionPara if fh.Identity().Kind != source.Go { return nil, nil } - ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestPackageHandle) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (s *Server) typeDefinition(ctx context.Context, params *protocol.TypeDefini if fh.Identity().Kind != source.Go { return nil, nil } - ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestPackageHandle) if err != nil { return nil, err } diff --git a/internal/lsp/hover.go b/internal/lsp/hover.go index a93a30ddf3..967907ab5f 100644 --- a/internal/lsp/hover.go +++ b/internal/lsp/hover.go @@ -26,7 +26,7 @@ func (s *Server) hover(ctx context.Context, params *protocol.HoverParams) (*prot if fh.Identity().Kind != source.Go { return nil, nil } - ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestPackageHandle) if err != nil { return nil, nil } diff --git a/internal/lsp/rename.go b/internal/lsp/rename.go index 7725bc6b88..7fa10389f2 100644 --- a/internal/lsp/rename.go +++ b/internal/lsp/rename.go @@ -26,7 +26,7 @@ func (s *Server) rename(ctx context.Context, params *protocol.RenameParams) (*pr if fh.Identity().Kind != source.Go { return nil, nil } - ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestPackageHandle) if err != nil { return nil, nil } @@ -61,7 +61,7 @@ func (s *Server) prepareRename(ctx context.Context, params *protocol.PrepareRena if fh.Identity().Kind != source.Go { return nil, nil } - ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, snapshot, fh, params.Position, source.WidestPackageHandle) if err != nil { return nil, nil // ignore errors } diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 1878f7321b..3d0ed09ffb 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -411,7 +411,7 @@ func Completion(ctx context.Context, snapshot Snapshot, fh FileHandle, pos proto startTime := time.Now() - pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestCheckPackageHandle) + pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestPackageHandle) if err != nil { return nil, nil, fmt.Errorf("getting file for Completion: %v", err) } diff --git a/internal/lsp/source/diagnostics.go b/internal/lsp/source/diagnostics.go index 89bf8d8163..8336706e3a 100644 --- a/internal/lsp/source/diagnostics.go +++ b/internal/lsp/source/diagnostics.go @@ -48,7 +48,7 @@ func FileDiagnostics(ctx context.Context, snapshot Snapshot, fh FileHandle, with if err != nil { return nil, "", err } - ph, err := WidestCheckPackageHandle(phs) + ph, err := WidestPackageHandle(phs) if err != nil { return nil, "", err } diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go index 7d10981361..6d6dfbf512 100644 --- a/internal/lsp/source/format.go +++ b/internal/lsp/source/format.go @@ -80,7 +80,7 @@ func AllImportsFixes(ctx context.Context, snapshot Snapshot, fh FileHandle) (all ctx, done := trace.StartSpan(ctx, "source.AllImportsFixes") defer done() - pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestCheckPackageHandle) + pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestPackageHandle) if err != nil { return nil, nil, errors.Errorf("getting file for AllImportsFixes: %v", err) } diff --git a/internal/lsp/source/highlight.go b/internal/lsp/source/highlight.go index 89c057db18..af9c6dab0b 100644 --- a/internal/lsp/source/highlight.go +++ b/internal/lsp/source/highlight.go @@ -21,7 +21,7 @@ func Highlight(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protoc ctx, done := trace.StartSpan(ctx, "source.Highlight") defer done() - pkg, pgh, err := getParsedFile(ctx, snapshot, fh, WidestCheckPackageHandle) + pkg, pgh, err := getParsedFile(ctx, snapshot, fh, WidestPackageHandle) if err != nil { return nil, fmt.Errorf("getting file for Highlight: %v", err) } diff --git a/internal/lsp/source/signature_help.go b/internal/lsp/source/signature_help.go index b3882b0c44..2e00d57cef 100644 --- a/internal/lsp/source/signature_help.go +++ b/internal/lsp/source/signature_help.go @@ -32,7 +32,7 @@ func SignatureHelp(ctx context.Context, snapshot Snapshot, fh FileHandle, pos pr ctx, done := trace.StartSpan(ctx, "source.SignatureHelp") defer done() - pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestCheckPackageHandle) + pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestPackageHandle) if err != nil { return nil, fmt.Errorf("getting file for SignatureHelp: %v", err) } diff --git a/internal/lsp/source/source_test.go b/internal/lsp/source/source_test.go index f6d36e9320..1c13d2f09d 100644 --- a/internal/lsp/source/source_test.go +++ b/internal/lsp/source/source_test.go @@ -496,7 +496,7 @@ func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) { if err != nil { t.Fatal(err) } - ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestCheckPackageHandle) + ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestPackageHandle) if err != nil { t.Fatalf("failed for %v: %v", d.Src, err) } @@ -638,7 +638,7 @@ func (r *runner) References(t *testing.T, src span.Span, itemList []span.Span) { if err != nil { t.Fatal(err) } - ident, err := source.Identifier(ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestCheckPackageHandle) + ident, err := source.Identifier(ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestPackageHandle) if err != nil { t.Fatalf("failed for %v: %v", src, err) } @@ -682,7 +682,7 @@ func (r *runner) Rename(t *testing.T, spn span.Span, newText string) { if err != nil { t.Fatal(err) } - ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestCheckPackageHandle) + ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestPackageHandle) if err != nil { t.Error(err) return @@ -769,7 +769,7 @@ func (r *runner) PrepareRename(t *testing.T, src span.Span, want *source.Prepare if err != nil { t.Fatal(err) } - ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestCheckPackageHandle) + ident, err := source.Identifier(r.ctx, r.view.Snapshot(), fh, srcRng.Start, source.WidestPackageHandle) if err != nil { if want.Text != "" { // expected an ident. t.Errorf("prepare rename failed for %v: got error: %v", src, err) diff --git a/internal/lsp/source/symbols.go b/internal/lsp/source/symbols.go index 609f430c6c..0627d03470 100644 --- a/internal/lsp/source/symbols.go +++ b/internal/lsp/source/symbols.go @@ -18,7 +18,7 @@ func DocumentSymbols(ctx context.Context, snapshot Snapshot, fh FileHandle) ([]p ctx, done := trace.StartSpan(ctx, "source.DocumentSymbols") defer done() - pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestCheckPackageHandle) + pkg, pgh, err := getParsedFile(ctx, snapshot, fh, NarrowestPackageHandle) if err != nil { return nil, fmt.Errorf("getting file for DocumentSymbols: %v", err) } diff --git a/internal/lsp/source/util.go b/internal/lsp/source/util.go index ce49b311e4..9e40ca03de 100644 --- a/internal/lsp/source/util.go +++ b/internal/lsp/source/util.go @@ -66,7 +66,7 @@ func (s mappedRange) URI() span.URI { } // getParsedFile is a convenience function that extracts the Package and ParseGoHandle for a File in a Snapshot. -// selectPackage is typically Narrowest/WidestCheckPackageHandle below. +// selectPackage is typically Narrowest/WidestPackageHandle below. func getParsedFile(ctx context.Context, snapshot Snapshot, fh FileHandle, selectPackage PackagePolicy) (Package, ParseGoHandle, error) { phs, err := snapshot.PackageHandles(ctx, fh) if err != nil { @@ -86,14 +86,14 @@ func getParsedFile(ctx context.Context, snapshot Snapshot, fh FileHandle, select type PackagePolicy func([]PackageHandle) (PackageHandle, error) -// NarrowestCheckPackageHandle picks the "narrowest" package for a given file. +// NarrowestPackageHandle picks the "narrowest" package for a given file. // // By "narrowest" package, we mean the package with the fewest number of files // that includes the given file. This solves the problem of test variants, // as the test will have more files than the non-test package. -func NarrowestCheckPackageHandle(handles []PackageHandle) (PackageHandle, error) { +func NarrowestPackageHandle(handles []PackageHandle) (PackageHandle, error) { if len(handles) < 1 { - return nil, errors.Errorf("no CheckPackageHandles") + return nil, errors.Errorf("no PackageHandles") } result := handles[0] for _, handle := range handles[1:] { @@ -102,18 +102,18 @@ func NarrowestCheckPackageHandle(handles []PackageHandle) (PackageHandle, error) } } if result == nil { - return nil, errors.Errorf("nil CheckPackageHandles have been returned") + return nil, errors.Errorf("nil PackageHandles have been returned") } return result, nil } -// WidestCheckPackageHandle returns the CheckPackageHandle containing the most files. +// WidestPackageHandle returns the PackageHandle containing the most files. // // This is useful for something like diagnostics, where we'd prefer to offer diagnostics // for as many files as possible. -func WidestCheckPackageHandle(handles []PackageHandle) (PackageHandle, error) { +func WidestPackageHandle(handles []PackageHandle) (PackageHandle, error) { if len(handles) < 1 { - return nil, errors.Errorf("no CheckPackageHandles") + return nil, errors.Errorf("no PackageHandles") } result := handles[0] for _, handle := range handles[1:] { @@ -122,7 +122,7 @@ func WidestCheckPackageHandle(handles []PackageHandle) (PackageHandle, error) { } } if result == nil { - return nil, errors.Errorf("nil CheckPackageHandles have been returned") + return nil, errors.Errorf("nil PackageHandles have been returned") } return result, nil } diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go index 789ac9980f..c946d23e87 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go @@ -40,8 +40,8 @@ type Snapshot interface { // ModFiles returns the FileHandles of the go.mod files attached to the view associated with this snapshot. ModFiles(ctx context.Context) (FileHandle, FileHandle, error) - // PackageHandles returns the CheckPackageHandles for the packages - // that this file belongs to. + // PackageHandles returns the PackageHandles for the packages that this file + // belongs to. PackageHandles(ctx context.Context, fh FileHandle) ([]PackageHandle, error) // GetActiveReverseDeps returns the active files belonging to the reverse @@ -63,16 +63,16 @@ type Snapshot interface { // PackageHandle represents a handle to a specific version of a package. // It is uniquely defined by the file handles that make up the package. type PackageHandle interface { - // ID returns the ID of the package associated with the CheckPackageHandle. + // ID returns the ID of the package associated with the PackageHandle. ID() string // CompiledGoFiles returns the ParseGoHandles composing the package. CompiledGoFiles() []ParseGoHandle - // Check returns the type-checked Package for the CheckPackageHandle. + // Check returns the type-checked Package for the PackageHandle. Check(ctx context.Context) (Package, error) - // Cached returns the Package for the CheckPackageHandle if it has already been stored. + // Cached returns the Package for the PackageHandle if it has already been stored. Cached() (Package, error) // MissingDependencies reports any unresolved imports.