Commit Graph

6613 Commits

Author SHA1 Message Date
Robert Findley 7404bd2ffd all: gofmt some recent file changes
Change-Id: I62d2d35275964b35032e36d6ed3c9f4a31176f91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/414495
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-06-27 19:42:14 +00:00
Alan Donovan ec0831a434 refactor/satisfy: don't crash on type parameters
This change causes the satisfy constraint pass to correctly handle
type parameters. In nearly all cases this means calling coreType(T)
instead of T.Underlying(). This, and the addition of cases for
C[T] and C[X, Y], should make the code robust to generic syntax.

However, it is still not clear what the semantics of constraints
are for the renaming tool. That work is left to a follow-up.

Also, add a test suite that exercises all the basic operators,
using generics in each case.

Fixes golang/go#52940

Change-Id: Ic1261eb551c99b582c35fadaa148b979532588df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413690
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-27 18:39:52 +00:00
Alan Donovan 66bbba3d58 internal/memoize: remove unused Store.generations map
This change removes an unused map, renames Store.mu, and
add minor commentary.

Change-Id: I2f064ff0daf87e0f73930bc980760a453d18e70a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/414494
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-27 17:33:17 +00:00
Robert Findley 56116ec015 internal/memoize: don't destroy reference counted handles
Unlike generational handles, when reference counted handles are evicted
from the Store we don't know that they are also no longer in use by
active goroutines. Destroying them causes goroutine leaks.

Also fix a data race because Handle.mu was not acquired in the release
func returned by GetHandle.

Change-Id: Ida7bb6961a035dd24ef8566c7e4faa6890296b5b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/414455
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>
2022-06-27 16:29:48 +00:00
Ben Sarah Golightly 10494c735e cmd/digraph: fix typo
Change-Id: I086edda41c57b603afa660afb9396e17ba6c1a36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/414074
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-06-25 13:13:44 +00:00
Robert Findley 93a03c2c54 internal/lsp/cache: invalidate reverse closure when loading packages
When setting new metadata for a package ID, we invalidate the
corresponding type-checked packages. Whenever we invalidate a package,
we must also invalidate its reverse transitive closure. Otherwise we may
end up in a scenario where the go/types import graph does not match
gopls' view of the import graph.

Change-Id: I8db6ff3e4a722656e6dde7907e7c0470375c4847
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413683
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-06-24 21:40:29 +00:00
Robert Findley c36379be2b internal/lsp/cache: don't set new metadata if existing is valid
If gopls believes it has valid metadata for a package, don't set new
metadata. This is consistent with previous behavior that was changed in
CL 340851.

In principle this shouldn't matter, but in practice there are places
where gopls doesn't yet want to invalidate packages, *even though* their
metadata may have changed (such as while editing a go.mod file before
saving). In the future we should eliminate these places, but for now we
should let snapshot.clone control this invalidation.

This also reduces the number of type-checked packages we invalidate on
load.

Change-Id: I0cc9bd4186245bec401332198de0047ff37e7ec7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413681
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-06-24 21:40:14 +00:00
Robert Findley e1ec1f3230 internal/imports: use a module resolver if GOWORK is set
Previously, gopls would fall back on a gopath resolver when running
goimports from a directory containing go.work (but not go.mod). Fix this
by update the code to recognize that GOWORK also puts goimports into
module mode.

All the work to _support_ go.work had already been done, but the tests
were only passing because they were setting GO111MODULE=on explicitly
(and therefore GOMOD=/dev/null was satisfying the pre-existing check).

Also add a test for the regression in gopls.

Fixes golang/go#52784

Change-Id: I31df6f71a949a5668e8dc001b3ee25ad26f2f927
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413689
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2022-06-24 21:03:09 +00:00
Jamal Carvalho 60ca6366e6 internal/lsp: use camel case for inlay hint config fields
To properly format these field names in the vscode config ui
these fields should be camel case.

Change-Id: I3b8b8fb6371172ecb464710f7d91b9fc67e0ed42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413684
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-24 17:24:36 +00:00
Ruslan Nigmatullin 2994e99415 internal/persistent: change map to use set/get as method names
Purely a style change, no expected behavior difference.

Change-Id: Ib882eb54537126b31d20dde65c4a517d5452a8b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413661
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-24 13:47:25 +00:00
Suzy Mueller 22ab2538d4 internal/lsp: rename viewport to range
The final LSP spec for 3.17 changed the name of ViewPort to Range
for both InlayHints and InlineValues. This manually updates just
these fields in our protocol.

