Commit Graph

2245 Commits

Author SHA1 Message Date
Heschi Kreinick 19db92ec3b internal/lsp/cache: remove mod upgrade code
At this point I'm fairly sure we don't want it.

Change-Id: Ib0657e8954463df751ab740aa5f582e496ee035b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/286475
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: Rebecca Stambler <rstambler@golang.org>
2021-02-01 16:52:01 +00:00
Rebecca Stambler 0cef57b5b5 internal/lsp/protocol: use a pointer for code action's disabled field
We were always sending an empty reason for "disabled" in code actions,
which leads clients to see all code actions as disabled.

Change-Id: I855fb622a52557cc56ce91cf90fdc971df099a90
Reviewed-on: https://go-review.googlesource.com/c/tools/+/287796
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-01-29 18:11:47 +00:00
Rob Findley f871472f1b internal/lsp/cache: lock in snapshot.knownFilesInDir
We were not locking while iterating s.files in snapshot.knownFilesInDir.
All other accesses of s.files appear to be locked, so this should fix
golang/go#43972.

Fixes golang/go#43972

Change-Id: I01184c3992c91f8beb4a3239f70cc4487a528ec0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/287573
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-01-28 15:26:31 +00:00
Rob Findley c2bea79de9 internal/lsp/source: make it an error to rename embedded fields
Field embedding links two objects (a TypeName and a Var) by name,
requiring special handling during renaming. In CL 282932, renaming of
types was made to propagate to uses of their embeddings. However, no
such propagation in the reverse direction was added, meaning that
renaming an embedded field would not rename the corresponding type, and
code could still be left in a non-compiling state.

It should be an invariant that renaming does not change program
behavior. To enforce with field embeddings this we'd need to also rename
the corresponding type, but this seems problematic. If I'm hovering over
the field selector x.T, and rename T, it is surprising that this would
end up renaming a type.

For lack of a better solution, make it an error to rename embedded
fields, but try to provide a helpful error message.

Also handle the blank identifier, for which renaming was giving a
message to "please file a bug".

Marker tests are added for the new errors in rename, but not for
prepareRename. The prepareRename tests were not set up for asserting on
errors -- perhaps that would be a good project for a later CL where we
clean up errors.

Fixes golang/go#43616

Change-Id: I66c2dd5e531dd102431d1edd443d553687d9ca7e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284312
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-26 13:52:46 +00:00
Ajanthan Balachandran 68bf78a686 internal/lsp/cmd: improve help output of gopls subcommands
This cleans up empty flag documentation of gopls subcommands with no flags.

Fixes #43447

Change-Id: I4d6f689062af24db4e6c652ec9ce0bc1a4a42a8c
GitHub-Last-Rev: d917bdb6ea20117f28b93d72d706874b0c1fcfeb
GitHub-Pull-Request: golang/tools#269
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284215
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-01-25 18:56:18 +00:00
Rob Findley 917f61dfb7 gopls/internal/regtest: automate counting of editor notifications to await
Using awaiting a certain number of work items in the regtest is a source
of flakes and latent bugs. This CL replaces all such assertions with
assertions based on the number of notifications sent by the fake.Editor.

While implementing this, I discovered several tests that had incorrect
counting, so this may fix some flakes.

Implementing this required pushing the asynchronous processing of file
events into the Editor, rather than the Workdir.

Change-Id: I9c3639409f2beed4a76295cbd53180c6e2ace126
Reviewed-on: https://go-review.googlesource.com/c/tools/+/285612
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-25 18:11:24 +00:00
Rebecca Stambler 2972602ec4 internal/lsp: correct links provided in critical error pop-ups
Fixes golang/go#43600

Change-Id: Ib36b832652d20b542a3065544d41fee1f2ae3172
Reviewed-on: https://go-review.googlesource.com/c/tools/+/285515
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-01-22 20:33:18 +00:00
pjw e13398c87d internal/lsp: display current diagnostics in the debug server
The change displays outstanding diagnostics on the Client page of
the debug server.

Very occasionally gopls displays incorrect diagnostics or diagnositics
that won't go away.  It is possible that providing more complete
information will help us find the causes, at least when the debug
server is running.

Change-Id: I01f2bbbfeac86e7296f57f4a9aad8e1e658babfa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/285252
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-22 19:37:57 +00:00
Rebecca Stambler ce34e26943 internal/lsp: don't show context cancellation in the progress bar
As part of investigating golang/go#43023, I noticed that it's possible
for us to show context cancellation as a critical error--we should not
do this.

