Commit Graph

8581 Commits (master)

Author SHA1 Message Date
Alan Donovan b6235391ad gopls/internal/cache: suppress "internal" import check on Bazel
The go command treats imports of packages whose path contains
"/internal/" specially, and gopls must simulate it in several
places. However, other build systems such as Bazel have their
own mechanisms for representing visibility.

This CL suppresses the check for packages obtained from a
build system other than go list. (We derive this information
from the view type, which in turn simulates the go/packages
driver protocol switch using $GOPACKAGESDRIVER, etc.)

Added test using Rob's new pass-through gopackagesdriver.

Fixes golang/go#66856

Change-Id: I6e0671caeabe2146d397eb56d5cd4f7a40384370
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587931
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-31 21:21:43 +00:00
Alan Donovan 1e9d12dd1f go/packages: pass -overlay to all 'go list' invocations
Even in the trivial go list invocations (to enumerate
modules or type sizes), the complex behavior of Go modules
requires that the appropriate overlays are visible, since
they may define go.mod files.

Also, a test case suggested by Dominik Honnef.

Fixes golang/go#67644

Change-Id: I19348ae7270769de438a7f4ce69c3f7a55fb2f55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588936
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-31 21:13:46 +00:00
Rob Findley 3c293ad67a internal/cache: invalidate broken imports when package files change
When a file->package association changes, it may fix broken imports.
Fix this invalidation in Snapshot.clone.

Fixes golang/go#66384

Change-Id: If0f491548043a30bb6302bf207733f6f458f2574
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588764
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-31 20:31:12 +00:00
Rob Findley 5eff1eeb9f gopls/internal/cache: check viewMap before altering views
The bug report in golang/go#67144 likely means that we got a change
notification after the session was shut down (and thus s.viewMap was
nil).

Fix this by being more rigorous in guarding any function that resets
s.viewMap with a check for s.viewMap != nil. Also, refactor to remove
the confusing updateViewLocked and dropView functions, which obscure the
logic of their callers.

Fixes golang/go#67144

Change-Id: Ic76ae56fa631f6a7b11709437ad74a2897d1e537
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589456
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-05-31 20:31:05 +00:00
Alan Donovan da9cad458c go/packages: avoid unnecessary "realpath" on pwd
GOPACKAGESDRIVER commands absolutize filenames
relative to their current working directory. However,
os.Getwd may inadvertently expand out any symbolic
links in the path, causing files to have the "wrong"
path, and breaking various name-based equivalence tests
that are common in the go/packages domain.

