go/internal/lsp/source
Rob Findley d463eb0e41 internal/lsp/cache: introduce a workspace abstraction
When incorporating the gopls.mod file, the invalidation logic for
workspace module information becomes quite complicated. For example:
 + if a modfile changes we should only invalidate if it is in the set of
   active modules
 + the set of active modules can be provided by either the filesystem or
   gopls.mod
 + if gopls.mod changes, we may gain or lose active modules in the
   workspace
 + if gopls.mod is *deleted*, we may need to walk the filesystem to
   actually find all active modules

Doing this with only concrete changes to the snapshot proved
prohibitively complex (at least for me), so a new workspace type is
introduced to manage the module state. This new abstraction is
responsible for tracking the set of active modules, the workspace
modfile, and the set of workspace directories. Its invalidation logic is
factored out of snapshot.clone, so that it can be tested and to
alleviate some of the growing complexity of snapshot.clone.

The workspace type is idempotent, allowing it to be shared across
snapshots without needing to use the cache. There is little benefit to
the cache in this case, since workspace module computation should be
infrequent, and the type itself consumes little memory.

This is made possible because the workspace type itself depends only on
file state, and therefore may be invalidated independently of the
snapshot. The new source.FileState interface is used in testing, and so
that the workspace module may be computed based on both the session file
state as well as the snapshot file state.

As a result of this change, the following improvements in functionality
are possible:
 + in the presence of a gopls.mod file, we avoid walking the filesystem
   to detect modules. This could be helpful for working in large
   monorepos or in GOPATH, when discovering all modules would be
   expensive.
 + The set of active modules should always be consistent with the
   gopls.mod file, likely fixing some bugs (for example, computing
   diagnostics for modfiles that shouldn't be loaded)

For golang/go#41837

Change-Id: I2da888c097748b659ee892ca2d6b3fbe29c1942e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261237
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-10-30 19:58:30 +00:00
..
completion internal/lsp/source/completion: remove "completion_" prefix from files 2020-10-30 17:45:15 +00:00
genapijson internal/lsp/source: use 'gopls.' instead of 'gopls_' 2020-10-20 14:19:29 +00:00
api_json.go internal/lsp: use the go command to fix go.mod files 2020-10-28 22:47:54 +00:00
call_hierarchy.go internal/lsp/source: handle a possible nil pointer in call hierarchy 2020-10-09 16:22:40 +00:00
code_lens.go gopls: add "go test" code action 2020-10-13 16:52:01 +00:00
command.go internal/lsp: use the go command to fix go.mod files 2020-10-28 22:47:54 +00:00
comment.go internal/lsp/source: use space character in markdown formatting 2020-08-26 03:44:07 +00:00
comment_test.go
diagnostics.go internal/lsp: use the go command to fix go.mod files 2020-10-28 22:47:54 +00:00
extract.go internal/lsp: clean up unused parameters 2020-10-16 23:51:31 +00:00
folding_range.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00
format.go internal/lsp: clean up unused parameters 2020-10-16 23:51:31 +00:00
format_test.go internal/lsp: reproduce and fix golang/go#41057 2020-09-02 22:40:51 +00:00
gc_annotations.go internal/lsp: elide details for non-package files 2020-10-30 01:04:31 +00:00
highlight.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00
hover.go internal/lsp: clean up unused parameters 2020-10-16 23:51:31 +00:00
identifier.go internal/lsp: fix hover for builtin error method (Error) 2020-10-05 18:50:03 +00:00
identifier_test.go internal/lsp/source: add a unit test for searchForEnclosing 2020-07-28 18:51:24 +00:00
implementation.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00
options.go internal/lsp/source: add missing vet analyzers 2020-10-29 19:53:23 +00:00
options_test.go internal/lsp: don't show an error for "allExperiments" in (options).set 2020-10-07 03:26:33 +00:00
references.go internal/lsp/source: show references to interface methods 2020-10-06 22:15:05 +00:00
rename.go internal/lsp/source: show references to interface methods 2020-10-06 22:15:05 +00:00
rename_check.go internal/lsp/source: handle nil pointer in rename_check.go 2020-10-23 17:41:41 +00:00
signature_help.go internal/lsp/source: respect user's hover kind in signature help 2020-10-29 22:52:41 +00:00
source_test.go internal/lsp: add gopls semtok command and semantic token tests 2020-10-16 18:10:36 +00:00
symbols.go internal/lsp: don't show blank identifiers in outline 2020-10-09 01:09:51 +00:00
types_format.go internal/lsp/source: respect user's hover kind in signature help 2020-10-29 22:52:41 +00:00
util.go internal/lsp: move package selection to before type checking 2020-09-24 22:42:22 +00:00
view.go internal/lsp/cache: introduce a workspace abstraction 2020-10-30 19:58:30 +00:00
workspace_symbol.go internal/lsp/source: use bestMatch for fully qualified symbol style 2020-10-30 14:32:52 +00:00
workspace_symbol_test.go internal/lsp/source: support some fzf-like tokens in symbol matching 2020-09-08 16:35:05 +00:00