Commit Graph

6926 Commits

Author SHA1 Message Date
wdvxdr 8166dca1ce go/analysis/passes/asmdecl: define register-ABI result registers for RISCV64
Change-Id: I7f88d31186704a7d83637acdf127e0522d725289
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443575
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-24 03:44:30 +00:00
David Chase 2dcdbd43ac go/internal/gcimporter: port CL 431495 to tools, add tests
Changes to the export format need to be ported here too;
added the tests that check for this bug.

Notable changes to the copypasta -- there were name clashes
between locally defined types and some new imports, resolved
with import renaming.

Change-Id: Ie7149595f65e91581e963ae4fe871d29fb98f4c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444235
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-10-21 20:44:30 +00:00
cuiweixie d476af7108 go/ssa: add slice to array conversion
For golang/go#46505

Change-Id: I642409e383c851277845b37dd8423dc673c12a8b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/433816
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-21 17:52:53 +00:00
Alan Donovan d212f7d04f gopls/internal/regtest/workspace: fix bugs in test
The test had a missing import of "fmt" that is somehow
ignored by the current analysis implementation (but was
flagged as an error by my pending redesign).

Add the import, and update the go.sum hashes.

Change-Id: I6dd91b2863a7cbd0f16018151c942867bddc92e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444795
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-21 15:44:01 +00:00
Alan Donovan 051f03f2c9 gopls/internal/lsp/cache: remove unnecessary params
The Context arg to missingPkgError was unused.

Also, simplify Sprintf + Write -> Fprintf.
Also, add missing newline to error message.

Change-Id: I1728fa5029b2da398fdb5b606c8381256b87276b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444775
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-21 15:43:15 +00:00
Alan Donovan 21f61277b0 gopls/internal/lsp/cache: add PkgPath->PackageID index to Metadata
DepsBy{Pkg,Imp}Path are two different ways to look up the PackageID
of a direct dependency. (We need both.)

MissingDeps is now represented as a blank value in DepsByImpPath.

Also try to make sense of MissingDependencies.
(The deleted pkg.types==nil condition was provably false.)

Change-Id: I6a04c69d3d97b3d78b77d4934592735bb941d05f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444538
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-20 21:54:57 +00:00
Robert Findley 06041c93ef gopls/doc: update manual documentation of the newDiff setting
Because we normally suppress internal options, the documentation for
this setting is managed manually, and was stale. Update it, and bring it
in-line with the actual setting docstring.

Change-Id: Id3ceaa7303df4ee2a6bf07c54d087451169962cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444539
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-10-20 20:54:24 +00:00
Heschi Kreinick f112c43328 go.mod: update golang.org/x dependencies
Update golang.org/x dependencies to their latest tagged versions.
Once this CL is submitted, and post-submit testing succeeds on all
first-class ports across all supported Go versions, this repository
will be tagged with its next minor version.

Change-Id: Ic6643ddc8dc991da1e6817b994390c38ef9ed231
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444536
Auto-Submit: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-20 20:04:29 +00:00
Alan Donovan 207f456f2d go/internal/gcimporter: bump version number in skew check
This constant controls the "version skew" warning printed
in case of panic, but doesn't control the version that is
actually accepted, which is currently v2.

Also, clarify meaning of 'path' parameter. The subtle
difference between "package path" (linker symbol prefix,
which may have "vendor/" prefix) and "import path" (string
literal appearing in import declaration, sans "vendor/")
is a pervasive source of bugs in gopls' handling of vendored
packages.

Change-Id: I8c3001a23b84abb1f18d861e01334bb3f0a5c27a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444537
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-20 19:01:47 +00:00
Robert Findley 65196caeed gopls/README.md: fix wording around supported Go versions
Change-Id: I25eb83edc5fca0958833371d2d4a6c28af6c21c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444175
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-20 18:01:13 +00:00
Robert Findley 61280309af gopls/internal: support renaming packages with int. test variants
We need to search intermediate test variants to find all imports of a
renamed package, but were missing them because we only considered
"active packages". Fix this by building up the set of renamed packages
based on metadata alone: it is unnecessary and potentially too costly to
request all (typechecked) known packages, when we only need access to
the metadata graph to determine which packages must be renamed.