This CL exploits the same trick used in gocommand to
prevent os.Getwd from expanding symbolic links:
if Stat(Getenv(PWD) returns the process's working
directory, then the iterated ".." search (which
inadvertently expands symlinks) is avoided.

It is unfortunate that driver writers must think about
this. Mostly it only shows up in tests, as that's
where the subprocess directory varies from the parent
directory.

Also, add -driver flag to gopackages debug helper,
which causes it to use drivertest instead of go list
directly.

Change-Id: Ibe12531fe565e74ca1d2565805b0f2458803f6b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588767
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-31 19:15:03 +00:00
John Dethridge 71b7fa927f go/callgraph/vta: save some heap allocations in the trie implementation
The mkLeaf and mkBranch functions use hash consing to dedup values, by
constructing the leaf or branch value, and inserting it into a hash map
if the value is not already there.

This change uses two variables, one as the key for the map lookup, and a
second for the map value.  This leads the compiler to place the first on
the stack and the second on the heap, so that a heap allocation is only
done if there is a cache miss.

This can be a significant saving for large VTA type graphs.

name              old time/op    new time/op    delta
TrieStandard-16     2.35µs ± 6%    2.03µs ± 5%  -13.48%  (p=0.008 n=5+5)
TrieSmallWide-16    1.70µs ± 8%    1.41µs ± 5%  -16.76%  (p=0.008 n=5+5)

name              old alloc/op   new alloc/op   delta
TrieStandard-16     1.20kB ± 9%    0.89kB ± 5%  -26.33%  (p=0.008 n=5+5)
TrieSmallWide-16      812B ±12%      480B ± 5%  -40.94%  (p=0.008 n=5+5)

name              old allocs/op  new allocs/op  delta
TrieStandard-16       6.00 ± 0%      3.00 ± 0%  -50.00%  (p=0.008 n=5+5)
TrieSmallWide-16      8.00 ± 0%      1.00 ± 0%  -87.50%  (p=0.008 n=5+5)

Change-Id: I7faeb5458320972f9a267ff7ead04b4e5c31dfb8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588217
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
2024-05-31 16:36:38 +00:00
Zvonimir Pavlinovic 2f8e37823b go/callgraph/vta: remove graph successors method
It is not used anywhere except tests, where it can be easily replaced.

Change-Id: Iec816099b7ce24685e2b42591a243a322689f6a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587098
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2024-05-31 13:58:28 +00:00
Alan Donovan 624dbd05dd go/analysis/passes/stringintconv: post gotypesalias=1 tweak
stringintconv will return the alias name if available.
Make the test agnostic.

Updates golang/go#64581

Change-Id: I47d245c62f45cd6c02f45ba5eb770318dcb7cbec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577657
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-30 23:22:45 +00:00
Rob Findley 4669dc77ee gopls/internal/test/marker: simplify seedCache file
Simplify the file used to seed the marker test cache, as suggested in CL
588940.

Change-Id: I421a3e013fcc17f2c6ab2ff5c269e6f360ca9d6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588942
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-05-30 19:32:06 +00:00
Rob Findley 6887e998b2 gopls/internal/cache: use a better view in viewOfLocked
The 'bestView' function was used in two places, where the meaning of
'best' differed. When re-evaluating view definitions in selectViewDefs,
we may want to create a new view if none of them matched build tags.
When operating on a file in viewOfLocked, we want to choose the most
relevant view out of the existing view definitions.

In golang/go#60776, we see that the latter concern was poorly handled by
the 'bestView' abstraction. Returning nil was not, in fact, best,
because it resulted in the file being associated with the default AdHoc
view, which doesn't know about modules.

Refactor so that viewOfLocked chooses the most relevant view, even if
none match build tags. This causes the orphaned file diagnostic to more
accurately report that the file is excluded due to build tags.

Fixes golang/go#60776

Change-Id: I40f236b3b63468faa1dfe6ae6aeac590c952594f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588941
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-30 19:19:34 +00:00
Rob Findley bd624fd45d gopls: make tests tolerant of new go/types error format
CL 589118 is changing the format of go/types errors.

Update tests and the unusedvariable analyzer to be tolerant of this new
format.

For golang/go#67685

Change-Id: Ic1d3e663973edac3dcc6d0d6cc512fffd595eeb2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589455
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2024-05-30 18:26:36 +00:00
Rob Findley 2e977dddbb internal/drivertest: evaluate symlink before calling packages.Load
Fixes a test failure following the submission of CL 589135.

Change-Id: I746d06d6a661552de472c21e7010d5b07ad261d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589059
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-30 17:27:21 +00:00
Rob Findley 8d54ca127f gopls/internal/test/marker: seed the cache before running tests
The marker tests are heavily parallelized, and many import common
standary library packages. As a result, depending on concurrency, they
perform a LOT of duplicate type checking and analysis.

Seeding the cache before running the tests resulted in an ~80% decrease
in CPU time on my workstation, from ~250s to ~50s, which is close to the
~40s of CPU time observed on the second invocation, which has a cache
seeded by the previous run. I also observed a ~33% decrease in run time.
Admittedly my workstation has 48 cores, and so I'd expect less of an
improvement on smaller machines.

Change-Id: Ied15062aa8d847a887cc8293c37cb3399e7a82b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588940
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2024-05-30 16:14:22 +00:00
Robert Findley 01018ba9ed Revert "gopls/internal/settings: enable semantic tokens by default"
This reverts CL 579337.

Reason for revert: need more work on staging this change in VS Code.

Change-Id: I82eea17f96a0365bd616ee2617536f10869e08f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589060
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2024-05-30 12:59:04 +00:00
Alan Donovan 019da392d7 gopls/internal/golang: OutgoingCalls: fix crash on unsafe.Slice
Also, audit the golang package for similar places where we
discriminate builtins, and make them all use the new isBuiltin
helper, which is based on lack of a position instead of messing
around with pkg==nil||pkg==types.Unsafe||...
"A symbol without a position" is a fair definition of a built-in.

Fixes golang/go#66923

Change-Id: I7f94b8d0f865f8c079f1164fd61121eefbb40522
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588937
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-05-29 22:47:42 +00:00
Rob Findley 30c880d92f gopls/internal/cache: improve missing import error message
Make the missing import error knowledgeable of the view type, so that it
can correctly reference modules, GOROOT, GOPATH, or go/packages driver
as applicable.

While at it, fix some duplicated and broken logic for determining if the
view is in go/packages driver mode, consolidate on representing the
driver accurately as GoEnv.EffectiveGOPACKAGESDRIVER.

Fixes golang/go#64980

Change-Id: I7961aade981173098ab02cbe1862ac2eca2c394b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589215
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-05-29 22:32:04 +00:00
Rob Findley d017f4a0a6 go/packages/internal/drivertest: a package for a fake go/packages driver
Add a new drivertest package that implements a fake go/packages driver,
which simply wraps a call to a (non-driver) go/packages.Load. This will
be used for writing gopls tests in GOPACKAGESDRIVER mode.

The test for this new package turned up an asymmetric in Package JSON
serialization: the IgnoredFiles field was not being set while
unmarshalling. As you might imagine, this was initially very confusing.

Fixes golang/go#67615

Change-Id: Ia400650947ade5984fa342cdafccfd4e80e9a4dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-05-29 21:36:25 +00:00
John Dethridge e2290455dc go/callgraph/vta: avoid some temporary data structures using callbacks
Change propTypes and siteCallees to call a supplied function for each
value they yield, instead of returning a slice of all the values.

Change resolve to return a map instead of a slice.  Its output is passed
to intersect, where the values were needed in a map.

Change intersect to produce its output more directly, using the above.

These changes can significantly reduce the amount of heap data created
for large graphs.

name    old time/op    new time/op    delta
VTA-16     629ms ± 1%     627ms ± 1%     ~     (p=0.548 n=5+5)

name    old alloc/op   new alloc/op   delta
VTA-16    88.9MB ± 0%    79.6MB ± 0%  -10.49%  (p=0.008 n=5+5)

name    old allocs/op  new allocs/op  delta
VTA-16     1.92M ± 0%     1.83M ± 0%   -4.84%  (p=0.008 n=5+5)

Change-Id: Ia143d3bb14df42980ce1b1bc027babd631d0d61c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588218
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-29 14:13:52 +00:00
Alan Donovan 0215a5b8f4 go/packages: document fields that are part of JSON schema
Package is both the "cooked" result data type of a Load
call, and the "raw" JSON schema used by DriverResponse.

This change documents the fields that are part of the
protocol, and ensures that the others are omitted from
the JSON encoding. (They are populated by the post-
processing done by 'refine', if the appropriate Need
bits are set.)

Also
- document that there are a number of open bugs
  in places where it may be likely to help,
  particularly Mode-related issues.
- document that Load returns new Packages,
  using distinct symbol realms (types.Importers).
- document Overlays in slightly more detail.

Fixes golang/go#67614
Fixes golang/go#61418
Fixes golang/go#67601
Fixes golang/go#43850
Updates golang/go#65816
Updates golang/go#58726
Updates golang/go#56677
Updates golang/go#48226
Updates golang/go#63517
Updates golang/go#56633

Change-Id: I2f5f2567baf61512042fc344fca56494f0f5e638
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588141
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2024-05-29 13:42:44 +00:00
Rob Findley f10a0f1c3b gopls/internal/golang: skip TestFreeRefs on js
This test was (surprisingly) the only source of failure on js/wasm. Skip
it to keep the build dashboard clean.

Change-Id: I69aa5b91152c313b5dba7d13a76fd6d32cd159a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588755
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2024-05-28 17:35:58 +00:00
Hana (Hyang-Ah) Kim d940b33567 gopls/internal/server: support InsertReplaceEdit completion
Many editors support two different operations when accepting
a completion item: insert and replace. LSP 3.16 introduced support
for both using `InsertReplaceEdit`. For clients that declare
textDocument.completion.insertReplaceSupport capability, gopls
can provide both insert/repace mode text edits.

See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItem

VS Code client supports this capability, and users can switch
the mode with the editor.suggest.insertMode setting.
Note that in VS Code, "insert" is the default. That means,
providing a different range for insert changes the
user-perceived completion behavior greatly.

To reduce potential regression, this CL sets a different range
for insert only if all of the following conditions are met:

   * there is a surrounding identifier token for the position.
   * when splitting the identifier surrounding the position
     to prefix and suffix, the suffix is not empty.
   * the suffix is not part of the candidate's insert text,
     which means the suffix may be deleted in replace mode.

Fixes golang/vscode-go#3365
Fixes golang/go#61215

Change-Id: Ibe2476ddb9c13ecbaca7fb88cb3564912c4e5f4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585275
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-28 17:19:42 +00:00
Alan Donovan e635bfa66b gopls/internal/golang: unexport more declarations
I missed a few in my previous CL:
- FindParam
- ParamInfo and its fields
- TestFn
- TestFns (eliminated entirely)

Change-Id: Ib8dabba73e679be5842bf1af359db80157446993
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587932
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-28 15:48:05 +00:00
Alan Donovan 7045d2e410 go/analysis/passes/nilness: fix bug with MakeInterface(TypeParam)
An interface conversion such as any(x) can be a MakeInterface
(if x is a non-interface type) or a ChangeInterface (if x has
an interface type), and their nilabilities differ.
If x's type is a type parameter, SSA uses MakeInterface, so
we have to ascertain whether the type parameter is definitely
or only maybe a concrete type in order to determine its
nilability.

This change required exposing NormalTerms to x/tools,
and making it take the Underlying of its argument,
so that NormalTerms(error) = NormalTerms(any) = [].
Previously, NormalTerms(error) was [error].

Fixes golang/go#66835
Change-Id: Idf9c39afeaeab918b0f8e6288dd93570f7cb7081
Reviewed-on: https://go-review.googlesource.com/c/tools/+/578938
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-25 11:56:57 +00:00
Alan Donovan e1b14a1915 gopls/internal/server: avoid VS Code lightbulb
VS Code has a complex and undocumented logic for presenting
Code Actions of various kinds in the user interface.
This CL documents the empirically observed behavior at
CodeActionKind.

Previously, users found that "nearly always available"
code actions such as "Inline call to f" were a distracting
source of lightbulb icons in the UI. This change suppresses
non-diagnostic-associated Code Actions (such as "Inline call")
when the CodeAction request does not have TriggerKind=Invoked.
(Invoked means the CodeAction request was caused by opening
a menu, as opposed to mere cursor motion.)

Also, rename BundleQuickFixes et al using "lazy" instead
of "quick" as QuickFix has a different special meaning
and lazy fixes do not necesarily have kind "quickfix"
(though all currently do).

Fixes golang/go#65167
Update golang/go#40438

Change-Id: I83563e1bb476e56a8404443d7e48b7c240bfa2e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587555
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-24 14:37:47 +00:00
Rob Findley 34db5bc3c8 gopls: initial support for godebug directive in go.mod and go.work
For now, incorporate godebug support by just updating x/mod and write
some tests. Diagnostics are mispositioned due to golang/go#67623.

While writing tests, I realized that the expect package still did not
support go.work files. Add this missing support. Also, remove a stale
comment from go.mod comment extraction, and simplify.

Fixes golang/go#67583

Change-Id: I9d9bb53824b8c817ee18f51a0cfca63842565513
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588055
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-24 13:57:01 +00:00
Alan Donovan 56f50e32fb gopls/doc: split codelenses out of settings
This CL splits codelenses.md out of settings.md, since
they aren't settings.

This reduces the indentation level of settings by one,
since we can dispense with a heading. Also, don't increase
the <h%d> nesting level for each level of nested dotted options:
ui.foo.bar should not be rendered smaller than ui.foo.
Use only h2 for groupings and h3 for settings.

Also:
- improve the introduction.
- add anchors for groupings.
- delete handwritten .md doc for obsolete newDiff setting.
- add TODOs for some existing bugs in the generator.

Change-Id: If6e7fff028b2c372e0d766d3d092bd0e41d61486
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586879
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-24 01:10:53 +00:00
Alan Donovan 3629652b9d gopls/internal/analysis/simplifyrange: suppress on range-over-func
go1.23's range-over-func currently requires all the vars be
declared, blank if necessary. That may change, but for now,
suppress the checker.

Fixes golang/go#67239
Updates golang/go#65236

Change-Id: I3e783fcfcb6a6f01f3acf62428cd9accbeb160c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588056
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
2024-05-24 00:39:57 +00:00
Hana (Hyang-Ah) Kim fb52877ad2 all: sync golang.org/x/telemetry@bda5523
Picks up bug fix CL 586098 and CL 586195.

Change-Id: Idc8b0c7f6b5202ae3ade4bcdf7349725a3c01eef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2024-05-22 19:28:01 +00:00
Hana (Hyang-Ah) Kim 4646dbf8ef gopls/internal/protocol: customize InsertReplaceEdit JSON unmarshal
InsertReplaceEdit is used instead of TextEdit in CompletionItem
in editors that support it. These two types are alike in appearance
but can be differentiated by the presence or absence of
certain properties. UnmarshalJSON of the sum type tries to
unmarshal as TextEdit only if unmarshal as InsertReplaceEdit fails.
Due to this similarity, unmarshal with the different type never fails.

Add a custom JSON unmarshaller for InsertReplaceEdit,
so it fails when the required fields are missing. That makes
Or_CompletionItem_textEdit decode TextEdit type correctly.

For golang/go#40871
For golang/go#61215

Change-Id: I62471fa973fa376cad5eb3934522ff21c14e3647
Reviewed-on: https://go-review.googlesource.com/c/tools/+/587135
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-22 18:44:40 +00:00
Alan Donovan bc5e086cf2 gopls/internal/golang: unexport several functions
All of these functions are no longer referenced across
packages since we cleaned up the server/lsprpc/golang split.

CanExtractVariable
EmbedDefinition
EnclosingStaticCall
FormatNodeFile
LinknameDefinition
CanExtractFunction

Updates golang/go#67573

Change-Id: I18490b333d79bad83eb5fcc34688fb41381771d1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586781
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-22 16:46:20 +00:00
Rob Findley 32cec11598 gopls/internal/test/integration: fix race in TestGCDetails_Toggle
The AfterChange predicate is insufficient for awaiting the GC details
command. We must await the specific diagnosis of GC details.

Fix the predicate, and update the documentation for AfterChange to more
clearly spell out what it awaits.

Fixes golang/go#67428

Change-Id: I4923a4dac773f2c953a21bf026cadca4b9370ef3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586878
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-21 16:24:46 +00:00
Alan Donovan c3aae998cf gopls/doc: tidy up analyzer documentation
Details:
- add introduction.
- change generator to put title in H2 heading,
  and add anchors.
- organize list of analyzers in gopls settings.
- fix typos.

Change-Id: Ie559a331a2ac51171c366104416d53a8329afe7c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586779
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-05-20 21:14:40 +00:00
Alan Donovan 41211c8b3a gopls/internal/golang: fix bug in freeRefs algorithm
The special case for dot imports was spuriously matching
struct field names from other packages.

+ regression test

Change-Id: Ib125e22f092b793007f6ee60d8e58890762c37a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586780
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-20 19:39:24 +00:00
Alan Donovan 788d39e776 gopls/internal/golang: "Show free symbols" code action
This change adds a new "Show free symbols" (source.freesymbols)
code action that reports the set of free symbols referenced by
the selected region of Go source. The HTML report, produced by
the /freerefs endpoint of gopls' web server, includes an
itemized list of symbols, and a color-annotated source listing.

Symbols are presented in three groups: imported symbols
(grouped by package); package-level symbols and local symbols.
Each symbol is a link to either the integrated doc viewer
(for imported symbols) or the declaration, for others.

The feature is visible in editors as:
- VS Code: Source actions... > Show free references
- Emacs+eglot: M-x go-freesymbols
  (Requires (eglot--code-action go-freerefs "source.freesymbols")
   until dominikh/go-mode.el#436 is resolved.)

There are a number of opportunities for factoring in common
with RenderPackageDoc; they will be dealt with in a follow-up.

Also:
- a unit test of the freeRefs algorithm;
- an integration test of the web interaction.
- release notes.

Change-Id: I97de76686fcc28e445a72e7c611673c47e467dfd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/539663
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-20 17:25:18 +00:00
Rob Findley f73683ea39 gopls/internal/golang: remove test debugging aix-ppc64 issue
Remove TestHoverLit_Issue65072 now that the aix-ppc64 bug is confirmed
and reported. Instead, update the note for the conditionally skipped
basiclit.txt.

Updates golang/go#67526

Change-Id: Id7dd54006e015ac6d8c06c0abe022d77826f71b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586777
Reviewed-by: Peter Weinberger <pjw@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-20 15:58:16 +00:00
Alan Donovan 0b4dca13e9 gopls/internal/protocol: separate CodeLens from Command; document
Historically, CodeLenses were identified in the UI (LSP, CLI, docs)
by the command.Command that they return, but this is confusing
and potentially ambiguous as a single lens algorithm may offer
many commands, potentially overlapping.

This change establishes a separate CodeLensKind identifier for
them. The actual string values must remain unchanged to avoid
breaking users.

The documentation generator now uses the doc comments attached
to these CodeLensKind enum declarations. I have updated and
elaborated the documentation for each one.

Change-Id: I4a331930ca6a22b85150615e87ee79a66434ebe3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586175
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-17 21:14:34 +00:00
Rob Findley 8cf8c6f7fa internal/test/integration: materialize startedWork and completedWork
While benchmarking, I noticed that the didChange benchmarks become much
slower on successive runs in the same session (-count=10), despite using
the same amount of server-side CPU per operation. Investigation revealed
that this was due to the time spent client side repeatedly counting
started work items. That predicate initially assumed a small number of
operations, but for benchmarks there will be tens or hundreds of
thousands of work items, as the didChange benchmarks run fast and share
a common session.

Fix this by materializing the startedWork and completedWork maps.

Change-Id: I4e96648cfd0f5af2285a35891f43a77143798856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586455
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-05-17 20:25:29 +00:00
Alan Donovan de1032b143 gopls: remove dead code
Change-Id: I0ce7ee99e92d0442765d47bce60a251daa8a26dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586261
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-17 17:09:11 +00:00
cuishuang 499663eff7 all: fix function names in comment
Change-Id: I70517b1b17b4ee3243e85de2701195a2531d67e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586335
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2024-05-17 16:49:08 +00:00
Rob Findley c184dd7db2 internal/test/marker: skip basiclit.txt on ppc64
This test was flaking in a bizarre manner on the aix-ppc64 builder. The
x/text/unicode/runenames package apparently returns a different name for
U+2211.

Since aix-ppc64 is not a first class port, skip to de-flake. However,
the failure mode is so bizarre that I added a unit test in the golang
package to try to reproduce the bug using only the x/text module. If
this new unit test also flakes, I will file a bug against aix-ppc64 and
x/text.

Fixes golang/go#65072

Change-Id: I99a6b60c7fd31b474e0b670e6f26e550de176ba8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586260
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2024-05-17 16:36:34 +00:00
Rob Findley 1f300c9005 gopls: upgrade x/telemetry to pick up CL 586195
Fixes golang/go#67430

Change-Id: I782ef6d06725686e089ae37cc1fceedd02a95f54
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586176
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-05-16 21:21:58 +00:00
Rob Findley fd7deae55c gopls/internal/test/marker: fix analyzers.txt test that requires cgo
Fixes golang/go#67429

Change-Id: Id09da732a336a22b20da33136329fbea65ebdfc6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/586096
Auto-Submit: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-05-16 18:16:29 +00:00
Alan Donovan af36634869 gopls/internal/protocol: rename DocumentChange{s,}
DocumentChange is a singular thing: a sum of four cases.
It is the element type of the WorkspaceEdit.DocumentChanges
slice field.

(The formatting of this type seen in
https://github.com/golang/tools/blob/gopls-release-branch.0.15/gopls/doc/commands.md#apply-a-fix
and commented on in CL 585277 is a consequence of structDoc
in gopls/doc/generate/generate.go; it remains unchanged.)

Change-Id: Idcd766a8a9c3228e5c43929fbf5dd6795ee7d301
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585975
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-16 17:28:08 +00:00
Alan Donovan 42d564ad64 gopls: support four kinds of DocumentChanges
The DocumentChange(s) type [which I will refer to in the
singular since the plural is a misnomer] is a sum of
four cases: edit, create, delete, rename. Historically
we have only supported edit, but new refactoring tools
(incl. the external contribution of "extract to new file"
in CL 565895) need broader support. This CL adds it.

There are three client implementations of ApplyEdit:
- The CLI tool (cmd) writes and/or displays the diff
  to the file;
- The integration test framework applies the changes
  to the Editor; and
- The marker test framework gathers the resulting
  file contents in a map without mutating the editor.
There doesn't appear to be a simple generalization,
but all three now signpost each other.

Also:
- remove the integration with Awaiter, which was unneeded.
- re-reorganize the protocol.WorkspaceEdit helper functions,
  undoing some of the (over)simplification of my recent CL 583315.

Change-Id: If2fd3560024e64e127c86d5fb220f4124a3f8663
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585277
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-16 17:26:26 +00:00
Alan Donovan b92578a596 x/tools: update to x/telemetry@9ff3ad9
Updates golang/go#67182

Change-Id: If9a225a0058c4c837b90238f993ac0d68783ca3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585821
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2024-05-15 22:01:09 +00:00
Alan Donovan 987af8bd35 x/tools: update to x/telemetry@ac8fed8
Updates golang/go#67182

Change-Id: I63e115eabb0e6780942add3e60c9a3cb147371be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585835
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-15 19:31:07 +00:00
Alan Donovan 069435cd8c gopls/internal/cache: use 1 not 0 for missing line/col info
This change causes the parser of go list error messages to
fill in 1, not 0, for missing line/column information, as
those are the correct values for this particular representation
(1-based UTF-8).

Also, report a bug if we see non-positive arguments to LineCol8Position.

Plus, a regression test.

Fixes golang/go#67360

Change-Id: I87635b99c8b13056c4816b58106ec4a29a9ceb9e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/585555
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2024-05-15 18:55:57 +00:00
Alan Donovan 528484d5f6 gopls/internal/cache: support overlays
This change causes go commands executed by the snapshot
to set the -overlay=... flag to a file describing
the unsaved editor buffers of the snapshot. (Previously,
this was done only for the main metadata load via
packages.Load.)

We factor the WriteOverlays logic from go/packages/golist.go
into internal/gocommand and use it from Snapshot.goCommandInvocation.
The cleanup logic has been cleaned up.

The ToggleGCDetails feature was an example of a command
that had a needless "file save required" restriction even
though the underlying machinery (go build) is overlay-aware.
This change removes that restriction and adds a test that
the feature works on unsaved editor buffers.

Another one is Tidy, for which I have also removed the
restriction and added a test.

(This is what happens when you try to write down a list of
all gopls features for documentation purposes...)

Change-Id: I801e3a9c7c27f6b63efaaa1257fcca37e6fafa4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/582937
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-15 17:13:51 +00:00
Alan Donovan 2e17129d72 gopls/doc/generate: add link anchors to each setting
Also, document how Options declarations become LSP-visible
settings and documentation in settings.md.

Change-Id: I5b47214ce1e07de8257ee6555fb82b3bc43c1629
Reviewed-on: https://go-review.googlesource.com/c/tools/+/584407
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-15 16:43:57 +00:00
Alan Donovan ab7bc6c424 gopls: further minor generator simplifications
gopls/doc: simplify and clarify the generator, inlining various
single-use helpers that used to be spread across packages.
Document the main pieces.

gopls/internal/protocol/command: snip the unnecessary dependencies
on dynamic analysis (execution) of gopls logic. In other words,
the generator is now purely a static analysis of command.Interface,
and does not link in any part of gopls.

No changes to output.

Change-Id: I314508470a155725a36a36ce823202668d057fac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/584215
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-05-15 16:36:50 +00:00