go/internal/lsp/cache
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
..
analysis.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
cache.go internal/lsp: remove some unused parameters, mostly in the cache package 2021-03-25 00:26:08 +00:00
check.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
error_test.go internal/lsp/cache: split up sourceDiagnostics 2021-03-02 02:05:13 +00:00
errors.go internal/lsp/cache: add a scheme for types error code links 2021-04-15 23:21:34 +00:00
imports.go internal/lsp/cache: fix panic in GOPATH mode 2021-01-07 18:21:03 +00:00
keys.go internal/lsp: decouple client and server debug 2020-06-11 13:49:48 +00:00
load.go internal/lsp: don't use ast.NewPackage to build builtin 2021-04-30 20:08:34 +00:00
mod.go internal/lsp: fix support for SourceFixAll code actions 2021-03-24 23:51:27 +00:00
mod_tidy.go internal/lsp: remove unnecessary call to WorkspacePackages in mod tidy 2021-03-30 04:13:47 +00:00
os_darwin.go
os_windows.go
parse.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
parse_test.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
pkg.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
session.go internal/lsp: do not reinitialize the workspace for didOpen events 2021-05-10 21:57:30 +00:00
snapshot.go internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
view.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
view_test.go internal/lsp: refactor go command error handling 2021-02-16 21:26:54 +00:00
workspace.go internal/lsp: do not reinitialize the workspace for didOpen events 2021-05-10 21:57:30 +00:00
workspace_test.go internal/lsp/cache: compare file size when invalidating file cache 2021-01-12 21:35:00 +00:00