Change-Id: I1f7cc13a151e0a161d5a4ea4d5b55fba15270b32
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284937
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-21 23:49:53 +00:00
Roland Shoemaker fe37c9e135 all: replace all usages of os/exec with golang.org/x/sys/execabs
This change ensures that packages using exec.LookPath or
exec.Command to find or run binaries do not accidentally run
programs from the current directory when they mean to run programs
from the system PATH instead.

Change-Id: I5907aa630ff64012395a7eb472967a477d90f12e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/949438
Reviewed-by: Katie Hockman <katiehockman@google.com>
Reviewed-by: Russ Cox <rsc@google.com>
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284773
Run-TryBot: Roland Shoemaker <roland@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-01-19 22:25:03 +00:00
Rebecca Stambler a46736d9d9 internal/lsp/source: handle possible nil pointer in rename check
Change-Id: I92cc4015361d40e8a10d05fa6857bee2b302cec4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/284583
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-01-19 19:51:17 +00:00
Rebecca Stambler d78b04bdf9 gopls/doc: clean up and slightly reorganize documentation
This is a first CL to clean up the gopls documentation. The main changes
are cosmetic (to correct warnings found by the MD Lint VS Code
extension), though some parts are reworded or moved around. Ultimately,
more work needs to be done, particularly on the user guide and features
overview.

My current thinking is that we should rename settings.md to
configuration and move the configuration piece out of the user guide,
and also reorganize the user guide to be more "getting started"
oriented.

I'm still not sure where miscellaneous items should go (e.g., working on
the Go distribution itself)--I deleted the FAQ because it seemed useless
and is probably not the most discoverable, but it's the only place that
comes to mind so far.

Change-Id: I3689362067672f7ad8d5e8fd97ca9c7c45cfc8c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280595
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-14 06:55:38 +00:00
Rob Findley f96436850f gopls/internal/regtest: fix synchronization for TestUseGoplsMod
Jumping to definition in a regtest can indirectly lead to a didOpen
call, so the awaits added to TestUseGoplsMod to synchronize metadata
were ineffectual. On Android, this can lead to the race described in
golang/go#43652.

But in any case, all this bookkeeping of notifications is fragile. Avoid
it entirely by having the fake editor keep track of notification
statistics. In the future, we should use this to clean up many existing
regtests.

For golang/go#43554
For golang/go#39384

Change-Id: Icd1619bd5cdd2f646d1a0050f5beaf2ab1c27f37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/283512
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-13 18:03:00 +00:00
Rob Findley f618651c09 internal/lsp/cache: compare file size when invalidating file cache
Our filesystem caching layer uses file modification time to invalidate
file contents. This is an imperfect heuristic, and on certain operating
systems with low resolution filesystem clocks (such as WSL), this can be
broken in practice.

A proper fix would be to just read the file contents directly and rely
on the snapshot to optimize file access, but we don't know that this is
a safe change. Instead, try to reduce the likelihood of false cache hits
by also checking the file size reported by Stat.

For golang/go#43554

Change-Id: I1af384db532725e84fa6f3a2e5469d10b43fee92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/283053
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-12 21:35:00 +00:00
Rob Findley 7646fae968 internal/lsp/fake: use hash rather than mtime to identify workdir files
On builders with low resolution clocks (e.g. WSL), it's possible for us
to miss file events that occur within a single 'tick'.

Fix this by instead tracking full file identity. Since we should have
only a few relatively small files in tests, the additional overhead
should be small.

For golang/go#43554

Change-Id: I05a48567f83007ff2278145638547c6ebb2523fd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/283052
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-12 21:27:48 +00:00
Rob Findley 45115c1c4d internal/lsp/source: rename uses of embedded fields
When renaming a type name, also rename indirect uses of the name as an
embedded field. This is conservatively isolated to just renames for now;
it's not clear to me that users would also want to see uses of embedded
fields as references.

Fixes golang/go#43616

Change-Id: I41913d037fedb8c27a448cd922eeaf11a02d01f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/282932
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2021-01-12 21:27:35 +00:00
Heschi Kreinick 88ba5d0b6d internal/imports: handle un-downloaded modules
Now that gopls is passing GOPROXY=off, running go list -m gives an error
if any modules aren't downloaded. We need to pass -e to get results for
the modules that we do have. Also add the missing error handling that
resulted in silent failure. That, in turn, reveals that we need to
explicitly ignore an expected error.

