Граф коммитов

8992 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley 8c3ba8c103 internal/refactor: undo variadic elimination during substitution
When substituting an argument that has been synthetically packed into a
composite literal expression, into the varadic argument of a call, we
can undo the variadic elimination and unpack the arguments into the
call.

Fixes golang/go#63717
Fixes golang/go#69441

Change-Id: I8a48664b2e6486ca492e03e233b8600473e9d1a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629136
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-20 19:06:21 +00:00
Rob Findley 3b0b264579 internal/refactor: handle qualified names in inlined assignments
Rewrite our call site processing of imports, to simplify, and so that we
can re-use the import lookup logic in the assignStmts strategy for the
purpose of writing out types.

A large TODO is included for a hypothetical refactoring of the inlining
logic that could formalize these types of interactions between call site
analysis and inlining strategy.

Fixes golang/go#65217

Change-Id: Ifd99ea14430deba3a03cdfb936b6edee9e81d0bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629435
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-20 19:05:51 +00:00
Rob Findley 9311800086 gopls/internal/test/marker: ignore diags in fixedbugs/issue59944.txt
go/types now (correctly) produces a diagnostic for this code.

For golang/go#59944

Change-Id: I858acbf4199171f6e6c98eb1286d037e89462018
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630117
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-11-20 19:04:54 +00:00
Alan Donovan c1aa79d3e2 gopls/internal/golang: fix gopls hover doc link
The hoverJSON.LinkPath field was incorrectly documented, and
the gopls links formed from it were invalid when a module
version was present. This CL fixes the URL logic.

The existing test covered the behavior, but the assertion
concealed a mistake.

Fixes golang/go#70453

Change-Id: If9a7d3e65dabff50c9f528d82df9de67a71c41d1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630077
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-20 18:09:13 +00:00
Hongxiang Jiang e751756721 internal/analysisinternal: unify zero value function to typesinternal
Refactors the ZeroExpr and ZeroString functions to provide more
consistent and correct handling of zero values for input types.

- Refactor: Unify similar switch case statements in both functions with
exception of types.Tuple. ZeroExpr panic due to the lack of a valid
ast.Expr representation.
- Fixing an issue where ZeroExpr returned nil for types.Array instead of
a composite literal.
- Adding support for type parameters in ZeroExpr, similar to ZeroString.
- Consolidating tests for both functions into TestZeroValue.

Change-Id: Ic77ae17ea091cf51bd4d4642186fe13093e0d461
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627604
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-20 16:07:55 +00:00
Peter Weinberger a2874818ed internal/imports: test Source for go mod cache
This CL provides an implementation of the Source interface to
use an index to the go module cache to satisfy imports.

There is also a test.

Change-Id: Ic931cb132fcf7253add7fc7faadd89726ee65567
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627235
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-20 12:37:14 +00:00
Alan Donovan 9387a3910c gopls/doc/contributing.md: update expectations
We are overwhelmed by contributions. This change updates
our expectations about CLs in an attempt to move more of
the discussion of the design and implementation plan into
the issue tracker. It also clarifies that we expect
review comments to be addressed.

Change-Id: Ibccd268d4f7d9b6daf256ac7c60b7fbd821e2a69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629755
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-11-19 20:34:34 +00:00
xzb e08fcf77c9 gopls/internal/analysis/undeclaredname: merge into CodeAction
This change removes the undeclaredname analyzer,
and instead computes it directly from the
protocol.QuickFix code action producer,
follow the same structure in CL 617035.

Also:
- include return types for undeclared function
- add basic return type test in missingfunction.txt,
the major functionality should be the same as
fromcall_returns.txt
- add more cases in TypesFromContext, and
corresponding tests.

Fixes golang/go#47558

Change-Id: Ic79cf2f07a3baee60631bf0b8f5c2b9f4f4393d0
GitHub-Last-Rev: 33b78d7997
GitHub-Pull-Request: golang/tools#538
Reviewed-on: https://go-review.googlesource.com/c/tools/+/623156
Reviewed-by: 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-11-19 15:17:08 +00:00
Rob Findley 0c01408d03 internal/refactor/inline: avoid binding decl for name used by other args
When inlining, a removed argument does not contain the last use of a
name if that name is also used by another arg that is referenced by the
callee. Implementing this logic improved a test case for
golang/go#65217.

