go/internal/lsp/source/completion
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
..
builtin.go lsp/completion: improve append() param type inference 2021-05-05 20:44:55 +00:00
completion.go internal/lsp/completion: indicate completion candidates that are deprecated 2021-04-30 19:49:23 +00:00
deep_completion.go internal/lsp/source: handle nil pointer exception in completion 2020-11-14 22:40:30 +00:00
deep_completion_test.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00
format.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
keywords.go internal/lsp/source/completion: remove "completion_" prefix from files 2020-10-30 17:45:15 +00:00
labels.go internal/lsp/source/completion: remove "completion_" prefix from files 2020-10-30 17:45:15 +00:00
literal.go internal/lsp/source/completion: add postfix snippet completions 2021-03-29 17:27:46 +00:00
package.go internal/lsp/source/completion: avoid a panic in package completion 2021-05-10 23:22:37 +00:00
package_test.go internal/lsp/source/completion: suggest only valid package names 2021-04-27 19:53:45 +00:00
postfix_snippets.go lsp/completion: fix postfix completions preceding assignments 2021-04-26 15:26:58 +00:00
printf.go internal/lsp: fix some incorrect spelling 2020-11-24 11:59:21 +00:00
printf_test.go internal/lsp/source/completion: remove "completion_" prefix from files 2020-10-30 17:45:15 +00:00
snippet.go internal/lsp/source/completion: remove "completion_" prefix from files 2020-10-30 17:45:15 +00:00
statements.go internal/lsp: add snippet completion for t.Fatal errs 2021-03-15 21:39:02 +00:00
util.go internal/lsp/source/completion: add postfix snippet completions 2021-03-29 17:27:46 +00:00
util_test.go internal/lsp/source: move completion to its own package 2020-09-08 19:19:08 +00:00