go/internal/lsp
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 internal/lsp: add support for extracting non-nested returns 2021-04-27 20:37:52 +00:00
browser all: replace all usages of os/exec with golang.org/x/sys/execabs 2021-01-19 22:25:03 +00:00
cache internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
cmd internal/lsp: make ShowDocument RPC available to gopls 2021-05-03 16:38:18 +00:00
command internal/lsp: add a command to start the debug server 2021-04-26 15:43:18 +00:00
debug internal/lsp/source/completion: avoid a panic in package completion 2021-05-10 23:22:37 +00:00
diff all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
fake internal/lsp/source: support typeDefinition for function/method's return values 2021-05-06 03:15:21 +00:00
fuzzy
helper internal/lsp/protocol: latest version of LSP 2021-04-20 19:23:16 +00:00
lsprpc internal/lsp/cmd: add a command-line command to start daemon debugging 2021-04-27 13:49:53 +00:00
mod internal/lsp: switch to 'go get -u ./...' for transitive upgrades 2021-04-07 17:38:53 +00:00
protocol internal/lsp: make ShowDocument RPC available to gopls 2021-05-03 16:38:18 +00:00
regtest internal/lsp/regtest: add a benchmark for didChange 2021-05-06 02:57:18 +00:00
snippet internal/lsp/source/completion: add postfix snippet completions 2021-03-29 17:27:46 +00:00
source internal/lsp/cache: trim more stuff in ParseExported mode 2021-05-11 17:48:41 +00:00
template internal/lsp: support template files 2021-05-05 01:45:45 +00:00
testdata internal/lsp: in semantic tokens, better distinguish between types and variables 2021-05-11 14:51:35 +00:00
tests internal/lsp: support template files 2021-05-05 01:45:45 +00:00
README.md internal/lsp: add READMEs that describe tests, how to run tests 2020-12-03 17:03:53 +00:00
call_hierarchy.go
code_action.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
code_lens.go internal/lsp: switch to the new command API 2021-02-09 22:09:28 +00:00
command.go internal/lsp: add a command to start the debug server 2021-04-26 15:43:18 +00:00
completion.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
completion_test.go internal/lsp/completion: move postfix completions behind option 2021-03-29 18:55:49 +00:00
debounce.go
debounce_test.go internal/lsp: delay longer in TestDebouncer 2020-10-30 20:03:00 +00:00
definition.go internal/lsp: fix no definition when importShortcut is link 2021-05-10 21:56:33 +00:00
diagnostics.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
folding_range.go all: add copyright notices to files that are missing them 2021-01-06 17:23:47 +00:00
format.go
general.go internal/lsp: warn users who have built gopls with go-diff v1.2.0 2021-05-03 16:36:24 +00:00
highlight.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
hover.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
implementation.go
link.go internal/lsp: add ?utm_source=gopls to links to pkg.go.dev 2020-11-16 00:15:58 +00:00
lsp_test.go internal/lsp: remove some unused parameters, mostly in the cache package 2021-03-25 00:26:08 +00:00
progress.go internal/lsp: update to latest version of LSP protocol 2021-02-02 11:32:59 +00:00
progress_test.go
references.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
rename.go internal/lsp/source: make it an error to rename embedded fields 2021-01-26 13:52:46 +00:00
reset_golden.sh
semantic.go internal/lsp: in semantic tokens, better distinguish between types and variables 2021-05-11 14:51:35 +00:00
server.go internal/lsp: add a temp workspace per folder, and a helper command 2021-03-15 23:11:33 +00:00
server_gen.go internal/lsp: make ShowDocument RPC available to gopls 2021-05-03 16:38:18 +00:00
signature_help.go internal/lsp: update to latest version of LSP protocol 2021-02-02 11:32:59 +00:00
symbols.go internal/lsp: support template files 2021-05-05 01:45:45 +00:00
text_synchronization.go internal/lsp: update to latest version of LSP protocol 2021-02-02 11:32:59 +00:00
workspace.go internal/lsp: add a temp workspace per folder, and a helper command 2021-03-15 23:11:33 +00:00
workspace_symbol.go

README.md

lsp

internal/lsp provides much of the Language Server Protocol (lsp) implementation for gopls.

Documentation for users and contributors can be found in the gopls/doc directory.