For golang/go#65217

Change-Id: I486306f4ed57d759d5ab65bb390db5e81332d3ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629295
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 22:15:53 +00:00
Rob Findley 63e03c315d gopls/internal/test/marker: generalize codeaction with named args
Address a TODO to consolidate the three codeaction marks into one, by
using named arguments to provide an optional end location and one of
edit, result, or err.

Along the way, I accidentally nuked my golden files after doing quite a
lot of manual editing of the test cases. To restore them, implement a
heuristic I've wanted for a while: when running with -update, add new
golden files immediately after the first reference to them among test
files. This is the convention we've been using, but previously we'd have
to position the golden files manually.

Change-Id: Ie78f759045aa0c07817d4eb21672be63e51c5067
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627136
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 20:43:13 +00:00
Michael Anthony Knyszek acc2a7418d go/analysis/passes/copylock: enable unfortunate tests
CL 628435 moved and disabled these tests. This CL re-enables them for
the time when CL 627777 lands.

Change-Id: I16cb8d4c23db35fadaac94054183f26bba2449e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629235
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>
2024-11-18 19:30:32 +00:00
Tim King 39cb6f0e85 internal/facts: use alias type parameters and arguments during imports
Derived from https://go.dev/cl/603935.

Change-Id: I409347a5bdf2218450d06f688b4c13fd302b2a16
Reviewed-on: https://go-review.googlesource.com/c/tools/+/619416
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Tim King <taking@google.com>
2024-11-18 18:50:39 +00:00
Michael Anthony Knyszek 9b9871da30 go/analysis/passes/copylock: test for noCopy for sync Map, Mutex, Once
Right now the copylock tests check for details on these types that are
implementation details and/or have some other problem (a less useful
error message, or a false negative altogether).

CL 627777 modifies the sync package to attach explicit anonymous noCopy
fields on each of these types. This change updates the tests to match
that, which also helps with and/or resolves a couple issues with
copylock captured in the test suite.

Note: this change also temporarily disables a couple of the problematic
tests. In the next CL we'll re-enable them, once CL 627777 lands.

Change-Id: I100c71ea05b4f08595e37d0c8e81f9543abe7d74
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628435
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Tim King <taking@google.com>
2024-11-18 18:29:39 +00:00
Rob Findley a54bd37b10 gopls/internal/golang: don't try to inline dynamic calls
Gopls previously reported a bug when encountering a dynamic method
reference. Instead, we should just skip this reference when inlining all
calls.

Fixes golang/go#69896

Change-Id: Id6971e2a3eb79a94e76eecbfcefc44bec9040b8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628376
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 18:14:20 +00:00
Daniel McCarney 52eb446eff internal/imports: adjust TestStdlibSelfImports pkg
This commit switches the test to use crypto/rc4 instead of crypto/ecdsa.

The crypto.ecdsa package will soon be imported into the FIPS module,
producing an unexpected import of crypto/internal/fips/ecdsa by the
pre-existing test.

Instead, use the rc4 stdlib package. This won't be under consideration
for FIPS.

Change-Id: I87bcaa04efe1138aa80bf7ce88f0df74469daf4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629115
Reviewed-by: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2024-11-18 16:05:08 +00:00
Rob Findley b8ff201971 gopls/internal/cache: refine bug reports for inconsistent dep view
The most likely cause of an inconsistent view of a dependency is a
mismatching test variant. Refine the bug report to identify this case.

For golang/go#63822

Change-Id: I1334501be1ea55a43a49557ad2cb1d03178268cc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628495
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 16:03:08 +00:00
Tim King e59fd368eb go/ssa: use ZeroString unconditionally
Follow up to https://go.dev/cl/626537

Change-Id: Ib8dee860c5ca65ea3dab8ef68564f9fe46c74832
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628535
Reviewed-by: Robert Findley <rfindley@google.com>
Commit-Queue: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 01:38:32 +00:00
Rob Findley 60bc93d368 gopls/internal/cache: fix handling of cgo standalone files
It is not a bug for go/packages to return no packages for standalone
files, if they use cgo and cgo is disabled. There may also be other
scenarios where standalone packages are not produced. In any case,
downgrade the bug report to a normal error.