Fixes golang/go#43333.

Change-Id: I77604650b67a3c480d8231c65f0486f22e4a6722
Reviewed-on: https://go-review.googlesource.com/c/tools/+/283172
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-12 18:32:54 +00:00
Heschi Kreinick 7905ceac4f internal/lsp/cmd: add licenses command
Add a "licenses" command that shows the licenses of included software.

As special cases, we print the Go license first, and the LSP
specification license second since we bundle a Go version of it.

Change-Id: I3575073766a458c214108643b2b550c407a118dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/282112
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: Rebecca Stambler <rstambler@golang.org>
2021-01-08 19:50:35 +00:00
Heschi Kreinick 5bd8423ece internal/lsp/cache: fix panic in GOPATH mode
We can't assume that we're in module mode when we rebuild the imports
cache. (This is a long standing bug, but I suspect it was made more
common by my recent CL that refactored this code.)

Fixes golang/go#43544.

Change-Id: Ie35c43e6b6e496bd2fbf49cf9bf06c28cf1dab80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/282113
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-01-07 18:21:03 +00:00
Rebecca Stambler 6f6e4b659e internal/lsp/cache: fix module paths in nested module error messages
The existing test didn't catch it because it doesn't look for specific
warning messages.

Change-Id: I1ec7f7a75c1055c960cdd7545331c2fd655e3aa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/281860
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2021-01-06 21:48:47 +00:00
Rebecca Stambler 92778473c2 all: add copyright notices to files that are missing them
This was generated using this script:
https://play.golang.org/p/Nbo3qsk1ADH.

Change-Id: I94ab794b0874ad74a09bba5b3bb29d2c487a491b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/281853
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-01-06 17:23:47 +00:00
Rebecca Stambler 5d65579003 go/packages: remove -mod, -modfile flags from build flags for go version
Use provided build flags may include -mod or -modfile, and these should
be removed before any go command calls that don't accept them.

Fixes golang/go#43418

Change-Id: Ie96626bced5093c67fc1890533f1f8cc03d42c80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280694
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-01-05 21:02:02 +00:00
Pontus Leitzler b8e0803c79 internal/lsp/source: return all field funcs from outgoing callhierarchy
Outgoing callhierarchy didn't handle different functions defined as
field in a struct as separate functions since they were declared by the
same AST node.

This change adds the identifier name to the key, so that a function
must share both declaration node and name to be considered "the same".

Fixes golang/go#43456

Change-Id: Ifbced98f2e8fc3a303834f7cefbae66829b68d27
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280618
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-05 17:25:16 +00:00
Rob Findley 2e889ff48d gopls/internal/regtest: support multiple workspace folders
This change both simplifies the options used to configure workspace
folders in regtests, and allows for configuring multiple workspace
folders. The WithoutWorkspaceFolders, RootPath, and NestWorkdir options
are all replaced by a single WorkspaceFolders option.

NestWorkdir was always a bit too magical, modifying the execution
directory within the runner itself. Instead, just explicitly move files
down into a nested directory.

runModfileTests was also a bit too much of a special case. Eliminate it
by adding functionality to run multiple times with different options.
Upon the way I started using literals to configure runs, and I think
this is cleaner. Let me know what you think about runMultiple, etc.
This overlaps with the execution modes, which could probably be
eliminated in a later CL.

For golang/go#42111

Change-Id: I56915d8930bc47561cc827b918621cff4b994226
Reviewed-on: https://go-review.googlesource.com/c/tools/+/276975
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-01-05 15:40:28 +00:00
pohzipohzi 2993f551b7 internal/lsp: avoid panic during interface assertion
This change fixes a panic in the non-standard request.

Fixes golang/go#43462

Change-Id: I216a56f96ca6159cb9b102183ba3a3eddd186889
GitHub-Last-Rev: 992e818f8a57112b436b831a96b6a9a4fcfa7355
GitHub-Pull-Request: golang/tools#265
Reviewed-on: https://go-review.googlesource.com/c/tools/+/281092
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
2021-01-02 18:51:54 +00:00
Rebecca Stambler 9ca8607e69 internal/lsp: save all possible keys for analyses, codelenses
The possible keys for analyses and codelenses are too long to enumerate
in settings, and we'd need to create enums for all possible analyzer
and code lens names, which is probably not feasible. Instead, collect
the list of possible values from the analyzers and command settings
generation and add them to enum values.