Change-Id: I0303a36536016ca59c87dc45f55fadcd80e72bfc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413677
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-23 18:17:15 +00:00
Ruslan Nigmatullin 3f5f798e2a internal/lsp/cache: use persistent map for storing files in the snapshot
This on average reduces latency from 34ms to 25ms on internal codebase.

Updates golang/go#45686

Change-Id: I57b05e5679620d8481b1f1a051645cf1cc00aca5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413654
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-06-23 13:23:41 +00:00
Ruslan Nigmatullin f60e9bc48f internal/lsp/cache: use persistent map for storing gofiles in the snapshot
Use treap (https://en.wikipedia.org/wiki/Treap) as a persistent map to avoid copying s.goFiles across generations.
Maintain an additional s.parseKeysByURIMap to avoid scanning s.goFiles on individual file's content invalidation.

This on average reduces didChange latency on internal codebase from 160ms to 150ms.

In a followup the same approach can be used to avoid copying s.files, s.packages, and s.knownSubdirs.

Updates golang/go#45686

Change-Id: Ic4a9b3c8fb2b66256f224adf9896ddcaaa6865b1
GitHub-Last-Rev: 0abd2570ae9b20ea7126ff31bee69aa0dc3f40aa
GitHub-Pull-Request: golang/tools#382
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411554
Reviewed-by: Robert Findley <rfindley@google.com>
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-06-22 21:10:11 +00:00
Suzy Mueller 871637b647 internal/lsp: add settings for inlay hints and enable
This change adds user settings for enabling inlay hints, modeled
roughly after analyzers. This will allow users to turn on specific
inlay hints that they like and leave others off.

With all of the inlay hints turned off by default, we can now enable
inlay hints.

Change-Id: Ie5dfcbbab1e0b7312eafcc4aa08cb4fe8a83fc31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411906
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-22 17:08:41 +00:00
Tormod Erevik Lea a44cc76dc1 cmd/stringer: use explicit NeedX values instead of deprecated LoadSyntax
Change-Id: Ie25f67fd98d34b0a907bd13357e2643b1b79443b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412914
Reviewed-by: Alex Rakoczy <alex@golang.org>
Auto-Submit: Daniel Martí <mvdan@mvdan.cc>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-06-22 16:23:22 +00:00
Robert Findley 4e231cb6f8 internal/lsp/cache: don't prune unreachable metadata on clone
Package metadata is small; there is no reason not to keep it around, and
pruning it on every clone is needless work.

Change-Id: I9ea73315cc6b673625f0f7defe1fd61c2e1eb123
Reviewed-on: https://go-review.googlesource.com/c/tools/+/373695
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-06-22 14:01:02 +00:00
Robert Findley a2de63544e internal/lsp/cache: honor the go.work for computing workspace packages
When using Go workspaces, the go.work file should be used to determine
which packages are workspace packages.

For golang/go#48929

Change-Id: I1a8753ab7887daf193e093fca5070b4cc250a245
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400822
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-06-22 14:00:53 +00:00
Alan Donovan cbb8e8e923 internal/span: optimise URI.Filename to avoid allocation
This change adds a fast-path check for the common case:
"file:", lowercase, followed by a simple POSIX absolute
file name without special characters.

This function used to account for 1% of CPU on the DidChange
benchmark (and I'm sure I've seen higher fractions on other
tests--but perhaps that was before the clone optimizations?).

It was tested by adding an assertion that it agrees with the
slow path and running all our tests.

Change-Id: I15492b8a317715468870b00041bf8f6b0bb53bb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411900
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-06-22 02:37:34 +00:00
Alan Donovan 63d8015eb8 internal/lsp/cache: minor simplifications to Symbols
Minor cleanups based on studying the code in preparation
for saving a persistent index:

- Remove unused error result from Symbols method.
- Remove unnecessary fields from symbolHandle.
- Add various explanatory comments.
- In workspace_symbols.go:
  - separate extract and match phases of collectSymbols clearly
  - replace symbolCollector and matchWorker types by simple parameters
  - combine loops (roots, buildMatcher)
  - move buildMatcher creation down to where it is needed.

Change-Id: Ifcad61a9a8c7d70f573024bcfa76d476552ee428
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412822
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-21 20:15:42 +00:00
Dylan Le 59bd4faed9 internal/lsp: find references to package
Update References to detect if the package is referenced and a regtest to test within and external package references.

Updates golang/go#41567

Change-Id: I607a47bf15f1c9f8236336f795fcef081db49d6a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/408714
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-21 19:39:47 +00:00
Jamal Carvalho a1303c83f3 internal/lsp: remove tooltip from inlay hints
The tooltip for truncated inlay hint labels is redundant
with the hover state of the target identifier. This matches
the behavior of inlay hint implementations in other languages.

Change-Id: I209054f8c65df504cae67121e3cbc3eacaf02710
Reviewed-on: https://go-review.googlesource.com/c/tools/+/413417
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-21 17:15:14 +00:00
Jamal Carvalho 641b30b3f4 internal/lsp: add inlay hints for inferred type params
This will show inferred type information for generic function
call expressions.

Example:
SumNumbers<[string, int64]>(ints)

For golang/go#52343

Change-Id: I05595f236626e8fb3666af5160611e074e8265a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412994
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
2022-06-21 17:15:02 +00:00
aarzilli 70ccf57e4b go/packages: fix loading single file when outside of GOPATH, module
Allows a 'file=' query to load a single file even when it is outside of
GOPATH or a module.

Fixes golang/go#49949

Change-Id: I519f1412923dfc1d2504ec49620d10c823e5c0dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/369014
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-21 16:40:32 +00:00
Alan Donovan 381ac87aae internal/lsp/debug: reduce critical sections in trace
This change reduces the sizes of the critical section
in traces.ProcessEvent, in particular moving allocations
ahead of Lock. This reduces the contention according
to the trace profiler.

See https://go-review.googlesource.com/c/go/+/411909 for
another reduction in contention. The largest remaining
contention is Handle.Get, which thousands of goroutines
wait for because we initiate typechecking top down.

(Second attempt at https://go-review.googlesource.com/c/tools/+/411910,
reverted in https://go-review.googlesource.com/c/tools/+/412694.
The changes to Generation.Bind have been dropped.)

Change-Id: Ia9050c97bd12d2d75055f8d1dfcda3ef1f5ad334
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412820
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-17 20:37:28 +00:00
Suzy Mueller 1e14d994d8 internal/lsp: add inlay hints for composite literal types
Add inlay hints for composite literal types. This will show type
information for composite literals with no explicit types.

Example:
<struct {in, want string}>{"hello", "goodbye"}

For golang/go#52343

Change-Id: Ia1f03b82669387c864353b8033940759fa1128e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411905
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-17 18:37:13 +00:00
Alan Donovan e9870152b0 internal/lsp/cache: symbolize in parallel
This change parallelizes the buildSymbolHandle().Get computation for
each file, with 2xGOMAXPROCS goroutines, since it is a mix of I/O (read)
and CPU (parse). (The symbolize AST walk happens in other goroutines.)

This reduces the time for the source.WorkspaceSymbols trace task
applied to kubernetes from 3981ms to 630ms (6x faster).

Change-Id: I5f1ee4afc2f6b2dd752791a30d33a21f50180a9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412818
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-16 20:50:23 +00:00
Alan Donovan 88325aa063 internal/memoize: add trace region for Handle.run
The region name includes the type of the key, such as packageHandleKey
or actionHandleKey, so we can separate these deferred computations
into their own buckets.

Change-Id: I0359127ccf47b158f353fae2bf74ba000668a40b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412817
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-06-16 20:40:53 +00:00
Rob Findley c353b054c4 internal/lsp/cache: delete checkSnapshotLocked
Now that the entire metadata graph and workspace packages are derived
from metadata, there should be no need to validate coherency.

This results in a small improvement to didChange benchmarking (within
statistical noise).

For golang/go#45686

Change-Id: I32683e025f42d768d62864683e55d4c00146a31c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340855
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-06-16 18:25:24 +00:00
Rob Findley 567c98ba1a internal/lsp/cache: don't walk URIs to invalidate metadata
Since ids is derived from metadata, we should not have to walk ids to
see which metadata is still active. Just compute metadata updates
directly.

Benchmark (didChange in k8s): ~45ms->41ms

For golang/go#45686

Change-Id: Id557ed3f2e05c903e4bb3f3f6a4af864751c4546
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340854
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-06-16 18:24:49 +00:00
Rob Findley dffd6452c0 internal/lsp/cache: only clone metadata if something changed
We with immutable metadata, we don't need to clone if nothing was
invalidated.

Benchmark (didChange in k8s): 65ms->45ms

For golang/go#45686

Change-Id: I6b5e764c53a35784fd8c7b43bc26361f4ee8d928
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340853
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-06-16 18:23:55 +00:00
Robert Findley 4ba3d2217f internal/lsp/cache: clone the metadata graph when clearing ShouldLoad
The Metadata type was mutated in exactly one place: when setting the
ShouldLoad bit after package loading completes. Address this by cloning
the metadata graph when clearing ShouldLoad. After this change, metadata
graphs and the data within them are immutable.

This also fixes a range-variable capture bug in load.go: previously we
were deferring a call to clearShouldLoad for the range variable scope.
After this change, we properly clear the ShouldLoad bit for all scopes.

Change-Id: I8f9140a490f81fbabacfc9e0102d9c638c7fbb37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400821
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-06-16 18:23:17 +00:00
Rob Findley 39d3d49260 internal/lsp/cache: use metadataGraph.Clone in snapshot.clone
Rather than updating metadata directly in snapshot.clone, build a set of
updates to apply and call metadata.Clone.

After this change, metadata is only updated by cloning, so we can
eliminate some code that works with mutable metadata.

In the next CL we'll only update the metadata if something changed, but
this is intentionally left out of this CL to isolate the change.

Benchmark (didChange in kubernetes): ~55ms->65ms, because it is now more
work to compute uris.

For golang/go#45686

Change-Id: I048bed65760b266a209f67111c57fae29bd3e6f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340852
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-06-16 18:19:30 +00:00
Rob Findley 8a9207816c internal/lsp/cache: build a new metadata graph on load
Introduce a metadataGraph.Clone method that can be used to clone a
metadata graph, applying a set of updates. During clone, ids and imports
are recomputed from scratch based on the known metadata.

Also refine the check for "real" packages when determining whether a
command-line-arguments package should be kept as a workspace package: if
all other packages are invalid, but the command-line-arguments package
is valid, we should keep the command-line-arguments package.

Updates golang/go#45686

Change-Id: Iea8d4f19c1d1c5a2b0582b9dda5f9143482a34af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340851
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-06-16 15:50:09 +00:00
Rob Findley 9f38ef7f15 internal/lsp/cache: derive workspace packages from metadata
Now that we preserve stale metadata, we can derive workspace packages
entirely from known metadata and files. This consolidates the logic to
compute workspace packages into a single location, which can be invoked
whenever metadata changes (via load or invalidation in clone).

Additionally:
 - Precompute 'HasWorkspaceFiles' when loading metadata. This value
   should never change for a given Metadata, and our view.contains func
   is actually quite slow due to evaluating symlinks.
 - Track 'PkgFilesChanged' on KnownMetadata, since we don't include
   packages whose package name has changed in our workspace.

Also introduce a few debug helpers, so that we can leave some
instrumentation in critical functions.

For golang/go#45686

Change-Id: I2c994a1e8ca05c3c42f67bd2f4519bea5095c54c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340735
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-16 15:49:38 +00:00
Alan Donovan 041035c34a Revert "internal/lsp/cache: reduce critical sections"
This reverts commit 654a14b527.

Reason for revert: my flawed understanding of the concurrency 

Change-Id: I31a35267323bb1ff4dff1d9244d3ce69c36cdda4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412694
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-16 15:42:24 +00:00
Hana (Hyang-Ah) Kim d097bc9f9d gopls/internal/vulncheck: include nonaffecting vulnerability info
This info is still useful to tell users that some required modules
have known vulnerabilities, but the analyzed packages/workspaces
are not affected.

Those vulnerabilities are missing Symbol/PkgPath/CallStacks.

Change-Id: I94ea0d8f9ebcb1270e05f055caff2a18ebacd034
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412457
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2022-06-16 14:42:12 +00:00
Hana (Hyang-Ah) Kim e8b9ff1291 gopls/internal/govulncheck: sync x/vuln@4eb5ba4
Change-Id: Idf2147684626368116a5330fefb0a63d8c82f7a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/412456
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-16 13:07:50 +00:00
Alan Donovan 654a14b527 internal/lsp/cache: reduce critical sections
This change reduces the sizes of the critical sections
in traces.ProcessEvent and Generation.Bind, in particular
moving allocations ahead of Lock. This reduces the contention
according to the trace profiler.

See https://go-review.googlesource.com/c/go/+/411909 for
another reduction in contention. The largest remaining
contention is Handle.Get, which thousands of goroutines
wait for because we initiate typechecking top down.

Also, add a couple of possible optimization TODO comments,
and delete a stale comment re: Bind.

Change-Id: I995a0bb46e8c9bf0c23492fb62b56f4539bc32f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411910
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-15 15:41:53 +00:00
Hana (Hyang-Ah) Kim 27db7f40b9 gopls: update golang.org/x/vuln to latest @4eb5ba4
This picks up the recent performance improvement work in vulncheck api
like https://go-review.googlesource.com/c/vuln/+/410897
and fix like https://go-review.googlesource.com/c/vuln/+/411354

Change-Id: Ie595fdb14ae27bd18b5cdd69ca9977d7c14d384c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411908
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2022-06-14 18:53:49 +00:00
Hana (Hyang-Ah) Kim c993be6923 go/analysis/internal/checker: log codeFact error, remove unused action.inputs
Change-Id: I39ac785ed7666a5a1373443a2f56a1742a8c0858
Reviewed-on: https://go-review.googlesource.com/c/tools/+/410368
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-06-14 18:53:22 +00:00
Ruslan Nigmatullin ed27611107 internal/lsp/cache: cache known subdirs pattern
Known subdirs change rarely and it's quite expensive to compute
a glob pattern derived from them, so cache computation result
and inherit it across generations.

Computation cost is divided ≈evenly between `sort.Sort` and
`span.URI.Filename` calls, and there is no trivial way to optimize
them away besides caching.

Benchmark (didChange in kubernetes): ~37ms->30ms

Change-Id: Idb1691c76b8ff163dc61f637f07229498888606c
GitHub-Last-Rev: cd99a9ce5c797afb5aaa9b478fcf433edd0dc03c
GitHub-Pull-Request: golang/tools#383
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411636
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-14 15:20:12 +00:00
Suzy Mueller ebc084af8b internal/lsp: add inlay hints count to test summary
Change-Id: Ia74f4a43a114715a6011405bf70f9dfa269c3318
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411901
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2022-06-14 14:54:03 +00:00
Suzy Mueller c15c04572c internal/lsp: enable inlay hint tests
The change to implement inlay hints has been merged, so we need to
enable the tests.

Change-Id: I47e7ab343d0ab10283caac0a3d6677dd69c7504a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411898
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-13 21:07:50 +00:00
Suzy Mueller 034398994d internal/lsp: fix error message for inlay hints
Fix the error message to describe inlay hints failure.

Change-Id: If4597bc3e513c4dce344f11f6fa92ba20e29681a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411899
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-06-13 21:07:40 +00:00
Alan Donovan a41fc9869a internal/lsp/cache: use [256]byte Hash instead of hex digit string
I had hoped to see a reduction in total allocation, but it does not
appear to be significant according to the included crude benchmark.
Nonetheless this is a slight code clarity improvement.

Change-Id: I94a503b377dd1146eb371ff11222a351cb5a43b7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411655
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-06-13 13:05:07 +00:00
Jamal Carvalho c41ddceaa4 internal/lsp: include padding in inlay hint marker tests
The marker tests are updated to include padding values
when mapping inlay hints to text edits.

Change-Id: Ieb421088238c65b07abdad12763816d3d1e757c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411654
Run-TryBot: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-06-10 19:32:04 +00:00
Jamal Carvalho 5e48d261e2 internal/lsp: add inlay hints for composite literal names
For golang/go#52343.
For golang/vscode-go#1631.

Change-Id: I8fba5ddf0bd25ba0fc20f3305ce13868f426087c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411102
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-10 19:31:56 +00:00
Jamal Carvalho 83b0675060 internal/lsp: add inlay hints for constant values
For golang/go#52343.
For golang/vscode-go#1631.

Change-Id: Iaef0beab2837502f6428767f457d1da21848fcb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411101
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-06-10 19:31:37 +00:00
Jamal Carvalho ecc1479278 internal/lsp: add inlay hints for variable types
For golang/go#52343.
For golang/vscode-go#1631.

Change-Id: I94a1b3c389d8bfaa48754e28a52ef76c29eb6ead
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411100
Run-TryBot: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-06-10 19:31:24 +00:00
Jamal Carvalho 65c0181b23 internal/lsp: support textDocument/inlayHint for parameter names
This change implements support for textDocument/inlayHint and
adds inlay hints for parameter names.

For golang/go#52343.
For golang/vscode-go#1631.

Change-Id: I3f989838b86cef4fd2b4076cb6340010fff7c24c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411094
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-10 19:31:11 +00:00