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

9001 Коммитов

Автор SHA1 Сообщение Дата
Alan Donovan 68caf84fca gopls/internal/golang: don't lose ... when split/joining variadics
We wrap the last argument f(x...) in an explicit Ellipsis
to record that it was a variadic call, and add the "..."
back with corresponding logic when creating the edits.

Fixes golang/go#70519

Change-Id: I1fdfa5f3ccb000c9622f856ed7703b31d7911620
Reviewed-on: https://go-review.googlesource.com/c/tools/+/631335
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-22 19:34:02 +00:00
Alan Donovan 1e0d4ee6a4 go/analysis/checker: disable Example on wasm
packages.Load needs os.Pipe.

Fixes golang/go#70502

Change-Id: I4fd5c0a0a4e2d76fdda24d474e9f0465462d649a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630677
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
2024-11-21 19:41:32 +00:00
Rob Findley 8b6e84ba2a gopls/internal/crash: don't crash in xrefs on out of bound nodes
As we've seen many times, it is currently (unfortunately) possible that
go/ast nodes exceed the bounds of the parsed file. Handle this
possibility correctly while building the xrefs index.

Updates golang/go#66683
Fixes golang/go#70446

Change-Id: If6364876eb7b8ed8ca11a058417aa028d6b55b41
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630675
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-21 18:47:22 +00:00
Hongxiang Jiang 936a401052 gopls/internal/golang: preserve copyright and build constraint
- This commit updates addTest and extractToFile to preserve
copyright and build constraint comments when creating new files.
- The change introduces utility functions to extract these comments
from an ast.File.

For golang/vscode-go#1594

Change-Id: I2b2f70d6d4de662c8357bca8558c094496c8b2e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/629756
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-21 18:23:17 +00:00
Rob Findley 1ffc3a165d gopls/internal/test/marker: add defloc, to bind positions by definition
Address a long-standing TODO in the marker tests by adding a new value
marker @defloc, which binds a name to the result of a definition
request.

Also
- more documentation improvements
- add support for formatting positions outside of the test archive
- refactor location formatting, to better handle external locations

Change-Id: I33e0d0e1a5d6d58cd83c62b8ad9b50e147077e2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630555
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-21 17:56:56 +00:00
Rob Findley 442d6be71a gopls/internal/test/marker: document named parameters
Update our marker test documentation to discuss the recently added
support for named parameters. Also, make a few other superficial doc
improvements (notably, adding missing documentation for
-{min,max}_go_command).

Change-Id: Ib210443fc4afbb1420345a17ec5b1eed75687c04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630138
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2024-11-21 17:56:47 +00:00
Alan Donovan ae39b133ca go/analysis/checker: a go/packages-based driver library
The {single,multi}checker packages provide the main function
for a complete application, as a black box. Many users want
the ability to customize the analyzer behavior with additional
logic, as described in the attached issues.

This change creates a new package, go/analysis/checker, that
exposes an Analyze pure function---one that avoids global flags,
os.Exit, logging, profiling, and other side effects---that
runs a set of analyzers on a set of packages loaded (by the
client) using go/packages, and presents the graph of results
in a form that allows postprocessing.

  package checker

  func Analyze([]*analysis.Analyzer, []*packages.Package, *Options) (*Graph, error)
  type Graph struct {
	Roots []*Action
  }
  type Action struct { ... } // information about each step

  func (*Graph) WriteJSONDiagnostics(io.Writer) error
  func (*Graph) WriteTextDiagnostics(io.Writer, contextLines int) error
  func (*Graph) All() iter.Seq[*Action] // (was Visit in the proposal)

See the example_test.go file for typical API usage.
API feedback welcome.

This change should have no effect on the behavior of
existing programs. Logic changes have been kept to a
minimum, so the large diffs are mostly code motion.
Auxiliary functions for printing, flags, fixes,
and so on has been kept to a minimum so that we
can make progress on this change.
They will be dealt with in follow-up changes.

Detailed list of changes to ease review:

analysistest:
- Run: we report Load errors to t.Log up front
  (unless RunDespiteErrors); this was previously in loadPackages.
- Run: the Validate call is now done by checker.Analyze.
- internal/checker.TestAnalyzer has melted away
- the logic to construct the "legacy" Result slice is new.
- Result: this type used to be an alias for
  internal/checker.checker.TestAnalyzerResult (regrettably
  exposing more than intended); now it is a plain public struct.
- check: the logic to check fact expectations is new.
- The buildtag and directive analyzers both used a similar
  hack w.r.t. IgnoredFiles; this hack is now in analysistest.
  Better ideas welcome.

checker:
- checker.go is mostly moved from internal/checker/checker.go.
- print.go is mostly split from old printDiagnostics in
  internal/checker/checker.go.
- Action.execOnce: the pass.Result/Err logic was simplified
  using an immediately-applied lambda.
- inheritFacts: the comments on package-fact handling are new.
- Graph.Visit is "born deprecated".
  Clients using go1.23 should use Graph.All (iter.Seq).
- Example: this is new code.

internal/checker:
- applyFixes: now accepts only the actions to apply, without
  calling visitAll over the action graph.
  The previous code was wrong, a latent bug.

Some files outside go/analysis were updated, not out of
necessity (it's not a breaking change) but to modernize
them (e.g. avoiding analysistest.Result.Pass).

Updates golang/go#61324		(new API proposal)
Fixes golang/go#53215		(feature proposal)
Fixes golang/go#31897
Fixes golang/go#50265
Fixes golang/go#53336
Fixes golang/go#66745
Updates golang/go#30231
Updates golang/go#30219
Updates golang/go#31007
Updates golang/go#66745

Change-Id: I745d319a587dca506564a4624b52a7f1eb5f4751
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411907
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-21 17:41:50 +00:00
xieyuschen c3a6283c06 go/packages: undeprecate Load* style flags
Updates golang/go#70470

Change-Id: Ia254b993b301fcc708d07b3773fad31a971c5997
Reviewed-on: https://go-review.googlesource.com/c/tools/+/630435
Reviewed-by: Robert Findley <rfindley@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-11-21 14:48:27 +00:00
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 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