1
0
mirror of https://github.com/golang/go synced 2024-09-30 12:28:35 -06:00
go/internal
Robert Findley 88346e9948 internal/lsp: refactor workspace Symbol method
This is based on Paul Jolly's CL 228760, updated to use the new cache
API, support the symbolStyle configuration option, and lift up the
concept of symbol score for later improvement.

From that CL:

There are a number of issues with the current implementation:

* test variant packages are not handled correctly, meaning duplicate
  symbols are returned
* fuzzy results are not ordered by score

We refactor the implementation of workspace symbol to use a
symbolCollector that carries context during the walk for symbols. As
part of resolving the test variant issue, we first determine a list of
packages to walk.

(*symbolCollector).collectPackages gathers the packages we are going to
inspect for symbols. This pre-step is required in order to filter out
any "duplicate" *types.Package. The duplicates arise for packages that
have test variants.  For example, if package mod.com/p has test files,
then we will visit two packages that have the PkgPath() mod.com/p: the
first is the actual package mod.com/p, the second is a special version
that includes the non-XTest _test.go files. If we were to walk both of
of these packages, then we would get duplicate matching symbols and we
would waste effort. Therefore where test variants exist we walk those
(because they include any symbols defined in non-XTest _test.go files).

One further complication is that even after this filtering, packages
between views might not be "identical" because they can be built using
different build constraints (via the "env" config option). Therefore on
a per view basis we first build up a map of PkgPath() -> *types.Package
preferring the test variants if they exist. Then we merge the results
between views, de-duping by *types.Package.

Finally, when we come to walk these packages and start gathering
symbols, we ignore any files we have already seen (due to different
*types.Package for the same import path as a result of different build
constraints), keeping track of those symbols via symbolCollector.

Then we walk that list of packages in much the same way as before.

For golang/go#40548

Co-authored-by: Paul Jolly <paul@myitcv.io>
Change-Id: I8af5bdedbd4a6c3631a213d73a735aea556a13ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247818
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 18:13:30 +00:00
..
analysisinternal internal/analysisinternal: add anonymous structs & interfaces to 2020-08-25 20:24:27 +00:00
apidiff all: fix more typos 2019-09-11 15:13:14 +00:00
event internal/event: improve the logging of events 2020-05-11 17:49:55 +00:00
fakenet internal/fakenet: add a fake network connection 2020-05-27 14:27:59 +00:00
fastwalk internal/fastwalk: attempt Symlink tests on Windows 2020-05-21 21:19:27 +00:00
gocommand all: rework goimports environment, support GOMODCACHE 2020-06-25 17:33:20 +00:00
gopathwalk internal/imports: fix crash when adding stdlib imports 2020-08-13 17:47:04 +00:00
imports internal/lsp: add completion suggestions for import statements 2020-08-27 18:03:53 +00:00
jsonrpc2 internal/lsp: support go1.12 2020-07-20 15:02:56 +00:00
lsp internal/lsp: refactor workspace Symbol method 2020-08-27 18:13:30 +00:00
memoize internal/memoize: switch from GC-driven to explicit deletion 2020-08-10 19:02:17 +00:00
packagesinternal go/packages: move TypecheckCgo to packagesinternal 2020-06-10 22:20:39 +00:00
proxydir all: remove version-specific test files 2020-05-28 17:13:50 +00:00
span internal/lsp/source: fix completion on final line of a document 2020-08-25 22:56:35 +00:00
stack internal/stack: add the leak test 2020-05-27 14:25:42 +00:00
testenv internal/testenv: add a NeedsGoBuild function 2020-06-10 16:09:22 +00:00
tool internal/tool: avoid editorialization 2020-03-05 14:01:59 +00:00
typesinternal go/packages: use go115UsesCgo instead of UsesCgo 2020-06-10 21:22:23 +00:00
xcontext internal/lsp: stop making background contexts everywhere 2019-07-11 16:38:52 +00:00