In doing so, it becomes possible that we produce duplicate edits by
renaming through a test variant. Avoid this by keeping track of import
path changes that we have already processed.

While at it, add a few more checks for package renaming:
 - check for valid identifiers
 - disallow renaming x_test packages
 - disallow renaming to x_test packages

Also refactor package renaming slightly to pass around an edit map. This
fixes a bug where nested import paths were not renamed in the original
renaming package.

Fix some testing bugs that were exercised by new tests.

For golang/go#41567

Change-Id: I18ab442b33a3ee5bf527f078dcaa81d47f0220c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443637
Reviewed-by: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-20 17:36:38 +00:00
Heschi Kreinick 649df2ea1a go.mod: mark as requiring -compat 1.16
When the tagging process runs go mod tidy it needs to pass -compat 1.16.
This magic comment will cause it to do so. See CL 443857.

For golang/go#48523.

Change-Id: I6824a2c78462604b9d4737444b4d16d4c21ecc99
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444295
Auto-Submit: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-20 17:00:14 +00:00
Alan Donovan 91311ab3b8 gopls/internal/lsp/cache: better import path hygiene
An import path is not the same as a package path.
For example, the declaration:
   import "example.com/foo"
may load a package whose PkgPath() is "vendor/example.com/foo".
There was a comment hinting at this in load.go.

This change introduces the concept of ImportPath as a
distinct type from PackagePath, and documents clearly
throughout the relevant APIs which one is expected.

Notes:
- Metadata.PkgPath is consistently set from the PackagePath,
  not sometimes (when a root) from PackagePath and sometimes (when
  indirectly loaded) from an arbitrary ImportPath that resolves to it.
  I expect this means some packages will now (correctly)
  appear to be called "vendor/example.com/foo"
  in the user interface where previously the vendor prefix was omitted.
- Metadata.Deps is gone.
- Metadata.Imports is a new map from ImportPath to ID.
- Metadata.MissingDeps is now a set of ImportPath.
- the package loading key is now based on a hash of
  unique imports. (Duplicates would cancel out.)
- The ImporterFunc no longer needs the guesswork of
  resolveImportPath, since 'go list' already told us
  the correct answer.
- Package.GetImport is renamed DirectDep(packagePath)
  to avoid the suggestion that it accepts an ImportPath.
- Package.ResolveImportPath is the analogous method
  for import paths. Most clients seem to want this.

Change-Id: I4999709120fff4663ba8669358fe149f1626bb8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443636
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-19 21:54:36 +00:00
Michael Matloob 9eda97bc2d go/analysis: enable a test that applies after go list behavior change
The despite-error case in TestRunDespiteErrors only returns error code 1
after golang.org/cl/437298. This CL enables the test for Go 1.20+.

Change-Id: Ib212026d595e7bf872aa2482e1d91723010e7018
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441880
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-19 20:55:33 +00:00
Robert Findley b50d7ba6ee gopls: minor cleanup of standalone package support
Remove an unused err value, and update tests to exercise multiple
standaloneTags.

Change-Id: I88daace99111cba6f8bc74fad8aa0db844cb2654
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442776
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-10-19 19:08:58 +00:00
Robert Findley 502b93c33e gopls/internal/lsp: tolerate missing end position in RelatedInformation
Fix the panic reported in #56270, allowing RelatedInformation.End to be
missing.

Fixes golang/go#56270

Change-Id: I5f2dc27cf149c324f39ddbb056862434fe38f730
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443337
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-10-19 18:04:39 +00:00
Peter Weinberger d67c3ada09 internal/imports: repair warnings from default analyzers
Some of the analyzers that are on by default in gopls produce many distracting
warnings. These are 'composites' and 'simplifycompositelit'.