Also, handle default values by setting them in the enum keys instead of
one big default value. Quite a few hacks to get this right, but maybe
there are other better alternatives we can consider in the future.

Fixes golang/go#42961

Change-Id: I5c096862b5e8fb89fe5d6639b4f46c06492e49c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280355
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2020-12-30 22:05:20 +00:00
Rebecca Stambler d2d86cca02 internal/lsp: restructure user options (CL 278433 continued)
This CL copies Heschi's structural changes to the options from CL 278433
and makes the necessary adjustments in the JSON and documentation
generation. Nested settings are grouped together and the "status" of a
given setting is also listed. Currently the only possible statuses are
"experimental" and "debug", but I will add "advanced" in a follow-up (to
indicate that a setting is only for advanced users).

The options "set" function still expects flattened settings to avoid
fundamentally changing people's current configurations, so VS Code Go
will just have to make sure to flatten the settings before sending them
to gopls (which should be easy enough).

No names of any settings are changed (Heschi's earlier CL adjusted the
experimental prefixes). As discussed offline, we've decided to prefix
any setting that we expect to delete with "experimental", and so we'll
leave existing setting names as they are.

Updates golang/go#43101

Change-Id: I55cf7ef09ce7b5b1f8af06fcadb4ba2a44ec9b17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280192
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2020-12-30 21:54:22 +00:00
Rob Findley ef3185ba9c internal/lsp/cache: add a check for snapshot invariants
Check that some invariants are met when cloning the snapshot, in an
attempt to catch golang/go#43347

For golang/go#43347

Change-Id: I7404509027a1b0b0085133cba4d21d1006a52a57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280698
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-30 15:44:40 +00:00
Matheus Alcantara b8413747bb internal/lsp: fix autocomplete appends on imports
Autocompleting a import without quotes appends to the completion,
producing this result: `import math "math/"`.
This commit changes to skip completions when typing a import without
quotes, because the users can be typing the alias of the import.

Fixes: golang/go#42748

Change-Id: I7050989f1f90a6720c17f71f338e50fad1f01456
GitHub-Last-Rev: e7b189a04acd8e501d6d7ac944d25de19156d0da
GitHub-Pull-Request: golang/tools#263
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280652
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-12-29 22:18:35 +00:00
Rebecca Stambler 929a8494cf internal/lsp: restructure the way we report critical errors
The fragmentation of the critical error reporting is getting in the way
of small fixes. This change adds a GetCriticalError function that reports
critical errors, while ModTidy and WorkspacePackages no longer report
critical errors. Any function that wants to process critical errors
should call AwaitLoaded.

Some other smaller changes are made to account for these changes. One
change is that we may report multiple *source.Errors, with the
assumption that duplicate diagnostics will be caught by the diagnostic
caching. Also, any `go list` error message that ends with "to add it" is
now considered an error that gets the "add dependency" suggested fix.

Fixes golang/go#43338
Fixes golang/go#43307

Change-Id: I056b32e0a0495d9a1dcc64f9f5103649a6102645
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280093
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-29 01:39:31 +00:00
Rebecca Stambler fbbba25c5f gopls/doc: generate documentation for analyzers
Analyzers are configured in the internal/lsp/source/options.go file as
well as settings, and we can generate documentation for them without
even using reflection. We add documentaton for each analyzer and list
whether or not it is enabled by default.

Change-Id: If0ffcd422f3f4a99ca3645c35197925ea1cc1616
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280352
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2020-12-29 01:23:49 +00:00
Rebecca Stambler 84d76fe320 internal/lsp: fix unimported completions with -mod=readonly
When -mod=readonly and GOPROXY=off are set, the newly imported package
is not type-checked with the new import until it is reflected in the
go.mod file. In such cases, we can continue treating the package as
unimported and get symbols through unimported completions.

Fixes golang/go#43339

Change-Id: I864c2c6738b537093c0670a266e9030af33f2d36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280095
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2020-12-28 20:48:37 +00:00
Eric Chiang 13ff2212a5 internal/lsp/cmd: include new name in rename help message
"gopls rename" appears to require a new name as a positional argument
but the command line help message doesn't include it. Update the help
message.

