Commit Graph

6753 Commits

Author SHA1 Message Date
Alan Donovan b3851a823f internal/lsp/cache: tweaks to metadata graph
- ignore error from buildPackageHandle, with rationale.
- remove unnessary optimization in call to Clone(updates={}):
  Clone does the same check internally.
- more comments.

Change-Id: I4551cf560aea722d972fb6da404aed71a79f4037
Reviewed-on: https://go-review.googlesource.com/c/tools/+/416217
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-08-16 01:59:44 +00:00
Robert Findley 938e162bcf gopls/internal/regtest: unskip TestDeleteModule_Interdependent
Reloading has been significantly refactored recently. Unskip this test
to see if it flakes:
 - If it does not flake, that is a useful signal.
 - If it does flake, that is also a useful signal.

Notably, following CL 419500 we allow network when reloading the
workspace, and so do not need to apply quick-fixes in order to download
the new module from the proxy.

For golang/go#46375
For golang/go#53878

Change-Id: Idde7195730c32bdb434a26b28aac82649dd1b5ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422910
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-15 20:02:31 +00:00
Rob Findley e8507bed92 gopls/internal/regtest/bench: replace -gopls_version with -gopls_commit
The go command can't always resolve arbitrary commits as versions, and
some commits have an x/tools replace directive that must be honored, so
use 'git clone' with an arbitrary commit ref, instead of 'go install'
with a Go module version, to install gopls.

Also rename BenchmarkIWL to BenchmarkInitialWorkspaceLoad.

For golang/go#53538

Change-Id: Ic3a08e4c023e0292f6595cc5b2ab59954d073546
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422908
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-15 19:50:52 +00:00
Robert Findley 8c830569a8 gopls/internal/regtest: unskip TestSumUpdateFixesDiagnostics
Metadata reloading has been significantly refactored recently. Unskip
this test to see if it still flakes.

For golang/go#51352
For golang/go#53878

Change-Id: I9f2ae1835bbace1b5095c2d45db082c4e709437b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/423974
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-08-15 18:38:24 +00:00
Robert Findley 987de349f4 internal/lsp/completion: don't use Type.String for checking identity
Completion is very performance sensitive, and building a string to check
for *testing.F has a significant cost.

StructCompletion-8         20.7ms ±14%  16.8ms ± 1%  -18.59%  (p=0.000 n=10+10)
ImportCompletion-8         1.36ms ± 5%  1.05ms ±18%  -22.55%  (p=0.000 n=9+10)
SliceCompletion-8          23.5ms ± 2%  19.3ms ±18%  -17.85%  (p=0.000 n=7+10)
FuncDeepCompletion-8       17.6ms ± 2%  15.5ms ± 2%  -11.82%  (p=0.000 n=8+8)
CompletionFollowingEdit-8  81.2ms ± 8%  74.2ms ± 5%   -8.60%  (p=0.000 n=9+9)

For golang/go#53992
For golang/go#53798

Change-Id: Ia138cbadce142a424caabe8259bda05bcc536055
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422906
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-08-15 17:37:01 +00:00
Robert Findley 5a26068387 internal/lsp/source: remove utm_source from pkgsite links
This query parameter is not needed.

Change-Id: Id45d7be0b1cbe5d383bcc6768ef20df26de3e7b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422901
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-08-15 16:22:50 +00:00
Leonardo Henrique 35f806b175 gopls/doc/workspace: correct grammar
Fixed double "the the".

Change-Id: Id431cdb2eaf1452453047818393324a30e21f971
GitHub-Last-Rev: 20c8438eeb504ac6b92e49e73a2acd2a97fe930e
GitHub-Pull-Request: golang/tools#380
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402236
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-12 22:57:26 +00:00
Robert Findley bebd890374 go/analysis: remove stray print statement in the timeformat analyzer
A debugging print statement was left in the analyzer, which breaks
gopls' communication over stdin/stdout.

Fix this, and add tests.

Fixes golang/vscode-go#2406

Change-Id: I1b785fa09e66eae2f1b1e03806e5b59d2015e75e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422902
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-08-12 17:40:51 +00:00
Michael Stapelberg 88d981ef8f printf analyzer: link to fmt#Printing for verb/type docs
Folks are reporting the current error message as not useful,
remarking that they don’t know which formatting verb goes with
which Go type, see e.g. b/227741360.