This CL changes code to remove the 160 or so warnings.

An alternative would be to remove these from the default set of gopls analyzers.

Change-Id: Id5724a5aef260939dedd21a37e28f3d05bfa023d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443635
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-19 15:24:07 +00:00
Bryan C. Mills bc2e3aeaba internal/jsonrpc2_v2: add Func convenience wrappers for the Binder and Preempter interfaces
Change-Id: Ib21dabb908c13d9bbf50f053a342a8644d3ee68b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388596
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-18 21:38:33 +00:00
Keith Randall a9b653b411 cmd/compilebench: use -a instead of -i to ensure dependencies are built
-i has been deprecated since 1.15, and is now gone in the soon-to-be-1.20.

Change-Id: Ib570f2bcfd0b1feb937990b72e4c9e43e1ada8cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443456
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
2022-10-18 15:43:22 +00:00
Robert Findley 4818d9eec9 Revert "gopls/internal/lsp/cache: disable strict analysis while we fix panics"
This reverts commit 9b5e55b1a7.

Reason for revert: Should have been fixed by https://go.dev/cl/443100

Change-Id: I44eeff6605697b745c3729ac1ec49b9c09114f71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443340
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-18 14:49:53 +00:00
Bryan C. Mills b2efd4d155 internal/jsonrpc2_v2: eliminate most arbitrary timeouts in tests
For golang/go#46047
For golang/go#49387
For golang/go#46520

Change-Id: Ib72863a024d74f45c70a6cb53482cb606510f7e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388598
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-10-17 20:15:06 +00:00
Bryan C. Mills 371ef162f2 internal/jsonrpc2_v2: rework concurrency in idleListener
This eliminates a race between a successful Accept call and a
concurrent Close call, which previously could have shut down the
'run' goroutine before Accept sent to the newConns channel, causing
Accept to deadlock.

In fact, it eliminates the long-running 'run' goroutine entirely
(replacing it with a time.Timer), and in the process avoids leaking
O(N) closed connections when only the very first one is long-lived.

It also eliminates a potential double-Close bug: if the run method had
called l.wrapped.Close due to an idle timeout, a subsequent call to
Close would invoke l.wrapped.Close again. The io.Closer method
explicitly documents doubled Close calls as undefined behavior, and
many Closer implementations (especially test fakes) panic or deadlock
in that case.

It also eliminates a timer leak if the Listener rapidly oscillates
between active and idle: previously the implementation used
time.After, but it now uses an explicit time.Timer which can be
stopped (and garbage-collected) when the listener becomes active.

Idleness is now tracked based on the connection's Close method rather
than Read: we have no guarantee in general that a caller will ever
actually invoke Read (if, for example, they Close the connection as
soon as it is dialed), but we can reasonably expect a caller to at
least try to ensure that Close is always called.

We now also verify, using a finalizer on a best-effort basis, that the
Close method on each connection is called. We use the finalizer to
verify the Close call — rather than to close the connection implicitly
— because closing the connection in a finalizer would delay the start
of the idle timer by an arbitrary and unbounded duration after the
last connection is actually no longer in use.

Fixes golang/go#46047.
Fixes golang/go#51435.
For golang/go#46520.
For golang/go#49387.

Change-Id: If173a3ed7a44aff14734b72c8340122e8d020f26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388597
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-17 20:15:04 +00:00
Bryan C. Mills 5935531253 internal/jsonrpc2_v2: remove “Box” suffix from channel field names
With the suffixes I end up a little lost in the “box” noise while I'm
reading — the channel ops alone suffice to make the storage mechanism
clear.