Change-Id: Iea769d2095b0642ebbacce128da336ec0dc56828
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280472
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-28 17:52:27 +00:00
Rebecca Stambler 34cd474b99 internal/lsp: use an enum for GC annotations settings
The annotations map should use an enum to indicate expected values. For
now, we reuse the EnumValues to expose the information in the settings.
Later, we'll create a separate EnumKeys field to expose this information
more correctly.

Also, adjust some of the logic that applies the settings because it was
incorrect.

Both gopls/doc/settings.md and internal/lsp/source/api_json.go are
generated files.

Updates golang/go#42961

Change-Id: Ifb032b70caaae73defe9a540df20d098d313e68e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280354
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-12-28 16:22:55 +00:00
Pontus Leitzler b1c90890d2 internal/lsp/source: do not panic in "var func" outgoing callhierarchy
When trying to get outgoing call hierarchy from an var func like:

func main() {
    foo := func() {}
    foo()
}

gopls crashed with a panic.

This change makes it return an empty call hierarchy instead.
It also adds support for testing outgoing calls where the expected
result is 0 items, to be able to test this change.

Fixes golang/go#43376

Change-Id: Icd91bf54cb4fbd5203f5865f0ff9d81365c27d5d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279469
Trust: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-26 21:56:59 +00:00
Rebecca Stambler 2b0845dc78 gopls/release: add a command to validate the gopls release process
The gopls release process has a number of steps which can be easily
forgotten, but they are also easy enough to check. In the future, we can
certainly automate this process further, but this basic program will
validate that mistakes like golang/go#43256 are not made again in the
future.

Change-Id: I04641ae202bc6615f2e4c8810b5dab4885d37fd4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279715
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-24 04:30:29 +00:00
Rebecca Stambler 57089f8fd7 internal/lsp: remove dependencies using text edits when necessary
golang/go#43335 explains the issues with using `go get module@none`,
which will only be resolved in Go 1.17. In the meantime, we use the
go command whenever possible, but if the module is not tidied, we
have to use textual edits instead. This means the go.sum file will not
be accurately updated to remove the dependency, but unfortunately, I
don't believe there is anything that we can do in that case.

Fixes golang/go#43335

Change-Id: I771f68f34a6136e73e9dd82b692ed4c235c3b293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279716
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-24 00:32:54 +00:00
Matheus Alcantara 834755c7db internal/lsp: add tests to set configuration options
Added some tests to hoverKind, matcher, env and directoryFilters
of configuration options.

I'm also add a validation on `env`configuration, to initialize the map if is nil to avoid the risk of inserting the values in a nil map. Please let me know if this validation is unnecessary.

Fixes golang/go#34244

Change-Id: I387ad0a393d981d070002c7e3736acad7b2191bf
GitHub-Last-Rev: 4fe354754323471f3260f990a264807525b3571b
GitHub-Pull-Request: golang/tools#261
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278072
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-23 23:03:58 +00:00
Rob Findley bdbb3c917f internal/lsp/cache: only reload the workspace on saved changes
Invalidating the workspace on any change to a go.mod can render a
workspace unusable. Only invalidate when changes are saved.

Additionally, invalidate the workspace if there is a saved change to
tracked go.sum changes.

Fixes golang/go#42529
Fixes golang/go#42815

Change-Id: I5d903013b33b932eca4998513e3d0a534b2e5a61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279720
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-23 22:53:30 +00:00
Rob Findley f6952e403d internal/lsp/cache: fix some package event tags
Package.ID() is far more useful to tag on events, as it disambiguates
multiple packages with the same path.

Change-Id: I03fd69f64641eb17155ca72ed2ef19641b75f004
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279722
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-23 20:03:49 +00:00
Ainar Garipov 9cbb1efa77 internal/lsp/source: add the shadow analyzer
Fixes golang/go#43245

Change-Id: I4b51d8bfcb815c29339754637114558c62b0f6bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279395
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-12-23 17:49:54 +00:00
Peter Weinbergr f2e330f490 gopls/test: add type checking for debug server templates
When internal data structures in gopls changed, the templates driving
the debug server failed because fields or methods they relied on
had gone away. At some cost, this change adds tests that all the
fields and methods in the templates can be satisfied.

The test assumes that all the template uses are through render() in
debug/serve.go. It checks that is list of templates is the same
as the server's, and then type checks each template.