Also, fix the failing test to require cgo.

Fixes golang/go#70363
Fixes golang/go#70362

Change-Id: I2b8a8b3947e4d7ff6482279540638e13dc9de2b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628017
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 01:22:19 +00:00
Rob Findley ed19fc789a gopls/internal/test: synchronize notifications during commands
It turns out that in the jsonrcp2 package, call responses are
asynchronous to other notifications. Therefore, we must synchronize
tests using progress notifications.

Introduce a DelayMessages test option to reproduce these types of races.
(It worked for reproducing golang/go#70342.)

Fixes golang/go#70342

Change-Id: I4cfcd7675335694a47eaf1a2547be0301fc244c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627696
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-18 01:02:45 +00:00
Rob Findley 254baba677 gopls/internal/cache: failure to extract diagnostic fixes is an error
Although the LSP specifies that diagnostic data should be transmitted
unmodified to codeAction requests, we can't control whether clients
abide by this rule. Therefore, a failure to extract fixes should be
treated as a user-facing error, not a bug.

Fixes golang/go#68819

Change-Id: I57e629cf381ee1112d98d22e728449995679b05f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628237
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-15 16:16:26 +00:00
Rob Findley 56ec111057 gopls/internal/server: remove spurious Async in legacy RunGoVulncheck
In the partial rollback CL 627556, I failed to remove the call to
jsonrpc2.Async in RunGoVulncheck, which is now (once again) async to
request handling. This introduces a race, leading to a panic if the
handler responds before the call to Async.

Fixes golang/go#70355

Change-Id: I8b33599a3f62b82dc6acf9d9b3616194c0372b9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628236
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-15 16:15:30 +00:00
Rob Findley b1c39aa3b6 gopls/internal/cache: use a named bool type for allowNetwork
As suggested on CL 626715, using a named bool clarifies call sites.

Change-Id: Ie36f406dcca382c7edc277895826265ae9040ee2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/628235
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-14 23:38:11 +00:00
Rob Findley c043599d4e gopls/internal/protocol: add DocumentURI.DirPath
To simplify many callsites where we called filepath.Dir on uri.Path(),
introduce the DocumentURI.DirPath helper method. This clarified many
call sites, and could make it easier to optimize URI manipulation in the
future.

Change-Id: Icc64155b6bba631f9df5da5a05e3126c7cb7954b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-14 23:37:56 +00:00
Rob Findley 29f4edbc1a gopls/internal/cache: simplify usage of snapshot.GoCommandInvocation
The Snapshot.GoCommandInvocation API is a source of confusion, because
it passes in a gocommand.Invocation, performs arbitrary mutation, and
then passes it back to the caller (which may perform mutation on top).
Aside from the readability problems of this indirectness, this API can
lead to real bugs, for example if one of the mutations is incompatible
with another.

Furthermore, the fact that the GoCommandInvocation is the golden source
of information about the Go command environment leads to awkwardness and
redundant work. For example, to get the packages.Config we called
Snapshot.GoCommandInvocation, just to read env, working dir, and build
flags (and the now irrelevant ModFile and ModFlag). But
GoCommandInvocation wrote overlays, so we'd end up writing overlays
twice: once within the gopls layer, and then again in the go/packages go
list driver.

Simplify as follows:
- Pass in dir, verb, args, and env to GoCommandInvocation, to avoid
  passing around and mutating an Invocation.
- Extract the View.Env, which is a useful concept, and apply invocation
  env on top. Surveying existing use cases that this was correct, as all
  call sites expected their env not to be overwritten.
- Move Snapshot.config to load.go, where it belongs, and simplify not to
  depend on GoCommandInvocation.

Also add an additional test case for BenchmarkReload.

Change-Id: I8ae7a13a033360e0e7b0b24ff718b5a22123e99c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626715
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-11-14 23:37:48 +00:00
Alan Donovan 3c20e3f6cb gopls/internal/analysis/yield: analyzer for iterator (yield) mistakes
This analyzer detects failure to check the result of a call to
yield (which can cause a range loop to run beyond the sequence,
leading to a panic).

It is not always a mistake to ignore the
result of a call to yield; it depends on whether control can
reach another call to yield without checking that the first
call returned true. Consequently, this analyzer uses SSA
for control flow analysis.

We plan to add this analyzer to gopls before we promote it to vet.

+ test, relnote

Fixes golang/go#65795

Change-Id: I75fa272e2f546be0c2acb10a1978c82bc19db5bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/609617
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-14 19:44:45 +00:00
Rob Findley 221e94d05c gopls/internal/cache: id command-line-arguments packages using GoFiles
Previously, we were using the first CompiledGoFiles to disambiguate the
ID of command-line-arguments packages, but in the presence of cgo
preprocessing there can actually be multiple CompiledGoFiles, leading
to the bug report of golang/go#64557. Fix this by using GoFiles instead.

Fixes golang/go#64557

Change-Id: I3eff976d07da32db1f26ced69228af41a388d9a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627776
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-11-14 19:13:17 +00:00
Rob Findley 84e9c336ed gopls/internal/golang: more idiomatic result naming in extract
Use field names or type names for result variables names, if available.
Otherwise, use the same conventions for var naming as completion. If all
else fails, use 'result' rather than 'returnValue'.

For golang/go#66289

Change-Id: Ife1d5435f00d2c4930fad48e7373e987668139ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627775
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
2024-11-14 19:13:15 +00:00
Hongxiang Jiang 8bb5da33e4 gopls/internal/golang: special handling for input context.Context
- Read and determine whether the first input parameter of function
or constructor is a context.Context through package name and name
comparison.
- Call the function or constructor with context.Background() but
honor is there is any renaming in foo.go or foo_test.go.
- Fix the issue where the constructor param is added to function
or method call.

For golang/vscode-go#1594

Change-Id: Ic1d145e65bc4b7cb34f637bab8ebdeccd36a33f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627355
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-14 19:09:28 +00:00
Hongxiang Jiang b4332e09d1 gopls/internal/golang, go/ssa: remove unnamed input parameter
- Unnamed/blank parameters are now assigned zero values, as
   they are not referenced within the function body.
- The `zeroString` function has been moved from `go/ssa` to
  `internal/typesinternal` for better organization.
- Honor the input parameter name from the function signature.
- Input parameters from both consutrctor and target functions
  are flattened into the test case struct. Potential field
  name duplication is handled by introducing prefixes.

For golang/vscode-go#1594

Change-Id: I8b56d8f3e0f0432d4f9fe269cc7ba86ea46decfc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626537
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-14 19:09:26 +00:00
Rob Findley a8d0fa56db go/packages: call testenv.NeedsGoPackages for TestDirAndForTest
To be consistent with other tests, and fix the breakage on js/wasm,
skip TestDirAndForTest on incompatible platforms.

Fixes golang/go#70286

Change-Id: I6195005e39103bbff4b5bb9ff99a63247eb0e9c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627996
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2024-11-14 17:27:25 +00:00
Rob Findley 47a5f7d131 gopls/internal/golang: fix bad slice append in function extraction
With multiple return statements, a slice append would overwrite the
return values of earlier returns. Fix by using slices.Concat.

For golang/go#66289

Change-Id: Ib23bcb9ff297aa1ce9511c7ae54e692b14facca7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627537
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-14 15:42:56 +00:00
toad 5b5d57c857 gopls/codeaction: fix panic when removing unused parameters with syntax errors.
Fixes golang/go#70268

Change-Id: I46643e79fc5cc30dac16bf18ef085bae173774a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626895
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-14 15:14:23 +00:00
Rob Findley 025b812242 gopls/internal/server: don't call window/showDocument if unsupported
Don't unconditionally call window/showDocument; check the client
capability. In the case of opening a browser window, use showMessage if
showDocument is unsupported.

Also somewhat clean up the way that we check for shown documents.

Fixes golang/go#68904

Change-Id: I29b281b615185f2bbda2f00e7c17575678177cd0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-13 23:15:23 +00:00
Hongxiang Jiang 288b9cb734 gopls/internal/golang: add missing imports in foo_test.go
- Gopls will honor any renaming of package "testing" if any.
- Gopls will collect all the package that have not been imported
in foo_test.go and modify the foo_test.go imports.

For golang/vscode-go#1594

Change-Id: Id6b87b6417a26f8e925582317e91fb4ebff4a0e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/620697
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-13 19:04:47 +00:00
Rob Findley 87ac91fb1f gopls/internal/server: revert the gopls.run_govulncheck command
As described in golang/vscode-go#3572 this CL reverts the behavior of
the gopls.run_govulncheck command to be asynchronous. Instead, we
introduce a new gopls.vulncheck command to run synchronously. We also
introduce a new "vulncheck" codelens setting to control the availability
of codelenses for this new command.

For expedience, the command handler is simply copied rather than
refactored, and minimal tests are added/modified to test the new
command. Hopefully we can migrate everything to the new command soon,
and delete the old command.

For golang/vscode-go#3572

Change-Id: Ib3cffd5fd038813680087fa1916127663f377581
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627556
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-11-13 18:29:24 +00:00
Rob Findley c531f1b303 gopls/internal/golang: avoid crash in hover on field of non-struct
Avoid a crash where types.Info.TyepOf(n) is assumed to be a non-nil
Struct for a StructType expr: this is not guaranteed in the presence of
type errors.

Unfortunately, I was not able to reproduce the crash after ~20m of
trying. Nevertheless, the existing code is making invalid assumptions.

Fixes golang/go#69150

Change-Id: I48abe9c134722db5c43f1c7c382b59e7632e367f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627135
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-12 18:46:03 +00:00
Ian Lance Taylor a37eeb4983 README: mention the git repo
Change-Id: Ia82717808152cc4f88c94ec58fe82f51dc95952d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625716
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-12 18:37:50 +00:00
Alan Donovan 8dd84a4a8d go/ssa/interp: assign phi nodes in parallel
This CL causes the interpreter to assign all phi nodes of a block
in parallel, as required by SSA semantics. Previously it would
execute them in order like real instructions, so that earlier
phis might clobber the environment values required as inputs
to later phis.

The phi handling is moved out of the ordinary visitInstr code
and into the block-entry logic, since all phis need to be
handled en bloc.

Also, a test, based on the user-reported problem in the attached
issue.

Fixes golang/go#69929

Change-Id: I12a61286b2151e2e72b642ca336e4ae31b7fa614
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621595
Reviewed-by: Matthew Dempsky <matthew@golang.org>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-12 18:11:11 +00:00
Peter Weinberger 12610a1270 internal/modindex: better behavior in edge cases
Write an index even if there is nothing in the module cache.

Change-Id: Ia98f8825d9914a0d4bd2ee9ff1bccf8519b91f37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-12 14:35:26 +00:00
Alan Donovan 06a498a7a3 go/ssa/interp: simplify output capturing
This CL uses the new output-capturing mechanism (via a pipe)
exclusively, eliminating two old mechanisms:
1) the CapturedOutput global var that was written by
   print and println; now those two functions just
   write to stderr, which is more faithful (than stdout).