Change-Id: I367bc8c4df3521f0726dc4defa4e563532706148
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422854
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-12 12:39:26 +00:00
David Chase c4ec74a5c9 go/internal/pkgbits: fix performance of rawReloc
Tracking changes in go repo for unified IR.

See CL 422297.

Change-Id: If05aba7693c70cac4969721e5dd8a5bf197670b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422899
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-11 18:06:33 +00:00
Suzy Mueller 37a81b68a0 internal/lsp: add unnecessary tags for unused vars and imports
Diagnostic Tags add another hint for the client for how to
display diagnostics. The Unnecessary tags allows clients to
fade out the diagnostic instead of adding a squiggle. This adds
this tag to unused import errors as well as unused vars.

For golang/vscode-go#2285

Change-Id: I0c93b28a6a2ef4eed314dcf30a37c27dd65940ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/415499
Reviewed-by: Robert Findley <rfindley@google.com>
2022-08-11 16:19:14 +00:00
Robert Findley 3807419523 internal/lsp/cache: validate the range for critical errors in go files
This avoids the panic reported in golang/go#54395.

Fixes golang/go#54395

Change-Id: Ief35985a503d3cc13971499dc6f4e9c1d1d63ea3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422894
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-08-11 13:46:09 +00:00
Robert Findley b2156b5c9a gopls: update dependencies
Update all dependencies, except sergi/go-diff.

Fixes golang/go#54294

Change-Id: I4f60a7563bf214a76594fef3f566c714fb59133c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422655
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-10 20:19:59 +00:00
Robert Findley 0ad49fdeb9 internal/imports: update stdlib index for 1.19
Updates golang/go#38706

Change-Id: I361c8862b4dcd5215ea0574715908f552f937e6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422654
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-10 17:41:25 +00:00
Robert Findley 3950865150 gopls/internal/regtest/bench: add a -gopls_version flag
To facilitate testing specific gopls versions, add a -gopls_version flag
that installs and uses a specified gopls version.

Also fix a bug in the DidChange benchmark that causes it to be
inaccurate when the benchmark function is invoked multiple times (by the
benchmark runner or via -count): because the server environment is
shared across invocations, we can't use the benchmark iteration to
derive the expected number of changes: we must use our count of actual
DidChange notifications from the server.

Change-Id: I1ad733cb3e695d382e81dfb7e31346162d9b7635
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422368
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nooras Saba‎ <saba@golang.org>
2022-08-10 15:08:24 +00:00
Dylan Le 6fa767d87c internal/lsp: update documentation for directoryFilters setting and default value
Add `**` usage to directoryFilters documentation. Change directoryFilters default value to `-**/node_modules`

For golang/go#46438

Change-Id: I3ea14ad8a20893d19df4cf8d584a7c7f9b213aab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422356
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-08-09 20:31:19 +00:00
Robert Findley 96d05aa120 gopls/internal/regtest: fix TestFailingDiagnosticClearingOnEdit
This test was asserting immediately on the non-presence of published
diagnostics, and therefore was racing with the diagnostics calculation
pass. Following https://go.dev/cl/420539 this became a flake, because
once gopls has calculated diagnostics for the open event, it will
actually publish empty diagnostics for the opened file.

Update the test to use a OnceMet so that we only evaluate the
expectation once we've finished the diagnostics pass. As a result, the
test deterministically failed, which was fixed by using the
EmptyOrNoDiagnostics expectation.

Fixes golang/go#54271

Change-Id: Id3f220ce44c7996132699a724b6c627f034e367f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/422136
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-09 15:36:31 +00:00
Antoine Cotten 4ff08b4044 gopls: Improve auto-imports example for NeoVim LSP
Follow Lua Style Guide for function names.

Query the client's offset encoding, with a fallback to utf-16.

Omit handling of r.command since the source.organizeImports code action
doesn't return any.

Omit passing a value for wait_ms. It is optional and defaults to 1000
(see NeoVim help for vim.lsp.buf_request_sync).

Change-Id: I5e5eb6cee3a46fee1edc1e6d15b40ad88498a26c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421295
Reviewed-by: Dylan Le <dungtuanle@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2022-08-09 15:21:58 +00:00
Robert Findley 92d58ea4e7 internal/lsp/cache: register a file watcher for explicit GOWORK values
When the go.work file is set by the GOWORK environment variable, we must
create an additional file watching pattern.