The costs are
1. the template type checking is done by a new external dependency,
github.com/jba/templatecheck
2. To avoid adding a new dependency to x/tools, the test is in
the gopls module, not the debug package, so variables from the
debug package have to be exported

In an ideal world the debug package, and much of internal/lsp,
would be in the gopls package. In that case the cost 2 about could
be avoided.

In an ideal world, the core runtime template packages would
contain template checking code, and cost 1 would be unnecessary.
In a more likely (or not so distant) world, perhaps jba would move
(or allow us to move) the template check package into x/tools.

Change-Id: I36b509a00cbdcb5323ee1af3c1193b603c7a907f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/277292
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-12-22 16:32:15 +00:00
Rebecca Stambler 1965356128 internal/lsp/mod: fix misplaced code lens with individual requires
If there is no require block, we were misplacing the Upgrade code
lenses.

Change-Id: Ic7ea5f254747bc1e1fc8aa42d0facc52702b745b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279172
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-21 20:10:19 +00:00
Rebecca Stambler b57d1c5b4a internal/lsp: return an error if code action has no title
Hopefully this will prevent missing titles in the future. Confirmed this
works by removing an existing title.

Change-Id: Id8c7fa2eaffd043b5c66976d945376d6558f75bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279173
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-21 19:58:07 +00:00
Rebecca Stambler ae774e9781 internal/lsp: don't show duplicate diagnostics for go.mod errors
We were getting duplicate diagnostics for certain mod tidy diagnostics.
The correct fix is to separate out the generation of such diagnostics
so that duplicates don't occur, but for now, this is the simplest fix.
I wanted to add a test, but my repro case involves `go clean -modcache`
and checking that a version cannot be downloaded, which doesn't work
with the file-based GOPROXY. I will probably have a CL at some point
that cleans up the way these diagnostics are produced.

Change-Id: I542648b4eae7aced15f720db6233c852879f2a26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278917
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-18 02:47:24 +00:00
Rebecca Stambler 5b06639e57 internal/lsp/source: only show "run file benchmarks" if available
We were previously showing them even if there were no benchmarks to run.

Fixes golang/go#43239

Change-Id: I51d1de12e86009cca6d8ea41208949ed01484f6a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278780
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-17 23:51:54 +00:00
Rebecca Stambler 008e477491 internal/lsp, gopls: recover from go-diff panics
This CL handles the panic in the sergi/go-diff library which has not
yet been resolved. We add an error return to the ComputeEdits function
and return an error if there is a panic. I'm not sure if this is the
best approach, but it does seem better than allowing the server to
crash.

A concern would be that the user wouldn't know why their code wasn't
being formatted, but hopefully they might look through the logs and
notice the error message. At least, other features would continue
working. The best fix will definitely be the fix for the panic, but that
is not yet available.

Threading through the error return was not pretty, but I thought it was
probably worth doing since it could be needed in other situations.

Updates golang/go#42927

Change-Id: I7f0c05eb296ef9e93b4de8ef071301cdb9dce152
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278775
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-12-17 16:56:54 +00:00
Rebecca Stambler 48e5bd1105 internal/lsp: add titles to `go mod tidy` and update go.sum fixes
These were missing titles, which was showing up empty for users in the
VS Code UI and leading people not to trust the fixes.

Also did a find references on SuggestedFix to confirm that we always
set the title in other cases.

Fixes golang/go#43234

Change-Id: I8d0f272c383a2e1a364aefcec6650988d18d4fb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278778
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-17 16:18:45 +00:00
Hana fa10ef0b87 internal/lsp/source: update codelenses example
And regenerate docs and api_json.go

Change-Id: I7504c5257893617adcc0b657b61feb3cdb235061
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278356
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-15 19:20:05 +00:00
Rob Findley d93e913c1a internal/lsp/debug: hook runtime/trace into event spans
Existing spans defined within gopls are leveraged to add runtime/trace
tasks, regions, and logging.

This made it easier to understand gopls' execution, though we still have
relatively sparse logging (arguably because we're conscious of the fact
that logs are reflected back to the LSP client). Add a new log package
with the concept of log level to facilitate excluding trace logs from
the LSP.

Add a little bit of additional instrumentation to demonstrate the usage
of the new package.

Change-Id: Id337be806484201103e30bfe2c8c62c7d7c363c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275252
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-12-11 18:50:31 +00:00