(To me, the mechanism of storing a value in a 1-buffered channel is
conceptually similar to storing it in a pointer, atomic.Pointer, or
similar — and we don't generally name those with a suffix either.)

For golang/go#46047.
For golang/go#46520.
For golang/go#49387.

Change-Id: I7f58a9ac532f597fe49ed70606d89bd8cbe33b55
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443355
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-17 20:13:30 +00:00
Bryan C. Mills fd32990e09 internal/jsonrpc2_v2: error out in-flight client calls when the reader breaks
Otherwise, the Await method on the corresponding AsyncCall will never
unblock, leading to a deadlock (detected by the test changes in
CL 388597).

For golang/go#46047
For golang/go#46520
For golang/go#49387

Change-Id: I7954f80786059772ddd7f8c98d8752d56d074919
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388775
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 19:48:19 +00:00
Bryan C. Mills 0e222f5c6f internal/jsonrpc2_v2: close the underlying connection if Wait is called instead of Close
(*Server).run calls Wait on all of its connections before returning,
but does not call Close explicitly. If Close is necessary to
release resources (as is often the case for a net.Conn),
the server ends up leaking resources.

For golang/go#46047

Change-Id: I4ad048c4f5e5d3f14f992eee6388acd42398c26b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388599
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-17 19:48:17 +00:00
Alan Donovan bc4e384f85 gopls/internal/lsp/cache: fix crash in analysis
Since we removed the 'recover' in analysis, which swept crash
bugs under the rug, we've seen a large number of crashes on
the builders in which an analyzer crashes while trying
to use the result of another analyzer (e.g. the inspector)
on the same package. Logging shows that the "same" package
is in fact a stale version of the same package.

The root cause is that the key for the analysis cache
is the analyzer name paired with the "recipe" for the
package. However, analysis is not content with an equivalent
package: identity matters for ast.Nodes, types.Objects, etc.

This change attemps to fix the problem by, in effect, using
the identity (not the recipe) of the package as part of the key.
It is materialized by adding a store of promises to the pkg,
and then using the analysis name as the key within this store.

Change-Id: I057807d2781492a685f27c815250c3445e7475f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443100
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 17:58:19 +00:00
Robert Findley b93a56f289 refactor/satisfy: fix visiting functions in the unsafe package
Unlike other calls of qualified functions, the type of certain functions
in the unsafe package (namely Slice, Add) is not constant, and cannot be
determined by the types.Func being called. Update Finder.expr to
pre-emptively handle calls to functions in the unsafe package, similarly
to how it handles other builtins.

Fixes golang/go#56227

Change-Id: I7af51c1ecacbdf35e39c8e7b8273ffe6f953427f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443096
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17 12:57:23 +00:00
Robert Findley 9b5e55b1a7 gopls/internal/lsp/cache: disable strict analysis while we fix panics
We now understand the longstanding race causing panics in gopls analysis
(the cache key for analysis handles is not correct, and can lead to
cache hits for analysis of stale packages).

It will take a little while to redesign our analysis caching, the
simplest solution being to hang analysis results off of the actual
package they are analyzing. In the meantime, suppress the panic as
before, to eliminate flakes.

For golang/go#55201
For golang/go#56035

Change-Id: I96600f186f9f31b67dae10c0a95a14fa73630571
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442794
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-15 19:01:56 +00:00
Alan Donovan 9ffaf69c2c gopls/internal/lsp/cache: minor analysis cleanups
This change moves the *pkg out of the actionHandle into
the actionResult. (In future we may not need to load the
package before creating the handle.) The actionResult
retains only the exported type information, to avoid keeping
the syntax trees (etc) live.

Also, perform object fact filtering once after the analysis pass,
instead of every time it is imported by another analysis.
Also, filter out unexported constants.

Also, log internal errors even when we don't bug.Reportf,
since errors merely returned by analysis are usually ignored,
making it harder to understand the analysis crashes.

Change-Id: I7257e8da5dc269090bff2817409948e46dcf7176
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442556
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-13 20:55:24 +00:00
Robert Findley ffb862b544 gopls/internal/lsp/cache: remove stray print statement
A stray print statement was accidentally left in CL 441877. Remove it.

Change-Id: I44e4408059f30d35ad8c84b070aea3e197762d1c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442782
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-13 17:41:26 +00:00
Charlie Vieth f87c1ed972 internal/fastwalk: improve Darwin performance by ~3x
On darwin/cgo use readdir_r instead of syscall.ReadDirent() since the
later is simulated and slow (see: golang/go#30933).

Unlike CL 392094, this uses CGO instead of "//go:linkname" and assembly.

goos: darwin
goarch: arm64

FastWalk-10    68.9ms ±11%    20.7ms ± 2%  -69.89%  (p=0.008 n=5+5)

name         old alloc/op   new alloc/op   delta
FastWalk-10    1.49MB ± 0%    1.51MB ± 0%   +1.06%  (p=0.008 n=5+5)

name         old allocs/op  new allocs/op  delta
FastWalk-10     32.2k ± 0%     30.7k ± 0%   -4.61%  (p=0.016 n=5+4)

Fixes golang/go#51356

Change-Id: Ia3afd06c8f14bd2036b2a1ea6e3cafbef81d3530
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436780
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-13 16:31:57 +00:00
Robert Findley b2533141c6 gopls/internal/lsp/cache: add support for loading standalone main files
Add support in gopls for working on "standalone main files", which are
Go source files that should be treated as standalone packages.
Standalone files are identified by a specific build tag, which may be
configured via the new standaloneTags setting. For example, it is common
to use the directive "//go:build ignore" to colocate standalone files
with other package files.

Specifically,
- add a new loadScope interface for use in snapshot.load, to add a bit
  of type safety
- add a new standaloneTags setting to allow configuring the set of build
  constraints that define standalone main files
- add an isStandaloneFile function that detects standalone files based
  on build constraints
- implement the loading of standalone files, by querying go/packages for
  the standalone file path
- rewrite getOrLoadIDsForURI, which had inconsistent behavior with
  respect to error handling and the experimentalUseInvalidMetadata
  setting
- update the WorkspaceSymbols handler to properly format
  command-line-arguments packages
- add regression tests for LSP behavior with standalone files, and for
  dynamic configuration of standalone files

Fixes golang/go#49657

Change-Id: I7b79257a984a87b67e476c32dec3c122f9bbc636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441877
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-13 15:07:40 +00:00
Alan Donovan 3beecff0f6 gopls/internal/span: some cleanups
This change eliminates these redundant helper functions
- cache.rangeFromPositions
- source.LineToRange
- source.ByteOffsetsToRange
and makes various other simplifications and documentation
improvements.

Change-Id: Ic820ab560d71b88bde00b005e3a919334a5d1856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442015
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-13 13:15:27 +00:00
Suzy Mueller d3752388a2 gopls: dedup upgrade code actions for vulncheck
Make sure we aren't sending multiple code actions
that do the same thing. This also adds a upgrade
to latest code action.

Change-Id: Ic9cecd0a9410648673d4afe63da5a940960a4afc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/436776
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2022-10-12 18:24:48 +00:00
Alan Yee b20ae4bcf7 README: format install command
Separate command into a separate line in order to make it easier to copy and paste into the terminal

Change-Id: I2e446475201c40ddb5054fe403ff23ed79b0742e
GitHub-Last-Rev: bbd650aa12415725168b59ec934aafeeaf0f21aa
GitHub-Pull-Request: golang/tools#346
Reviewed-on: https://go-review.googlesource.com/c/tools/+/361394
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-12 14:51:54 +00:00
Hana (Hyang-Ah) Kim 19a5504ffc gopls/internal/lsp: use the golang.org/x/vuln/exp/govulncheck
Change-Id: Ifac1c9398a7d0923fa84c175ce8eea40e41a93f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/435362
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-11 21:42:28 +00:00
Tim King ab79327e05 cmd/ssadump: disable run mode with runtime package
Changes `ssadump -run` to ensure that the package runtime
is not imported (changed from must be imported). For several
years, the runtime package has used unsafe constructs
x/tools/go/ssa/interp cannot interpret. This must have been
failing a similar amount of time.

This is unfortunate, but is unlikely to be addressed soon.

For golang/go#43163

Change-Id: I9e2aee640ff7b1123e591e6c49cac9967c5e8da8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441817
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-11 20:40:41 +00:00
Alan Donovan 29429f53af gopls/internal/lsp/source: sort protocol edits
The LSP protocol doesn't require edits to be sorted,
but some clients such as govim were relying on it,
as we learned when I recently removed the sort.
This change restores the sort behavior.

See also govim/govim#1171

Change-Id: I589b6cfde933ea6907859bf40acd33c1a7fcde02
Reviewed-on: https://go-review.googlesource.com/c/tools/+/442256
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-11 18:07:12 +00:00
Michael Matloob 49b340b352 go/analysis: update tests for different go list error behavior
golang.org/cl/437298 updates go list to not exit with a non-zero
error code in some cases and instead place the error on the Package
struct. Also, as a cleanup, some places where exit status 2 was returned
will return exit status 1 (bringing it in line with other errors
returned by the go command).

TestEncodeDecode in facts_test.go has been updated to fix a missing
function body that is not relevant to the test, but that was causing an
error because the Package struct now has an error on it.

TestRunDespiteErrors in checker_test.go has been updated to reflect that
in some cases an analysis with RunDespiteErrors will fail to run because
a build error returned by go list when it's run to get export data is
not recognized as being a parse/typechecker error (the kind of error
allowed by TestRunDespiteError).

TestIntegration in unitchecker_test.go has been updated to reflect that
go vet running unitchecker will now fail with exit status 1 instead of 2
(so it just checks for a zero or non-zero status).

For golang/go#25842

Change-Id: Idbbd19b5de661e6e5f49e0475c5bc918d8e33803
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441879
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-11 16:22:44 +00:00
Robert Findley cd0288ff85 internal/lsp/cache: invalidate analysis results on packages.Load
Most invalidation happens in snapshot.clone, but to be safe we were also
invalidating package data when new metadata is set via packages.Load. At
the time, I wasn't sure why this was necessary.

Now I understand: with experimentalUseInvalidMetadata it is possible
that we re-compute invalidated data using stale metadata in between the
initial clone and the subsequent reload. I noticed that it was also
possible to have stale analysis results after the Load results arrive.

Fix this by invalidating analysis results on Load, in addition to
packages. Factor out invalidation into a new helper method.

Since we believe this may fix analyzer panics, re-enable strict handling
of analysis panics during tests.

For golang/go#56035
For golang/go#54762
For golang/go#42857

Change-Id: I8c28e0700f8c16c58df4ecf60f6127b1c05d6dc5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/420538
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-11 16:03:54 +00:00
Robert Findley 906c733cc2 gopls/internal/lsp/source: find references in test packages
When finding references or implementations, we must include objects
defined in intermediate test variants. However, as we have seen we
should be careful to avoid accidentally type-checking intermediate test
variants in ParseFull, which is not their workspace parse mode.
Therefore eliminate the problematic TypecheckAll type-check mode in
favor of special handling in this one case where it is necessary.

Along the way:
 - Simplify the mapping of protocol position->offset. This should not
   require getting a package, or even parsing a file. For isolation,
   just use the NewColumnMapper constructor, even though it may
   technically result in building a token.File multiple times.
 - Update package renaming logic to use TypecheckWorkspace, since we
   only need to rename within the workspace.
 - Add regtest support for Implementations requests.

Fixes golang/go#43144

Change-Id: I41f684ad766f5af805abbd7c5ee0a010ff9b9b8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/438755
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-10-11 14:54:39 +00:00
Robert Findley 2a41b2554b internal/robustio: fix log.Fatal calls that should be log.Fatalf
Change-Id: I810160ebabfdd6062f5cdd902ceda77b5912a6fa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441876
Reviewed-by: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-10-10 21:31:25 +00:00
Robert Findley 150b5f8bb6 internal/imports: read entire API dir in mkstdlib.go
Read the entire API directory, so that we don't need to edit mkstdlib.go
when regenerating zstdlib.go for new go versions.

Joint with Dylan Le.

Co-Authored-By: dle8@u.rochester.edu.
Change-Id: If5c71bfcfd2104f923df10cf21d16b5280fed025
Reviewed-on: https://go-review.googlesource.com/c/tools/+/438504
Reviewed-by: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-10-10 18:26:39 +00:00
Robert Findley 19cfa79754 internal/lsp/source: switch the default diff algorithm to "checked"
We've been using this setting in experimental for some time without
issue, so switch it to default.

For golang/go#52967

Change-Id: Ib4d786e689d4b0f009195cc86d7dd5d8269cf424
Reviewed-on: https://go-review.googlesource.com/c/tools/+/427534
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-10 17:23:42 +00:00
Suzy Mueller fa6bd3b49c gopls: include informational vulnerability diagnostics
Unaffecting vulnerabilities that appear should be shown as
informational diagnostics. These do not have current version.

Change-Id: I5dc8d111fd9de8388195627c8f050a2660426abb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441875
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2022-10-10 16:14:14 +00:00
Robert Findley 89b4335324 gopls/internal/lsp: merge notifications about deprecated settings
VS Code suppresses notifications if we send too many, but we don't want
users to miss warnings about deprecated settings. Merge them all into a
single message body.

Also fix a race in a test that added in the preceding CL: the old go
warnings may race with the initial workspace load.

For golang/vscode-go#2487

Change-Id: I69d61a17e0e6e888fa04fa1edce864e28a8d650e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440180
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-10-10 13:27:02 +00:00
cui fliter f90d8ad46c all: fix a few function names on comments
Change-Id: I91eec68ebd9394685a6586c8d0cf01ecf3fd82e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441775
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-10-10 13:22:38 +00:00
Robert Findley 350f1e2c0a gopls/internal/lsp/fake: retry ephemeral errors when renaming on windows
Investigation of renaming flakes revealed that renaming is known to be
flaky on windows, and the go command has a robustio package that works
around known flakes for certain IO operations on darwin and windows.

Rather than duplicate this logic piecemeal, copy the entire robustio
package to the gopls module, along with a script to sync it from GOROOT
using go generate. Use this new package to de-flake renaming, and
replace an existing workaround.

The copy script got a little out of hand at the point where I needed to
add +build constraints. Nevertheless, I've decided to keep it with the
caveat that it may be removed if it proves too difficult to maintain. As
is, it at least serves as documentation for how the sync was done.

For golang/go#56040
For golang/go#56039
For golang/go#56038
For golang/go#55324

Change-Id: Ifeda408ac44a2866e84015a2a38ae340dc0a88bb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440181
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-07 21:46:09 +00:00
Alan Donovan 8b1d1ec39c gopls/internal/lsp/cache: suppress panics during analysis
We now have a plausible model for the cause of the analysis
crashes and are disabling this check until we have submitted
a plausible fix.

(Specifically: actionHandle.promise may be a stale promise
for an older package with the same ID, since snapshot.actions
uses the package ID as a key. This causes us to re-use
stale inspectors, whose syntax nodes won't be found in TypesInfo.)

Updates golang/go#54762
Updates golang/go#56035

Change-Id: I1a7cc1b02b8c322692b1a6bee03f6cd858c08ea0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/440179
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2022-10-07 18:11:00 +00:00
Robert Findley 20c1ee70e4 gopls/internal/lsp: warn about Go versions that are too old
Add a showMessage notification when the Go version in PATH is too old.

Also delete the unused View.Rebuild method.

Updates golang/go#50825

Change-Id: I279a04f021a0f8ddb09fcfe299fbab8d10e8c022
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439836
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-10-07 17:55:15 +00:00