1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:38:33 -06:00
go/internal/lsp
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
..
analysis internal/lsp: do not log failed suggested fix for fillstruct to stderr 2020-08-22 20:38:24 +00:00
browser internal/lsp: add version and bug commands 2019-05-11 04:16:02 +00:00
cache internal/lsp, go/packages: work-around invalid files in GOPATH mode 2020-08-27 16:29:21 +00:00
cmd internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
debug internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
diff internal/testenv: check that external 'diff' tool is the GNU version 2020-05-08 20:46:49 +00:00
fake internal/lsp/regtest: add benchmarks for IWL and completion 2020-08-27 17:51:12 +00:00
fuzzy internal/lsp: fix errors found by staticcheck 2020-03-19 19:20:54 +00:00
helper internal/lsp: change to helper.go to output a formatted file 2020-01-31 20:35:38 +00:00
lsprpc internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
mod internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
protocol internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
regtest internal/lsp/regtest: add benchmarks for IWL and completion 2020-08-27 17:51:12 +00:00
snippet all: fix broken links to LSP specification 2019-10-02 18:32:53 +00:00
source internal/lsp: refactor workspace Symbol method 2020-08-27 18:13:30 +00:00
testdata internal/lsp: refactor workspace Symbol method 2020-08-27 18:13:30 +00:00
tests internal/lsp: add outgoing calls call hierarchy 2020-08-20 01:08:01 +00:00
call_hierarchy.go internal/lsp: release resources for call hierarchy file requests 2020-08-07 21:04:51 +00:00
code_action.go internal/lsp/cache: don't always type check in default mode 2020-08-19 19:22:15 +00:00
code_lens.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
command.go internal/lsp: improvements for command messages 2020-08-21 20:07:30 +00:00
completion_test.go internal/lsp/source: improve completion in append() 2020-08-15 16:31:36 +00:00
completion.go internal/lsp: ignore period ('.') triggered completions in comments 2020-08-26 04:07:57 +00:00
definition.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
diagnostics.go internal/lsp, go/packages: work-around invalid files in GOPATH mode 2020-08-27 16:29:21 +00:00
folding_range.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
format.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
general.go lsp/general.go: change error messages to give more context 2020-08-27 16:34:09 +00:00
highlight.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
hover.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
implementation.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
link.go internal/lsp/cache: don't always type check in default mode 2020-08-19 19:22:15 +00:00
lsp_test.go internal/lsp: add outgoing calls call hierarchy 2020-08-20 01:08:01 +00:00
progress_test.go internal/lsp: improvements for command messages 2020-08-21 20:07:30 +00:00
progress.go internal/lsp: improvements for command messages 2020-08-21 20:07:30 +00:00
references.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
rename.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
reset_golden.sh internal/lsp: fix regeneration of golden files 2019-09-25 13:16:59 +00:00
server_gen.go internal/lsp/progress: refactor progress reporting 2020-08-10 15:18:52 +00:00
server.go internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
signature_help.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
symbols.go internal/lsp/cache: ref-count snapshots 2020-08-03 22:08:54 +00:00
text_synchronization.go internal/lsp: fix builds and tests for go1.12+ 2020-08-27 14:30:46 +00:00
workspace_symbol.go internal/lsp/source: add a new symbolStyle configuration option 2020-06-26 17:13:37 +00:00
workspace.go internal/memoize: switch from GC-driven to explicit deletion 2020-08-10 19:02:17 +00:00