Skip to content

Commit

Permalink
gopls/internal/lsp/source/completion: avoid Snapshot.CachedPackages
Browse files Browse the repository at this point in the history
This change removes the last use of CachedPackages, from unimported
completions. Instead, we find candidates in the workspace using
the metadata, then perform a quick parse of each file to extract
the names of exported package members. The quick parse first
uses the scanner to find the function bodies and then deletes
them, eliminating most of the input to the actual scanner.

Unfortunately we can't simply load export data for the relevant
package (which should be quick) and use its type information in
the usual way, because the deep completion machinery is tightly
coupled to the notion of a single realm of objects. We can only
display syntactic information (e.g. var/func/const/type).
Thus this change is a slight functional regression from the old
behavior which presented accurate type information.

Fixes golang/go#58663

Change-Id: Ia750785f51ea82ddea7c7849c2565ed6394df467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/472183
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
adonovan authored and gopherbot committed Mar 7, 2023
1 parent b72edd1 commit f477bf4
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 122 deletions.
8 changes: 0 additions & 8 deletions gopls/internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1113,14 +1113,6 @@ func (s *snapshot) AllMetadata(ctx context.Context) ([]*source.Metadata, error)
return meta, nil
}

func (s *snapshot) CachedPackages(ctx context.Context) []source.Package {
// Cached packages do not make sense with incremental gopls.
//
// TODO(golang/go#58663): re-implement unimported completions to not depend
// on cached import paths.
return nil
}

// TODO(rfindley): clarify that this is only active modules. Or update to just
// use findRootPattern.
func (s *snapshot) GoModForFile(uri span.URI) span.URI {
Expand Down
Loading

0 comments on commit f477bf4

Please sign in to comment.