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

2222 Коммитов

Автор SHA1 Сообщение Дата
Rob Findley 9dff42e52e gopls/internal/golang/extract: preserve comments in extracted block
Use printer.CommentedNode to preserve comments in function and method
extraction.

Fixes golang/go#50851

Change-Id: I7d8aa2683c980e613592f64646f8077952ea61be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629376
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:46 +00:00
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 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
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
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
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
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 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
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
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
xieyuschen 8a0e08fb12 gopls/doc: add missing doc link
Change-Id: I691a03d5d48bee2a38a074d623c192cbb7ff3bd6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626415
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: 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-11-08 14:46:21 +00:00
Rob Findley 61415bee33 gopls/internal/cache: guard against malformed paths in port.matches
It's possible that we may encounter the path inconsistency of
golang/go#67288 due to unclean or relative paths. Guard against this
with a new bug report.

For golang/go#67288

Change-Id: I37ac1f74334bcb9e955d75e436f74398c73f0acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/626015
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-07 22:10:23 +00:00
Rob Findley 9a89d3a985 internal/analysisinternal: avoid sub-token spans in TypeErrorEndPos
Avoid assigning end positions to type errors that are within the current
token (such as could happen in an import path). To test this, introduce
our first named argument in the marker tests: 'exact' for the @diag
marker.

Also, attempt to document the heuristic of TypeErrorEndPos.

Fixes golang/go#69505

Change-Id: If3cf82f241dd354d834a7dcbf24b7b3c59246911
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625916
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-11-07 22:10:20 +00:00
Alan Donovan ca2b41b3fd x/tools: use internal/expect instead of go/expect
The only remaining uses of go/expect are from packagestest.

Updates golang/go#70229

Change-Id: I5a8c835b761381747fbd3f936d261ed773b536e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625919
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-11-06 19:53:11 +00:00
xzb f1ae722a68 gopls/internal/semtok: change types.Named to types.Basic for iota, true, and false
Fixes golang/go#70219

Change-Id: I4aacfc8f55c2b9bae17b5012cc8967329849cc6c
GitHub-Last-Rev: 88ecf46921
GitHub-Pull-Request: golang/tools#541
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625895
Reviewed-by: 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>
Auto-Submit: Robert Findley <rfindley@google.com>
2024-11-06 18:15:25 +00:00
Rob Findley dba5486c2a gopls: update x/telemetry to pick up fix for countertest.ReadCounter
In CL 625496, countertest.ReadCounter was updated to read using mmap,
avoiding filesystem races that are causing flaky gopls tests.

Fixes golang/go#68659
Fixes golang/go#69132

Change-Id: I4a7a5b50a784f35a911e346a988966fb79dcf279
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625915
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-11-06 15:15:29 +00:00
Rob Findley 9d40727055 gopls/internal/server: don't interact with os.UserConfigDir from tests
This change makes it such that tests must set GOPLS_CONFIG_DIR if they
want to exercise behavior related to the telemetry prompt. Tests should
not interact with os.UserConfigDir.

Change-Id: I9f6dfdea2408f75085855a82fc50fad20cda82e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625795
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-11-05 21:41:32 +00:00
Rob Findley f1f7c26696 gopls/internal/cache: ensure GO111MODULE is unset in GOPATH tests
With GO111MODULE=on in the test environment, the GOPATH subtest of
TestZeroConfigAlgorithm was failing, since GO111MODULE=on invalidated
our detection of a GOPATH workspace. Fix the test environment.

Fixes golang/go#70196

Change-Id: Ia80a5a63d93842aef4b67ca419e1d27eb11573c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625515
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
2024-11-05 18:44:49 +00:00
Hongxiang Jiang 4f98d3f914 gopls/internal/golang: run testcases as subtests
Test case names displayed in subtest names instead of test
failure messages.

For golang/vscode-go#1594

Change-Id: Iab207cd9af0af99a036dc69a8b2230f12bf876fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/621816
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-11-05 17:37:37 +00:00
Hongxiang Jiang 6d27bba24a gopls/internal/golang: add testcase handling for func with error returns
This commit improves the handling of test cases for functions
that return an error as their last return value.

- A boolean field called "wantErr" is added to the test case
struct to indicate whether an error is expected.
- The error return value is now handled before comparing other
return values, ensuring correct error handling in test cases.

For golang/vscode-go#1594

Change-Id: Ib48f6b85b2fdad96cb7fb563b8bdbf17d692f569
Reviewed-on: https://go-review.googlesource.com/c/tools/+/623997
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-05 16:25:43 +00:00
Rob Findley e5417d7d9f gopls/internal/cache: log go env in TestZeroConfigAlgorithm
Add an additional log message to help diagnose the problem encountered
by a user in golang/go#70196.

For golang/go#70196

Change-Id: I8347d842d5a9327fa6797229bf64dc4407f7aa61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/625415
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-05 16:00:57 +00:00
Hongxiang Jiang 691997ad25 gopls/internal/golang: consolidate imports from both file in qualifier
This commit improves qualifier by consolidating imports from both the
main file (x.go) and its corresponding test file (x_test.go).

An imports map is used to track all import paths and their local
renames.  Imports from x_test.go are prioritized over x.go as gopls
is generating test in x_test.go.

This ensures that the generated qualifier correctly reflects any
necessary renames, improving accuracy and consistency.

For golang/vscode-go#1594

Change-Id: I457d5f22f7de4fe86006b57487f243494c8e7f6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/622320
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
2024-11-05 15:28:29 +00:00