Fixes golang/go#53631

Change-Id: I2d78c5a9ee8a71551d5274db7eb4e6c623d8db74
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421501
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-08-08 18:11:08 +00:00
Robert Findley 98aef77998 internal/lsp/cache: track explicit go.work files outside the workspace
In order to correctly process changes to the go.work file, the workspace
must know about GOWORK settings configured in the users environment.
Compute this when initializing the view, and thread this through to the
workspace.

At this point, workspace information is spread around in a few places.
Add some TODOs to clean this up.

Also remove some module data that was not used in
TestBrokenWorkspace_DuplicateModules.

Updates golang/go#53631

Change-Id: Ie0577d702c8a229304387bc7fe53a8befb544acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421500
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-08 18:11:01 +00:00
Robert Findley fff6d6d39f internal/lsp: update the broken workspace message to mention go.work
For users of Go >= 1.18, update the error message presented to users
with broken workspaces to suggest using a go.work. For older Go
versions, suggest updating to 1.18+.

Also:
- add support for changing workspace folders from the fake editor
- update the test to confirm that changing workspace folders resolves
  the error message
- inline validBuildConfiguration, and make a few TODOs for how the code
  could be further cleaned up

Fixes golang/go#53882

Change-Id: Ia03dcfec59569b1a3ac941dc40d079b9c2593825
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421499
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Dylan Le <dungtuanle@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-08-08 18:10:56 +00:00
Robert Findley 9b60852425 gopls/internal/regtest: move TestMultipleModules_Warning to ./workspace
This test is really about workspace setup, not diagnostics. Move it
in advance of changes to this feature.

Pure code move, no other changes.

Change-Id: Ib78f1fe5ce701673f5aa071f399da11f208874df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421498
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-08-08 15:48:44 +00:00
Robert Findley 06d96ee8fc gopls/internal/regtest/bench: add a test for completion following edits
For golang/go#53992

Change-Id: Ia1f1e27663992707eef9226273b152117ee977ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420220
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-08-05 17:04:18 +00:00
Hana (Hyang-Ah) Kim 81c7dc4e4e internal/lsp: polish vulncheck progress messages
gopls.run_vulncheck_exp runs `gopls vulncheck`
(fork of govulncheck) and pipes its stderr (logs)
as progress messages. The default log format
includes timestamp and that is too long for progress
message. Tell gopls vulncheck to omit timestamp
in the log message.

Use "govulncheck" as the progress message prefix,
instead of the long "Checking vulnerabilities".

Change-Id: I92fe9958b20d0260711a42af9b5f9f399e267587
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420998
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-04 20:05:03 +00:00
Hana (Hyang-Ah) Kim af2a0a8167 internal/lsp: use exec.CommandContext when running vulncheck
That, hopefully, handles process termination upon context
cancellation. (not 100% guaranteed)

Change-Id: I79441afb794c37e9e55f710f124871a82aa4effe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420997
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-04 20:04:51 +00:00
Hana (Hyang-Ah) Kim 3519aa25b8 internal/lsp/cmd: remove unused Env from pkgLoadConfig
Instead rely on the process env vars the `gopls vulncheck`
command runs with.

Change-Id: I313a035d9bb7dbbdf2199474e0864cdb591e15ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420996
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-04 20:04:16 +00:00
Hana (Hyang-Ah) Kim 6c27717f2a internal/lsp/mod/code_lens: add "run govulncheck" codelens
And, make gopls.run_vulncheck_exp show an information/error
message popup after a successful run. This is temporary.
We plan to publish the results as diagnostics and quick-fix.

Finally, changed the stdlib vulnerability info id in
testdata to GO-0000-0001 which looks more like a vulnerability
ID than STD.

Changed TestRunVulncheckExp to include tests on codelens
and use the command included in the codelens, instead of
directly calling the gopls.run_vulncheck_exp command.

Change-Id: Iaf91e4e61b2dfc1e050b887946a69efd3e3785b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420995
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-04 20:03:56 +00:00
Robert Findley 763f65c3d2 gopls/internal/regtest/misc: simplify shared edit tests
In order to avoid shutdown races we must always close the second editor
created for simultaneous edit tests.

