Commit Graph

806 Commits

Author SHA1 Message Date
Gopher Robot 502c634771 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.
Once this CL is submitted, and post-submit testing succeeds on all
first-class ports across all supported Go versions, this repository
will be tagged with its next minor version.

Change-Id: Ie52140f20343bd6dd2b73662fce64c8065f5a80b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449096
Auto-Submit: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Gopher Robot <gobot@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-09 17:16:50 +00:00
Arsen Musayelyan 3057465037 gopls/doc: Add plugin for Lapce to gopls documentation
Add [Lapce](https://lapce.dev) Go plugin to `gopls` documentation

Change-Id: I58ec42d69708b519cfba3de1cdee269ffecdbbc4
GitHub-Last-Rev: 37762df491e6e7a5797606025357fcfed28be56d
GitHub-Pull-Request: golang/tools#413
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448235
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-09 13:30:16 +00:00
Angus Dippenaar 9474ca31d0 gopls/doc: clarify `go work use`
I felt a bit confused on my first reading of the docs for using `go work`.

It wasn't clear to me if the `tools` argument in `go work use tools tools/gopls` was an alias or a directory name, so I thought this might make it very clear to understand for first time users.

Change-Id: I9c5a04a8928207b53acfb36ce7add8ca5f033d46
GitHub-Last-Rev: 49e125d83e40f06239f3a24c92f16258a25305c3
GitHub-Pull-Request: golang/tools#409
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441415
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-08 17:28:46 +00:00
pjw 50506576b8 gopls/fake: add semantic token modifiers to fake editor
This change will make it possible to do semantic token regtests.

Change-Id: I9963c60f61af30f973a2ee4cd32aaa5545bdc4ec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448296
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-07 18:28:08 +00:00
pjw 88a3548304 gopls/coverage: repair coverage.go
Coverage.go computes the test coverage from running all the gopls tests.

This CL accounts for the changed source tree (internal/lsp is gone)
and new actions returned by go test -json ('pause' and 'cont').

Change-Id: I970b3ec107746ce02e3dcdcad9f8c19cffad8d11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448295
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-07 18:26:12 +00:00
Robert Findley 8e0240af74 internal/regtest/workspace: permanently skip TestDeleteModule_Interdependent
This test is flaky, likely due to some race in the
experimentalWorkspaceModule logic. Since we're about to delete support
for that experimental feature, simply skip the test to stop the flakes.

Leave the test as an artifact, as it will be deleted as part of the
clean up of experimentalWorkspaceModule. No need to delete it before
then.

Updates golang/go#55331
Fixes golang/go#55923

Change-Id: Ic17485e42e335459df462af00a2088812ecfb5f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448116
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-11-07 14:31:53 +00:00
Robert Findley fe725d9349 gopls/internal/regtest: simplify awaiting diagnostics from a change
When awaiting diagnostics, we should almost always wrap expectations in
a OnceMet(precondition, ...), so that tests do not hang indefinitely if
the diagnostic pass completes and the expectations are still not met.

Before this change, the user must be careful to pass in the correct
precondition (or combination of preconditions), else they may be
susceptible to races.

This change adds an AllOf combinator, and uses it to define a new
DoneDiagnosingChanges expectation that waits for all anticipated
diagnostic passes to complete. This should fix the race in
TestUnknownRevision.

We should apply a similar transformation throughout the regression test
suites. To make this easier, add a shorter AfterChange helper that
implements the common pattern.

Fixes golang/go#55070

Change-Id: Ie0e3c4701fba7b1d10de6b43d776562d198ffac9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448115
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-07 14:31:48 +00:00
Robert Findley 39c2fd8bff internal/lsp/cache: simplify importsState modfile hashing logic
While checking for changes to go.mod files in the importsState, there is
no reason for special handling based on workspace mode: we can simply
hash all active modfiles. This moves us towards an improved API for the
workspace: it should simply be responsible for tracking active modfiles.

This also incidentally avoids the panic reported in golang/go#55837.

Fixes golang/go#55837

Change-Id: I8cb345d1689be12382683186afe3f9addb19d467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447956
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 18:06:00 +00:00
Robert Findley ec044b1a47 gopls: update dependencies following the v0.10.0 release
Update selected dependencies following the v0.10.0 release, excluding
sergi/go-diff and x/vuln.

Gofumpt@v0.4.0 requires go1.18, so link it selectively following the
pattern of staticcheck. While at it, clean up some things related to the
wiring of staticcheck and gofumpt support. Notably, in VS Code error
messages do not support formatting such as newlines or tabs.

Add a test for the conditional Gofumpt support.

For golang/go#56211

Change-Id: Id09fdcc30ad83c0ace11b0dea9a5556a6461d552
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446736
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 16:52:27 +00:00
Alan Donovan 2b29c66d7e internal/gcimporter: API for shallow export data
This change adds an internal API for marshalling and
unmarshalling a types.Package to "shallow" export data,
which does not index packages other than the main one.
The import function accepts a function that loads symbols
on demand (e.g. by recursively reading export data for
indirect dependencies).

The CL includes a test that the entire standard
library can be type-checked using shallow data.

Also:
- break dependency on go/ast.
- narrow the name and type of qualifiedObject.
- add (test) dependency on errgroup, and tidy go.mod.

Change-Id: I92d31efd343cf5dd6fca6d7b918a23749e2d1e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447737
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-04 16:27:25 +00:00
Hana (Hyang-Ah) Kim a77a1fb995 gopls/internal/lsp/mod: fix vulncheck hover message
This fixes multi-paragraph vulnerability description rendering.

Change-Id: I2960c5f3a839fb4161ae5e25d3e88b5a7345b65d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447736
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-11-04 14:59:01 +00:00
Hana (Hyang-Ah) Kim 4ada35e5cb gopls/internal/lsp: handle modVulncheckSource in diagnosticSource.String
Change-Id: If6ebdfa2db3de8915842cf09da279d8ea7fa9b97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447735
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 14:58:54 +00:00
Robert Findley e5f03c1041 gopls/doc: clean up README and add a release policy
Clean up some broken links and stale documentation in gopls/README.md,
and add new documentation for the gopls release policy.

Fixes golang/go#55267

Change-Id: I9c7ed1f1d3949025f3c02edb69b475cf34f214eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446863
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-03 20:32:59 +00:00
Robert Findley d5e9e3592c go/analysis/passes/loopclosure: enable analysis of parallel subtests
Remove the internal guard preventing the loopclosure analyzer from
checking parallel subtests.

Also, improve the accuracy of the parallel subtest check:
 - only consider statements after the final labeled statement in the
   subtest body
 - verify that the *testing.T value for which T.Parallel() is invoked
   matches the argument to the subtest literal

Fixes golang/go#55972

Change-Id: Ia2d9e08dfa88b5e31a9151872025272560d4b5e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447256
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-03 17:48:16 +00:00
Alan Donovan 32e1cb7aed gopls/internal/lsp: clarify control around diagnostics
This CL includes some clarifications while trying to
understand the performance of the initial workspace load
and analysis. No significant behavior changes.

Server.diagnose:
- Factor the four copies of the logic for dealing
  with diagnostics and errors.
- Make the ActivePackages blocking step explicit.
  Previously mod.Diagnostics would do this implicitly,
  making it look more expensive than it is.
Server.addFolders:
- eliminate TODO. The logic is not in fact fishy.
- use informative names and comments for WaitGroups.
- use a channel in place of a non-counting WaitGroup.

Also, give pkg a String method.

Change-Id: Ia3eff4e784fc04796b636a4635abdfe8ca4e7b5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445897
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-01 21:03:16 +00:00
Robert Findley feeb0ba914 gopls/internal/lsp/cmd: fix deadlock when opening a file
Rename (*connection).AddFile to openFile, which is more accurate, and
fix a deadlock resulting from holding a Client lock while issuing a
Server request.

Fixes golang/go#56450

Change-Id: Ie6f34613e1e10e3274c3e6728b12f77e3a523b89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446856
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-01 17:35:21 +00:00
Robert Findley 6e9dc865e2 gopls/internal/lsp/source/completion: fix panic in completion on *error
Fix a panic during completion on variables of type *error. As a
predeclared type, the error type has nil package. Fix the crash
resulting from this oversight, as well as a related crash in the tests
analyzer, from which the new completion code was adapted.

Fixes golang/go#56505

Change-Id: I0707924d0666b238821fd14b6fc34639cc7a9c53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446815
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-01 16:24:04 +00:00
Robert Findley 70a130ebec gopls/api-diff: simplify the api-diff implementation
Simplify the api-diff implementation to use `go run` and cmp.Diff. The
latter is more maintainable and produces more readable output, due to
supporting line diffs for multi-line strings.

For golang/go#54459

Change-Id: I11c00e9728ce241aef8f9828f3840b4202294a9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444799
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-31 20:33:45 +00:00
Alan Donovan 3566f695a7 gopls/internal/lsp/source: minor space optimizations
Memory profiles show heavy allocation for the stack
and the function closure of FindDeclAndField.
This change moves both outside the loop, reducing
this function's fraction of allocation from 6.7%
before to 5.0% after, and reducing running time
by 3-7% on these benchmarks.

before
BenchmarkStructCompletion/completion-8               100          10432280 ns/op
BenchmarkImportCompletion/completion-8              1350            921785 ns/op
BenchmarkSliceCompletion/completion-8                100          10876852 ns/op
BenchmarkFuncDeepCompletion/completion-8             142           7136768 ns/op
BenchmarkCompletionFollowingEdit/completion-8         63          21267031 ns/op

After
BenchmarkStructCompletion/completion-8               100          10030458 ns/op
BenchmarkImportCompletion/completion-8              1311            918306 ns/op
BenchmarkSliceCompletion/completion-8                100          10179937 ns/op
BenchmarkFuncDeepCompletion/completion-8             150           6986303 ns/op
BenchmarkCompletionFollowingEdit/completion-8         63          20575987 ns/op

Change-Id: Ia459e41ecf20851ff4544f76ad7b415a24606cd1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446185
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-31 19:44:01 +00:00
Bryan C. Mills 7cdb0e7352 internal/jsonrpc2_v2: rename Serve to NewServer and eliminate its error return
Serve had a misleading name and signature: it did not actually block
on serving the connection, and never returned a non-nil error.

Updates golang/go#56281.

Change-Id: Ia6df0ba20066811b0551df3b3267dff2fffd7881
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443678
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:39 +00:00
Bryan C. Mills 28e9e509a6 internal/jsonrpc2_v2: eliminate error return from Bind
Also make (*Connection).Close safe to call from Bind.

A jsonrpc2_v2.Server has no good way to report an error from Bind.

If the Server saves the error to return from its own Wait method, that
might not ever actually happen: Wait waits for in-flight connections
to complete, but if some existing connection stays up then Wait will
not return.

If the Server goes ahead with establishing the connection and installs
its own Handler, that Handler needs to decide whether to serve the
error from Bind or something more opaque, and at that point Bind may
as well return a handler that makes that choice more precisely.

If the Server merely logs the error and closes the Connection, then
the Bind method itself may as well do that directly too.

It seems to me that the only winning move is not to play. Only Bind is
in a position to decide how to handle its errors appropriately, so it
should not return them to the Server.

Updates golang/go#56281.

Change-Id: I07dc43ddf31253ce23da21a92d2b6c0f8d4b3afe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443677
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-31 15:32:37 +00:00
Bryan C. Mills eabc3a08b7 internal/jsonrpc2_v2: eliminate isClosingErr
Also implement and use the Shutdown method, which was mentioned in a
doc comment in CL 292169 but not actually present at that time.

With proper synchronization, we don't need heuristics to determine
whether an error is due to a connection or listener being closed.
We know whether we have called Close (and why), and we can assume
that if we have called Close then that is probably the reason for
any returned error.

Fixes golang/go#56281.

Change-Id: I5e0ed7db0f736ca8df8cd8cf556b674e7a863a69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443675
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:17 +00:00
Alan Donovan f1c8f7f8d5 internal/lsp/source: optimize filter regular expression
When the default filter glob changed to **/node_modules,
the performance of BenchmarkWorkspaceSymbols was observed
to degrade by an astonishing 20%.

(CPU profiles of the benchmark reported that the Disallow
functions percentage had increased only slightly, but these
measures are misleading since the benchmark has a very
CPU-intensive set-up step, so all the percentages are
quotients of this figure, masking their relative importance
to the small region during which the benchmark timer is
running.)

This change removes the unnecessary ^.* prefix from the
generated regular expression. Really the regexp package
ought to do this.

Also, minor cleanups and tweaks to the surrounding code.

Change-Id: I806aad810ce2e7bbfb2c9b04009d8db752a3b10d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446177
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-28 18:07:06 +00:00
Robert Findley e074ef8db8 gopls/internal: don't show a warning if the Go version is undetected
CL 445581 inadvertently removed suppression of the Go version error if
the Go version was undetected. Add it back, with a test.

Fixes golang/go#56465

Change-Id: I352369096280c8d3423a7345123ec9309359fb58
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446175
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-10-28 15:53:15 +00:00
Hana (Hyang-Ah) Kim 7fba77ce5d gopls/internal/lsp/source: remove deprecated settings from EnableAllExperiments
VSCode Go Nightly uses `allExperiments` setting which triggers
calling this option. It doesn't make sense to add the settings
that are scheduled to be deleted.

Change-Id: I443d7b1722feafee04b6c63a06ff514a396c5d50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446095
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-27 22:55:48 +00:00
Robert Findley 42cb7bed6e gopls/internal/lsp: improve the Go version deprecation message
Improve the Go version deprecation message to be a warning at 1.13-15,
and provide better instructions for making it go away. Clarify support
in the gopls README.

Change-Id: I6b08e0bd698f5c085eee7a851a130c53affb8ab5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445581
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Auto-Submit: 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-10-27 13:53:43 +00:00
Alan Donovan 2af106efed gopls/internal/hooks: fixes to diff disaster logic
Previously, the disaster logic in the new diff implementation
would "encrypt" the before/after files using a monoalphabetic
substitution, which has been insecure since the 9th century.
Instead, save plain text, in file with mode 0600, and invite
the user to audit the file before sharing it with us.

Also, separate the two files using a NUL byte, not a newline,
which is highly ambiguous.

Also, in the JSON diff stats writer:
- print a warning if we can't create the log file.
  (The previous code was subtle--it stored a nil *os.File in
  an io.Writer, which caused Writes to fail with an error,
  in effect, silently.)
- Don't hold the mutex around the write operation.
- Fix minor off-by-one error (re: 15)
- Crash if JSON encoding fails; it "can't happen".

Change-Id: I9b6a4145451afd77594f0ef9868143634a9c4561
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445580
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-27 00:23:26 +00:00
pjw de675d5479 tools/gopls: argument in function bodies marked as parameter by semantic tokens
In func f(x int) int {return x;} the second x used to be marked as a
variable, but now is marked as a parameter, visually tying it to its
definition.

Fixes golang/go#56257

Change-Id: I8aa506b1ddff5ed9a3d2716d48c64521bdea0fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445095
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-26 15:27:38 +00:00
pjw 3e1371fd13 gopls/internal: start on LSP stub generator in Go.
This is the first in a series of CLs implementing the new stub
generator. The code is intended to reproduce exactly the current
state of the generated code.

This CL has the final file layout, but primarily consists
of the parsing of the specification.

The LSP maintainers now provide a .json file describing the messages and
types used in the protocol. The new code in this CL, written in Go,
parses this file and generates Go definitions.

The tests need to be run by hand because the metaModel.json file is not
available to the presubmit tests.

Related golang/go#52969

Change-Id: Id2fc58c973a92c39ba98c936f2af03b1c40ada44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443055
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
2022-10-26 13:02:30 +00:00
Hana (Hyang-Ah) Kim 121f889bbc gopls/internal/lsp/mod: merge vuln diagnostics to one, and add a hover
When a module contains multiple vulnerabilities, previously gopls published
one diagnostic message for each vulnerability. This change modifies this
behavior to publish only one vuln diagnostic for each module. This will
make the PROBLEMS panel more concise and readable. However, the information
about each vulnerability finding is useful, so we supplement this diagnostics
by sending a hover message in the module require line. An added benefit
of this approach is that, unlike the Diagnostics, VS Code supports rich
text rendering for Hover messages. So we can use markdown to add links and
necessary highlighting.

Before this change, go.mod require hover messages (e.g. go mod why result)
were associated only with the module path part, excluding the version string
part. But for vulnerability information hover message, I think it is better
to be applied to the entire module require line (both module path & version)
because they are information about the specific module/version. Currently
LSP hover returns only one hover, so we cannot use this different range only
to the vulnerability information hover. Thus, one side effect of this change
is that the module info hover message will be also shown to the version
part of each require statement.

Change-Id: Iccacd19fdebadc4768abcad8a218bbae14f9d7e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444798
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-10-25 17:27:10 +00:00
Alan Donovan d212f7d04f gopls/internal/regtest/workspace: fix bugs in test
The test had a missing import of "fmt" that is somehow
ignored by the current analysis implementation (but was
flagged as an error by my pending redesign).

Add the import, and update the go.sum hashes.

Change-Id: I6dd91b2863a7cbd0f16018151c942867bddc92e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444795
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-21 15:44:01 +00:00
Alan Donovan 051f03f2c9 gopls/internal/lsp/cache: remove unnecessary params
The Context arg to missingPkgError was unused.

Also, simplify Sprintf + Write -> Fprintf.
Also, add missing newline to error message.

Change-Id: I1728fa5029b2da398fdb5b606c8381256b87276b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444775
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>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-21 15:43:15 +00:00
Alan Donovan 21f61277b0 gopls/internal/lsp/cache: add PkgPath->PackageID index to Metadata
DepsBy{Pkg,Imp}Path are two different ways to look up the PackageID
of a direct dependency. (We need both.)

MissingDeps is now represented as a blank value in DepsByImpPath.

Also try to make sense of MissingDependencies.
(The deleted pkg.types==nil condition was provably false.)

Change-Id: I6a04c69d3d97b3d78b77d4934592735bb941d05f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444538
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-20 21:54:57 +00:00
Robert Findley 06041c93ef gopls/doc: update manual documentation of the newDiff setting
Because we normally suppress internal options, the documentation for
this setting is managed manually, and was stale. Update it, and bring it
in-line with the actual setting docstring.

Change-Id: Id3ceaa7303df4ee2a6bf07c54d087451169962cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444539
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-10-20 20:54:24 +00:00
Heschi Kreinick f112c43328 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.
Once this CL is submitted, and post-submit testing succeeds on all
first-class ports across all supported Go versions, this repository
will be tagged with its next minor version.

Change-Id: Ic6643ddc8dc991da1e6817b994390c38ef9ed231
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444536
Auto-Submit: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-20 20:04:29 +00:00
Robert Findley 65196caeed gopls/README.md: fix wording around supported Go versions
Change-Id: I25eb83edc5fca0958833371d2d4a6c28af6c21c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444175
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-20 18:01:13 +00:00
Robert Findley 61280309af gopls/internal: support renaming packages with int. test variants
We need to search intermediate test variants to find all imports of a
renamed package, but were missing them because we only considered
"active packages". Fix this by building up the set of renamed packages
based on metadata alone: it is unnecessary and potentially too costly to
request all (typechecked) known packages, when we only need access to
the metadata graph to determine which packages must be renamed.

In doing so, it becomes possible that we produce duplicate edits by
renaming through a test variant. Avoid this by keeping track of import
path changes that we have already processed.

While at it, add a few more checks for package renaming:
 - check for valid identifiers
 - disallow renaming x_test packages
 - disallow renaming to x_test packages

Also refactor package renaming slightly to pass around an edit map. This
fixes a bug where nested import paths were not renamed in the original
renaming package.

Fix some testing bugs that were exercised by new tests.

For golang/go#41567

Change-Id: I18ab442b33a3ee5bf527f078dcaa81d47f0220c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443637
Reviewed-by: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-20 17:36:38 +00:00
Alan Donovan 91311ab3b8 gopls/internal/lsp/cache: better import path hygiene
An import path is not the same as a package path.
For example, the declaration:
   import "example.com/foo"
may load a package whose PkgPath() is "vendor/example.com/foo".
There was a comment hinting at this in load.go.

This change introduces the concept of ImportPath as a
distinct type from PackagePath, and documents clearly
throughout the relevant APIs which one is expected.

Notes:
- Metadata.PkgPath is consistently set from the PackagePath,
  not sometimes (when a root) from PackagePath and sometimes (when
  indirectly loaded) from an arbitrary ImportPath that resolves to it.
  I expect this means some packages will now (correctly)
  appear to be called "vendor/example.com/foo"
  in the user interface where previously the vendor prefix was omitted.
- Metadata.Deps is gone.
- Metadata.Imports is a new map from ImportPath to ID.
- Metadata.MissingDeps is now a set of ImportPath.
- the package loading key is now based on a hash of
  unique imports. (Duplicates would cancel out.)
- The ImporterFunc no longer needs the guesswork of
  resolveImportPath, since 'go list' already told us
  the correct answer.
- Package.GetImport is renamed DirectDep(packagePath)
  to avoid the suggestion that it accepts an ImportPath.
- Package.ResolveImportPath is the analogous method
  for import paths. Most clients seem to want this.

Change-Id: I4999709120fff4663ba8669358fe149f1626bb8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443636
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-19 21:54:36 +00:00
Robert Findley b50d7ba6ee gopls: minor cleanup of standalone package support
Remove an unused err value, and update tests to exercise multiple
standaloneTags.

Change-Id: I88daace99111cba6f8bc74fad8aa0db844cb2654
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442776
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-10-19 19:08:58 +00:00
Robert Findley 502b93c33e gopls/internal/lsp: tolerate missing end position in RelatedInformation
Fix the panic reported in #56270, allowing RelatedInformation.End to be
missing.

Fixes golang/go#56270

Change-Id: I5f2dc27cf149c324f39ddbb056862434fe38f730
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443337
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>
2022-10-19 18:04:39 +00:00
Robert Findley 4818d9eec9 Revert "gopls/internal/lsp/cache: disable strict analysis while we fix panics"
This reverts commit 9b5e55b1a7.

Reason for revert: Should have been fixed by https://go.dev/cl/443100

Change-Id: I44eeff6605697b745c3729ac1ec49b9c09114f71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443340
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-18 14:49:53 +00:00
Alan Donovan bc4e384f85 gopls/internal/lsp/cache: fix crash in analysis
Since we removed the 'recover' in analysis, which swept crash
bugs under the rug, we've seen a large number of crashes on
the builders in which an analyzer crashes while trying
to use the result of another analyzer (e.g. the inspector)
on the same package. Logging shows that the "same" package
is in fact a stale version of the same package.

The root cause is that the key for the analysis cache
is the analyzer name paired with the "recipe" for the
package. However, analysis is not content with an equivalent
package: identity matters for ast.Nodes, types.Objects, etc.

This change attemps to fix the problem by, in effect, using
the identity (not the recipe) of the package as part of the key.
It is materialized by adding a store of promises to the pkg,
and then using the analysis name as the key within this store.

Change-Id: I057807d2781492a685f27c815250c3445e7475f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443100
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 17:58:19 +00:00
Robert Findley b93a56f289 refactor/satisfy: fix visiting functions in the unsafe package
Unlike other calls of qualified functions, the type of certain functions
in the unsafe package (namely Slice, Add) is not constant, and cannot be
determined by the types.Func being called. Update Finder.expr to
pre-emptively handle calls to functions in the unsafe package, similarly
to how it handles other builtins.

Fixes golang/go#56227

Change-Id: I7af51c1ecacbdf35e39c8e7b8273ffe6f953427f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443096
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 12:57:23 +00:00
Robert Findley 9b5e55b1a7 gopls/internal/lsp/cache: disable strict analysis while we fix panics
We now understand the longstanding race causing panics in gopls analysis
(the cache key for analysis handles is not correct, and can lead to
cache hits for analysis of stale packages).

It will take a little while to redesign our analysis caching, the
simplest solution being to hang analysis results off of the actual
package they are analyzing. In the meantime, suppress the panic as
before, to eliminate flakes.

For golang/go#55201
For golang/go#56035

Change-Id: I96600f186f9f31b67dae10c0a95a14fa73630571
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442794
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-15 19:01:56 +00:00
Alan Donovan 9ffaf69c2c gopls/internal/lsp/cache: minor analysis cleanups
This change moves the *pkg out of the actionHandle into
the actionResult. (In future we may not need to load the
package before creating the handle.) The actionResult
retains only the exported type information, to avoid keeping
the syntax trees (etc) live.

Also, perform object fact filtering once after the analysis pass,
instead of every time it is imported by another analysis.
Also, filter out unexported constants.

Also, log internal errors even when we don't bug.Reportf,
since errors merely returned by analysis are usually ignored,
making it harder to understand the analysis crashes.

Change-Id: I7257e8da5dc269090bff2817409948e46dcf7176
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442556
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-13 20:55:24 +00:00
Robert Findley ffb862b544 gopls/internal/lsp/cache: remove stray print statement
A stray print statement was accidentally left in CL 441877. Remove it.

Change-Id: I44e4408059f30d35ad8c84b070aea3e197762d1c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442782
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-13 17:41:26 +00:00
Robert Findley b2533141c6 gopls/internal/lsp/cache: add support for loading standalone main files
Add support in gopls for working on "standalone main files", which are
Go source files that should be treated as standalone packages.
Standalone files are identified by a specific build tag, which may be
configured via the new standaloneTags setting. For example, it is common
to use the directive "//go:build ignore" to colocate standalone files
with other package files.

Specifically,
- add a new loadScope interface for use in snapshot.load, to add a bit
  of type safety
- add a new standaloneTags setting to allow configuring the set of build
  constraints that define standalone main files
- add an isStandaloneFile function that detects standalone files based
  on build constraints
- implement the loading of standalone files, by querying go/packages for
  the standalone file path
- rewrite getOrLoadIDsForURI, which had inconsistent behavior with
  respect to error handling and the experimentalUseInvalidMetadata
  setting
- update the WorkspaceSymbols handler to properly format
  command-line-arguments packages
- add regression tests for LSP behavior with standalone files, and for
  dynamic configuration of standalone files

Fixes golang/go#49657

Change-Id: I7b79257a984a87b67e476c32dec3c122f9bbc636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441877
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-13 15:07:40 +00:00
Alan Donovan 3beecff0f6 gopls/internal/span: some cleanups
This change eliminates these redundant helper functions
- cache.rangeFromPositions
- source.LineToRange
- source.ByteOffsetsToRange
and makes various other simplifications and documentation
improvements.

Change-Id: Ic820ab560d71b88bde00b005e3a919334a5d1856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442015
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-13 13:15:27 +00:00
Suzy Mueller d3752388a2 gopls: dedup upgrade code actions for vulncheck
Make sure we aren't sending multiple code actions
that do the same thing. This also adds a upgrade
to latest code action.

Change-Id: Ic9cecd0a9410648673d4afe63da5a940960a4afc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436776
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: Suzy Mueller <suzmue@golang.org>
2022-10-12 18:24:48 +00:00
Hana (Hyang-Ah) Kim 19a5504ffc gopls/internal/lsp: use the golang.org/x/vuln/exp/govulncheck
Change-Id: Ifac1c9398a7d0923fa84c175ce8eea40e41a93f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/435362
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-11 21:42:28 +00:00