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 <rstambler@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go
index f54f3c8..c33f9e2 100644
--- a/internal/lsp/cache/analysis.go
+++ b/internal/lsp/cache/analysis.go
@@ -85,10 +85,10 @@
 	}
 	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 00042dd2..b3e9e04 100644
--- a/internal/lsp/cache/check.go
+++ b/internal/lsp/cache/check.go
@@ -24,7 +24,7 @@
 	errors "golang.org/x/xerrors"
 )
 
-// packageHandle implements source.CheckPackageHandle.
+// packageHandle implements source.PackageHandle.
 type packageHandle struct {
 	handle *memoize.Handle
 
@@ -58,14 +58,14 @@
 	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 @@
 	})
 	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 0bd0fee..4f7f3df 100644
--- a/internal/lsp/cache/snapshot.go
+++ b/internal/lsp/cache/snapshot.go
@@ -41,7 +41,7 @@
 	// 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 @@
 	}
 	// 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 @@
 	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 d78e53f..bdf6e46 100644
--- a/internal/lsp/code_action.go
+++ b/internal/lsp/code_action.go
@@ -209,7 +209,7 @@
 	}
 	// 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 a328800..e8b8b54 100644
--- a/internal/lsp/definition.go
+++ b/internal/lsp/definition.go
@@ -26,7 +26,7 @@
 	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 @@
 	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 a93a30d..967907a 100644
--- a/internal/lsp/hover.go
+++ b/internal/lsp/hover.go
@@ -26,7 +26,7 @@
 	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 7725bc6..7fa1038 100644
--- a/internal/lsp/rename.go
+++ b/internal/lsp/rename.go
@@ -26,7 +26,7 @@
 	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 @@
 	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 1878f73..3d0ed09 100644
--- a/internal/lsp/source/completion.go
+++ b/internal/lsp/source/completion.go
@@ -411,7 +411,7 @@
 
 	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 89bf8d8..8336706 100644
--- a/internal/lsp/source/diagnostics.go
+++ b/internal/lsp/source/diagnostics.go
@@ -48,7 +48,7 @@
 	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 7d10981..6d6dfbf 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -80,7 +80,7 @@
 	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 89c057d..af9c6da 100644
--- a/internal/lsp/source/highlight.go
+++ b/internal/lsp/source/highlight.go
@@ -21,7 +21,7 @@
 	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 b3882b0..2e00d57 100644
--- a/internal/lsp/source/signature_help.go
+++ b/internal/lsp/source/signature_help.go
@@ -32,7 +32,7 @@
 	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 f6d36e9..1c13d2f 100644
--- a/internal/lsp/source/source_test.go
+++ b/internal/lsp/source/source_test.go
@@ -496,7 +496,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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 609f430..0627d03 100644
--- a/internal/lsp/source/symbols.go
+++ b/internal/lsp/source/symbols.go
@@ -18,7 +18,7 @@
 	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 ce49b31..9e40ca0 100644
--- a/internal/lsp/source/util.go
+++ b/internal/lsp/source/util.go
@@ -66,7 +66,7 @@
 }
 
 // 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 @@
 
 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 @@
 		}
 	}
 	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 @@
 		}
 	}
 	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 789ac99..c946d23 100644
--- a/internal/lsp/source/view.go
+++ b/internal/lsp/source/view.go
@@ -40,8 +40,8 @@
 	// 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 @@
 // 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.