2) TestRangeFunc called the interpreter in a subprocess
   so that it could capture output (via pipes), but
   that is no longer necessary; 'run' returns the captured
   output.

Also:
- t.Log the duration unconditionally; remove "if false" cruft.
- eliminate the unnecessary cwd arguments to filepath.Join.

Change-Id: Ib23f895fafecab059ecda60f73fb7082388f0240
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622416
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-11 21:46:03 +00:00
Alan Donovan b2321e7ac0 gopls/internal/golang: refine crash report golang/go#69362
This CL splits the various fallible checks that may have
been responsible for the crash report in golang/go#69362 onto
separate lines so that we can confirm whether a nil
map entry is indeed the cause. (I am almost certain that
it is, but I still can't explain it.)

Updates golang/go#69362

Change-Id: I0469e285bda65c21e80a348af04ea0e69f6a31c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/627015
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-11-11 20:47:12 +00:00
Hongxiang Jiang c8756776ec gopls/internal/golang: support add test for receiver w/o constructor
Gopls loops over all the function and find the ones qualifies based
on its signature.

- When a qualifying constructor is found, the test skeleton uses the
constructor to initialize the receiver and call the method.
- When no constructor is found, gopls generates a test skeleton with
a variable declaration using the receiver type (e.g., "var t T") and
includes a TODO comment to remind users to implement receiver variable
initialization.

For golang/vscode-go#1594

Change-Id: I2a703bbd099f03fd1bf85e516f86484805b4a0ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/620696
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-11 18:49:33 +00:00
Alan Donovan e26dff9fb9 gopls/internal/golang: semtok: use type information consistently
Previously there were two competing mechanisms for annotating
identifiers: the syntactic traversal and type information.
This meant that identifiers in different grammatical places
were annotated differently.

This change annotates identifiers using type information exclusively.
In addition to making things consistent, it also means that
types are reported independently (using modifiers) to symbol kind,
so, for example, a "var x func()" is a Variable with modifier
Signature, indicating that its type is a function.
Also, the rules for "defaultLibrary", "readonly", and so on
are more simply and consistently enforced.

The "deprecated" modifier is however lost as a consequence,
as it relied on the syntax.

+ Tests for both issues.

Also, use an enum for all the Modifiers.

Also, document the complete current set of token types
and modifiers that gopls returns.

Fixes golang/go#66809
Fixes golang/go#70251

Change-Id: I15e59d10f5a9269bc6be87f30e3502a9054d88e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626279
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-11 18:34:52 +00:00
xieyuschen fd8d0289c0 go/pacakges: remove some todos
* use std slices.Clip
* remove outdated check as the original issue was fixed

Change-Id: Ie54b202ecabc3318a4f20772fd62bd63542f8237
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626416
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-11 15:41:40 +00:00
Peter Weinberger 69c27ad360 gopls/internal/protocol: upgrade to latest LSP
We were on 3.17.6-next.2. This CL brings us up to next.9.

Aside from extending the Client and Server types, the change is
backwards compatible. There are additional fields in
ApplyWorkspaceEditParams, CodeLensClientCapabilities,
DiagnosticClientCapabilities, WorkspaceClientCapabilities,
WorkspaceOptions.

There are new types
ClientCodeLensResolveOptions, DiagnosticCapabilities,
SnippetTextEdit, TextDocumentContentClientCapabilities,
TextDocumentContentOptions, TextDocumentContentParams,
TextDocumentContentRefreshParams,TextDocumentContentRegistrationOptions,
WorkspaceEditMetadata.

There is a new SemanticTokenType "label" (LabelType).

Change-Id: I1a7c79252d4726ab4d95bca6c1244a02a7bb62da
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626095
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-11 14:12:59 +00:00
Hana (Hyang-Ah) Kim 25699c3720 internal/server: make MaybePromptForTelemetry no-op
For the transition of vscode go extension users who explicitly trigger
prompting using the command, make the command no-op if the telemetry
prompt setting is already true.

For golang/go#67821

Change-Id: I648c5a8e4449eeb15fb28c71879c967975363a79
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589836
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-08 19:43:26 +00:00
Rob Findley 35d7f2837a go/packages: add Dir and ForTest fields to Package
Add a new Dir field, and export ForTest, per golang/go#38445. The
needInternalForTest mode bit is promoted to NeedForTest, but no mode bit
is added for Dir as it is logically related to NeedFiles.

A test is added for the new fields using a simpler txtar-based setup,
since I did not have time to page in the quite heavyweight packagestest
framework.

For golang/go#38445

Change-Id: I92026462f7ed7e237db1f4e50a3bbf2936802fbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626495
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-08 18:44:44 +00:00
Gopher Robot 4d2b19f26d go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.

Change-Id: I9a6c0d0c4aeb4d35a39babf90d1fb031f1fb8527
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626516
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-08 16:44:01 +00:00
Rob Findley 636867761e gopls/internal/golang: strength reduce ComputeImportFixEdits
Simplify the API of ComputeOneImportFixEdits (renamed to
ComputeImportFixEdits), so that it can be used in more scenarios.

Change-Id: I4c4adb5f38947074dfb005e0c745d1a623bd3fd8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626280
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-08 16:27:52 +00:00
Rob Findley 777f155311 gopls/internal/golang: show package attributes on hover
When hovering over a package name in a package declaration, show
language version and GODEBUG values that differ from the toolchain
default. Also, for consistency with other hover content, show the
package declaration as the 'signature' of both a package name and an
import.

Finally, to help differentiate this information, introduce hlines in
the hover output between logical sections. This is similar to what is
done by other LSP servers such as tsserver.

Fixes golang/go#68900

Change-Id: I5013bb9fb4086c71cc3565fd67993764cad69237
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626276
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-11-08 14:51:24 +00:00