Rather than introduce additional indirection, just merge the two tests
into one.

For golang/go#54241

Change-Id: I6604141baa77d07f6281d3a90efa13c02b94079a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421258
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-04 19:57:25 +00:00
David Chase fc3b24a456 go/internal/gcimporter: rewrite interface receiver parameters
Tracking changes in go repo for unified IR.

See CL 421355.

Change-Id: Idc0d2afeb6f2241f3608cbdb0fbc128f8755ec55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421255
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-08-04 19:12:52 +00:00
Hana (Hyang-Ah) Kim b5fd08821a internal/lsp/command: replace VulncheckArgs Dir with URI
commandHandler.run expects a valid file for forURI and
forURI is necessary to fully populate commandDeps.
Our use of directory URI does not work.

We plan to use this custom command triggered through
codelenses on documents (e.g. go.mod), so we use
the document's URI.

Change-Id: I4de6d488dec5a4b71716499e7fc5e8328ecf3e49
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420994
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-08-04 18:58:55 +00:00
Robert Findley 99fd76f9c0 internal/lsp/cache: delete KnownMetadata.PkgFilesChanged
It is no longer needed, now that we don't consider invalid packages to
be workspace packages.

Change-Id: I6155a2609ab07046b9507dc04717eea7b974f1b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421257
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-08-04 18:51:46 +00:00
Robert Findley 01c9ff0536 internal/lsp/cache: invalid packages should not be workspace packages
To support the experimentalUseInvalidMetadata mode, we keep around
invalid metadata. This can help gopls features work when, for example,
the go.mod file is broken. It is debatable whether this feature is worth
supporting (see golang/go#54180), but in the meantime there is a very
negative side-effect when module paths are changed in the go.mod file:
we keep around a bunch of workspace packages with a stale module path.
As a result we can be left with a lots of extra type-checked packages
in memory, and many inaccurate diagnostics.

Fix this by skipping packages with invalid metadata when computing
workspace packages. While we may want to use invalid metadata when
finding the best package for a file, it does not make sense to re-
type-check and diagnose all those stale packages.

Fixes golang/go#43186

Change-Id: Id73b47ea138ec80a9de63b03dae41d4e509b8d5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420956
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-04 18:51:19 +00:00
pjw bd68922a85 internal/lsp: new options to disable certain kinds of semantic tokens
Semantic tokens, as defined by the LSP, have no way of marking parts of
strings or numbers, for instance, to emphasize escape character. But
if gopls returns no semantic tokens for strings, then the editor
will use its coloring for strings, which may be more useful (and
similarly for components of numbers).

This change introduces boolean flags noSemanticString and
noSemanticNumber that can be set to true to suppress the semantic
token and let the editor's formatting shine through.

Fixes: Fixes golang/go#45753

Change-Id: Ibae880a08fb9a67daa73aa172375a1c949431e11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/421256
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
2022-08-04 18:30:35 +00:00
Hana (Hyang-Ah) Kim bceee4b059 internal/lsp/command: let RunVulncheckExp call gopls vulncheck
By making gopls.run_vulncheck_exp (RunVulncheckExp implements)
call `gopls vulncheck`, we achieve

  - gopls.run_vulncheck_exp can run asynchronously and be cancellable
  - log information can be forwarded as progress messages
  - isolate any failures during vulncheck execution

In this CL, we also changed not to include test files in the analysis
(match the default of govulncheck). We will add an option in the future.

TODO:
 - prevent concurrent gopls.run_vulncheck_exp
 - convert the gopls vulncheck output to diagnostics and publish it
 - remove timestamps from the `gopls vulncheck` log messages
   for simplify progress messages
 - add test to check vulnerability in third-party dependencies

Change-Id: I21592e03794cd9e9d96ed3989973a2ab7d75c538
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420717
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-04 18:21:12 +00:00
Robert Findley 3e0a5031e3 internal/lsp: use directoryFilters in import scanning
Based on dle8's CL 414454, wire in directoryFilters into the goimports
ModuleResolver scan. A few changes/fixes/additions from that CL:

- Fix a bug in filter validation that was causing -**/a not to validate.
- Fix a bug in regex building where -a was not treated as an excluded
  prefix (it was matching 'a' anywhere).
- Use absolute paths in the SkipPathInScan, so that we can evaluate
  directory filters relative to the workspace folder.
- Add several regression tests.
- Consolidate directoryFilters regression tests under a new
  directoryfilters_test.go file.
- Add several TODOs.

Fixes golang/go#46438

Change-Id: I55cd3d6410905216cc8cfbdf528f301d67c2bbac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420959
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Le <dungtuanle@google.com>
2022-08-04 15:50:11 +00:00
Robert Findley 87f47bbfb4 gopls/internal/regtest/bench: refactor and improve benchmarks
Significantly refactor the gopls benchmarks to turn them into proper
benchmarks, eliminate the need for passing flags, and allow running them
on external gopls processes so that they may be used to test older gopls
versions.

Doing this required decoupling the benchmarks themselves from the
regtest.Runner. Instead, they just create their own regtest.Env to use
for scripting operations. In order to facilitate this, I tried to
redefine Env as a convenience wrapper around other primitives.

By using a separate environment setup for benchmarks, I was able to
eliminate a lot of regtest.Options that existed only to prevent the
regtest runner from adding instrumentation that would affect
benchmarking. This also helped clean up Runner.Run somewhat, though it
is still too complicated.

Also eliminate the unused AnyDiagnosticAtCurrentVersion, and make a few
other TODOs about future cleanup.

For golang/go#53992
For golang/go#53538

Change-Id: Idbf923178d4256900c3c05bc8999c0c9839a3c07
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419988
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-04 14:58:59 +00:00
Zvonimir Pavlinovic 8b9a1fbdf5 go/callgraph/vta: do not assume that recovers cannot be deferred
Otherwise, one has a panic.

Change-Id: I850d99ad373ac877bfbc2a8c2ef0c8ac98992dff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420914
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-08-03 21:02:27 +00:00
Erik Dubbelboer 371fc67d3b go/tools: add check for time formats with 2006-02-01
yyyy-dd-mm is a time format that isn't really used anywhere [1]. It is
much more likely that the user intended to use yyyy-mm-dd instead and
made a mistake. This happens quite often [2] because of the unusual way
to handle time formatting and parsing in Go. Since the mistake is Go
specific and happens so often a vet check will be useful.

1. https://stackoverflow.com/questions/2254014/are-there-locales-or-common-programs-that-use-yyyy-dd-mm-as-the-date-format
2. https://github.com/search?l=&p=1&q=%222006-02-01%22+language%3AGo&type=Code

Updates golang/go#48801

Change-Id: I20960c93710766f20a7df90873bff960dea41b28
GitHub-Last-Rev: 496b9917b5eda0525cb75d04a3487d174ccf8fea
GitHub-Pull-Request: golang/tools#342
Reviewed-on: https://go-review.googlesource.com/c/tools/+/354010
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-08-03 20:00:23 +00:00
Robert Findley d08f5dc9fb gopls/internal/regtest: unskip all of TestModFileModification
I believe the races described in the issue have been fixed: we should
invalidate mod tidy results on any metadata change. If this invalidation
doesn't work due to a race, we want to know about it.

Update the test to wait for file-related events to complete before
removing files, in an attempt to avoid windows file-locking issues.

For golang/go#40269
For golang/go#53878

Change-Id: I91f0cb4969851010b34904a0b78ab9bd2808f92e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420718
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-08-03 18:07:40 +00:00
Robert Findley ddb90ecd31 internal/lsp/cache: fix data races to view.options
Use the concurrency-safe view.Options method.

Fixes golang/go#54214

Change-Id: If75a544ae477ee7361540c3933a18e3366d8ffd7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420954
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dylan Le <dungtuanle@google.com>
2022-08-03 12:09:24 +00:00
Robert Findley 0d04f65da9 internal/lsp: re-send diagnostics on file events
Fix golang/go#50267 by ensuring that diagnostics are re-sent following
didOpen or didClose events. Additionally, introduce a new hidden
'chattyDiagnostics' option that causes diagnostics to be resent on
*every* file change event. This latter option is for LSP clients that
get confused when diagnostics are not re-sent for later file versions.
For now, be conservative and only force diagnostic publication on
didOpen and didClose.

Update tests whose 'NoDiagnostics' assertions were broken by the new
behavior.

Fixes golang/go#50267

Change-Id: I6332d66a1851e0d8261599d37020a03b4c598f7d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420539
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-02 18:52:36 +00:00
Robert Findley d025cced83 internal/lsp/source: don't crash requesting gc_details for an empty file
Requesting gc_details for an empty file never worked, but in the past it
would inadvertently get handled by our forgiving position helpers. With
https://go.dev/cl/409935, it became a crasher.

Fix the crash by adding handling when the package name position is
invalid.

Also move gc_details related codelens to their own file.

Fixes golang/go#54199

Change-Id: I7339b3903abd1315f1fea3dd9929d81855a8264a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420715
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-02 18:19:01 +00:00
Robert Findley 10cb4353f9 internal/lsp/regtest: improvements for shared execution modes
Following up on CL 417587, make several improvements to the regtest
runner related to shared execution modes:

- guard lazily-allocated resources with sync.Once rather than a common
  mutex.
- for simplicity, always set Runner.goplsPath
- start the separate process server synchronously, to ensure that it is
  running before test execution
- cancel the separate process server when the test runner exits
- remove the testing.T argument from server constructors
- close the regtest runner in a deferred function

Tested manually via -enable_gopls_subprocess_tests.

Change-Id: Ide3972a94c129bcce554c10dd167df01c3040d31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419954
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-02 18:16:22 +00:00
Robert Findley 4d0b383458 internal/lsp/regtest: minor cleanup for magic regtest envvar
For some reason, we were not reusing the constant runTestAsGoplsEnvVar
in the regtest Main function. Fix this, add a bit more commentary, and
check the envvar before doing anything else. Also fix the threading of
hooks to the created gopls server.

Tested manually via -enable_gopls_subprocess_tests.

Change-Id: Ieb5329aa5850e845f4d9e3868703bfa16387bce3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420716
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-02 16:05:48 +00:00
Robert Findley 310ea71b71 gopls/internal/regtest: add a test that ignoring a file resolves errors
Add a test that when a user adds a "//go:build ignore" to a file, gopls
correctly invalidates diagnostics.

This used to be broken, but was fixed by CL 417576.

Fixes golang/go#54147

Change-Id: I554fcfc0a56b72f657e19b3c0ae53a66d1a99a76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420537
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-08-02 14:13:40 +00:00
Robert Findley 21861e6be5 gopls/internal/regtest/bench: put feature benchmarks in their own file
Purely for consistent organization. No functional changes.

Change-Id: Id26d55d6496523827c154f8a2a17b3660f6081eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419982
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-08-01 21:40:07 +00:00
David Chase c7f11917cb go/internal/gcimporter: set underlying types in proper order; flatten imports
These are copied from go/internal, for processing
export data from unified IR compilation.

The underlying types order problem appeared in google-internal
testing. If the run-later functions are run in the wrong order,
type definitions won't resolve properly.

Flatten imports makes the unified IR export/import match the
behavior of export data from older compilers, though it's not
clear that this behavior was intended, it is now expected.

See https://go.dev/cl/419996 and https://go.dev/cl/419596

Change-Id: I4197fe9e93ee07eb7f24597ba9157ce083a1d086
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420534
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-08-01 20:48:56 +00:00
Dylan Le bd3f524777 internal/lsp: rename all the package names in the renamed package
This CL contains a partial implementation of package renaming. Currently gopls is only able to rename references to the renaming package within the renaming package itself.

prepareRename is still expected to return an error for renaming a package.

For golang/go#41567

Change-Id: I3683a0a7128bba7620ef30db528f45b753e6c08f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420219
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dylan Le <dungtuanle@google.com>
2022-08-01 17:28:00 +00:00
Robert Findley 9f65685098 internal/lsp/source: enable the new diff with allExperiments
When enabling all experiments (done by VS Code nightly), switch to the
checked version of the new diff implementation.

Also remove some experimental settings that are now on by default.

Updates golang/go#52967

Change-Id: Id272c4a646006a739e49d48f0f09b2f8b0982bab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419981
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-01 13:49:32 +00:00
Dylan Le 9580c84d57 internal/lsp: Check if user's editor support rename operation
Change-Id: Iadda768e93eda1d53fa00a5ff8a28013a575ef57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419774
Run-TryBot: Dylan Le <dungtuanle@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-07-29 20:19:23 +00:00