mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
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>
This commit is contained in:
parent
3d14842334
commit
7ae403b6b5
4
internal/lsp/cache/analysis.go
vendored
4
internal/lsp/cache/analysis.go
vendored
@ -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 {
|
||||
|
12
internal/lsp/cache/check.go
vendored
12
internal/lsp/cache/check.go
vendored
@ -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 {
|
||||
|
6
internal/lsp/cache/snapshot.go
vendored
6
internal/lsp/cache/snapshot.go
vendored
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user