go/internal/lsp/source
Heschi Kreinick cd1d0887dc internal/lsp/cache: trim more stuff in ParseExported mode
Despite the name, ParseExported only hollowed out declarations -- it
didn't actually drop any from the AST. This leaves a fair amount of
unexported crud behind. Unfortunately, there are a *lot* of ways to
expose an unexported declaration from an exported one, and it can be
done across files. Because of that, discarding unexported declarations
requires a lot of work.

This CL implements a decent attempt at pruning as much as possible from
the AST in ParseExported mode.

First, we analyze the AST of all the files in the package for exported
uses of unexported identifiers, iterating to a fixed point. Then, we
type check those ASTs. If there are missing identifiers (probably due to
a bug in the dependency analysis) we use those errors to re-parse. After
that we give up and fall back to the older, less effective trimming. The
pkg type changes slightly to accomodate the new control flow.

We have to analyze all the files at once because an unexported type
might be exposed in another file. Unfortunately, that means we can't
parse a single file at a time any more -- the result of parsing a file
depends on the result of parsing its siblings. To avoid cache
corruption, we have to do the parsing directly in type checking,
uncached.

This, in turn, required changes to the PosTo* functions. Previously,
they operated just on files, but a file name is no longer sufficient to
get a ParseExported AST. Change them to work on Packages instead. I
squeezed in a bit of refactoring while I was touching them.

Change-Id: I61249144ffa43ad645ed38d79e873e3998b0f38d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312471
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-11 17:48:41 +00:00
..
completion internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
api_json.go lsp/source: enable experimentalPostfixCompletions by default 2021-05-05 22:35:07 +00:00
call_hierarchy.go internal/lsp/source: return all field funcs from outgoing callhierarchy 2021-01-05 17:25:16 +00:00
code_lens.go internal/lsp: switch to the new command API 2021-02-09 22:09:28 +00:00
comment.go all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
comment_test.go all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
diagnostics.go internal/lsp: fix support for SourceFixAll code actions 2021-03-24 23:51:27 +00:00
extract.go internal/lsp: print comments that would be lost during extract func 2021-04-28 01:46:37 +00:00
fix.go internal/lsp: fix support for SourceFixAll code actions 2021-03-24 23:51:27 +00:00
folding_range.go internal/lsp/source: return nil for foldingRange in case of parse error 2021-03-08 17:39:28 +00:00
format.go internal/lsp, gopls: recover from go-diff panics 2020-12-17 16:56:54 +00:00
format_test.go all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
gc_annotations.go internal/lsp: key GC details off package ID 2021-03-02 22:01:38 +00:00
highlight.go internal/lsp/source: fix Highlight for std and 3rd-party packages 2021-04-05 22:17:18 +00:00
hover.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
identifier.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
identifier_test.go internal/lsp: fix some incorrect spelling 2020-11-24 11:59:21 +00:00
implementation.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00
options.go lsp/source: enable experimentalPostfixCompletions by default 2021-05-05 22:35:07 +00:00
options_test.go internal/lsp: restructure user options (CL 278433 continued) 2020-12-30 21:54:22 +00:00
references.go internal/lsp/source: rename uses of embedded fields 2021-01-12 21:27:35 +00:00
rename.go internal/lsp/source: make it an error to rename embedded fields 2021-01-26 13:52:46 +00:00
rename_check.go internal/lsp/source: eliminate GetTypeCheckDiagnostics 2021-03-03 21:21:28 +00:00
signature_help.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
source_test.go internal/lsp/completion: move postfix completions behind option 2021-03-29 18:55:49 +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/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
util.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
view.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
workspace_symbol.go internal/lsp/source: correct workspace symbol logic for unpacking receivers 2021-03-05 19:21:50 +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