Commit Graph

7011 Commits

Author SHA1 Message Date
Bryan C. Mills b978661c6c cmd/godoc: streamline test subprocesses
- Use testenv.Command to obtain Cmd instances that terminate (with
  useful goroutine dumps!) before the test's timeout, and remove
  arbitrary hard-coded timeouts.

- Execute the test binary itself as cmd/godoc instead of invoking (and
  cleaning up after) 'go build'.

- Use context cancellation to reduce the number of ad-hoc goroutines
  and channels needed by the tests and to provide stronger invariants
  on process cleanup.

For golang/go#50014

Change-Id: I19ae4d10da691db233c79734799ae074ffdf6a03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377836
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-11-21 16:55:09 +00:00
Bryan C. Mills 932ec22a59 internal/testenv: add a Command function that replaces exec.Command
The function is derived from the testenv.Command function in the main
repo as of CL 446875, with a couple of modifications to allow it to
build (with more limited functionality) with Go versions as old as
1.16 (currently needed in order to test gopls with such versions).

testenv.Command sets up an exec.Cmd with more useful termination
behavior in the context of a test: namely, it is terminated with
SIGQUIT (to get a goroutine dump from the subprocess) shortly before
the test would otherwise time out.

Assuming that the test logs the output from the command appropriately,
this should make deadlocks and unexpectedly slow operations easier to
diagnose in the builders.

For golang/go#50014.
Updates golang/go#50436.

Change-Id: I872d4b24e63951bf9b7811189e672973d366fb78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377835
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-21 16:54:26 +00:00
Alan Donovan 19fb30d1d2 gopls/internal/lsp/cache: fix data race in Symbols
We forgot to acquire a lock while accessing snapshot.files.

Also, upgrade errgroup and use its new SetLimit feature.

Change-Id: Iff1449fd727f0766f6c81391acccaa21951f59be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/452058
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-18 21:46:24 +00:00
Hana (Hyang-Ah) Kim 4ce4f93a92 gopls/internal/lsp: add gopls.fetch_vulncheck_result
This CL changes the signature of View's Vulnerabilities
and SetVulnerabilities, to use govulncheck.Result
instead of []*govulncheck.Vuln. That allows us to hold
extra information about the analysis in addition to
the list of vulnerabilities.

Also, instead of aliasing x/vuln/exp/govulncheck.Result
define our own gopls/internal/govulncheck.Result type
so the gopls documentation is less confusing.

Change-Id: I7a18da9bf047b9ebed6fc0264b5e0f66c04ba3f3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451696
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-18 21:44:59 +00:00
Hana (Hyang-Ah) Kim 8ba9a370ee gopls/internal/lsp/mod: highlight when there is no fix for vuln
Change-Id: If53455159b8578901ff728640e9c1ec671c61cdb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451695
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-11-18 21:44:32 +00:00
Hana (Hyang-Ah) Kim 128f61d438 gopls/internal/lsp/mod: add related info
Related info in module vulncheck diagnostics carries the location
to the entry stack frame found from some of the call paths.

Change-Id: I99eb60ab1c2cb7cc356eae8d2ba35a2167cb179e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450278
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-11-18 21:44:02 +00:00
Hana (Hyang-Ah) Kim fc039936a9 internal/lsp/mod: adjust vulncheck diagnostics suppression logic
Vulnerabilities associated with a module should be suppressed
after the module is updated. Previously, we checked whether the
module version in go.mod 'require' matches the FoundVersion reported
by the vulncheck. However, we realized that we cannot always assume
the module version in require is the actually used module version
(due to how minimal version selection works, and how exclude/replace
affects). Instead check whether the module version is newer or equals
to the suggested fixed version and if this go.mod require is newer,
assume that the user updated the module already and suppress diagnostics
about the module. This is not perfect but a heuristic to reduce
confusion from the stale vulncheck report right after applying the
quick fixes and upgrading modules.

Change-Id: I40f4c3e70b19af3f6edd98f30de3ccb7a6bd7498
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450277
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-18 21:37:48 +00:00
Hana (Hyang-Ah) Kim c099dff179 gopls/internal/vulncheck: log progress
Log before/after package loading and govulncheck.Source calls.
All stderr output of `gopls vulncheck` command is forwarded to the
client as LSP progress reports and visible to users.

go/packages.Load can be traced further if GOPACKAGESDEBUG env var
is set. Instrumentation in govulncheck.Source is still under
discussion in upstream.

For golang/go#56795

Change-Id: I8244930494aed17b319887bf96c2523f3215fa50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/452055
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-18 20:21:45 +00:00
Tim King 36a5c6a8a6 go/ssa: build generic function bodies
ssa now always builds the bodies of generic functions and methods.
Within the bodies of generic functions, parameterized types may appear
in Instructions.

When ssa.InstantiateGenerics is on, calls to generic functions
with ground (non-parameterized) types are built as instantiations of the
generic function bodies. Otherwise, calls to generic functions are built
as a wrapper function that delegates to the generic function body.

The ChangeType instruction can now represent a coercion to or from a
parameterized type to an instance of the type.

*ssa.Const values may now represent the zero value of any type.

The build mode of go/analysis/passes/buildssa is again
ssa.BuilderMode(0) (i.e. ssa.InstantiateGenerics is off).

This change is a stack of already reviewed CLs.

Fixes golang/go#48525

Change-Id: Ib516eba43963674c804a63e3dcdae6d4116353c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/425496
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-18 18:55:10 +00:00
Alan Donovan 85bf7a8fb4 gopls/internal/lsp/source: eliminate Metadata interface
This change merges the source.Metadata interface with
its sole implementation, cache.Metadata.

One possible concern: the struct cannot have private
fields used only by the cache-package logic that
constructs these structs. We are ok with that.

Change-Id: I93c112f92dc812bd0da07d36e7244d5d77978312
Reviewed-on: https://go-review.googlesource.com/c/tools/+/452035
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-18 18:23:35 +00:00
Alan Donovan 2592a854ec gopls/internal/lsp: simplify KnownPackages
This change simplifies the two functions called KnownPackages,
and renames one of them.

The first, source.KnownPackages, is a standalone function
called in exactly one place: ListKnownPackages.
It has been renamed KnownPackagePaths to distinguish
from the other and to make clear that it returns only
metadata. Its implementation could be greatly simplified
in a follow-up, as noted. In the meantime, one obviously
wrong use of ImportSpec.Path.Value (a quoted string literal!)
as an package (not import!) path was fixed, and the package
name was obtained directly, not via CompiledGoFiles.

The second, Snapshot.KnownPackagePaths, is called from two places.
This CL eliminates one of them: stubMethods used it apparently
only to populate a field of missingInterface (pkg) that was unused.
The other call (from 'implementations') is something that should
eventually go away as we incrementalize; in any case it doesn't
rely on the undocumented ordering invariant established by the
implementation. This change removes the ordering invariant,
documents the lack of order, and removes the ordering logic.

Change-Id: Ia515a62c2d78276b3344f2880c22746b2c06ff64
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-18 17:22:07 +00:00
Robert Findley c7ed4b3c0e gopls/internal/lsp/cache: clean up tracking of GO111MODULE
Gopls views stored at least 4 copies of GO111MODULE:
- the value in view.environmentVariables
- the value in view.goEnv
- the value in view.userGo111Module
- the value in view.effectiveGo111Module

All of these values may differ from eachother, depending on the user's
environment and go version, and their meaning is not clearly documented.

Try to clean this up, by having environmentVariables track precisely the
variables output by `go env`, and providing a method to implement the
derived logic of userGo111Module and effectiveGo111Module. Ignore
view.goEnv for now, but leave a TODO.

Confusingly, the name 'effectiveGO111MODULE' turned out to be a more
appropriate name for what was formerly 'userGo111Module', so the naming
has switched.

This change is intended to be a no-op cleanup.

Change-Id: I529cc005c1875915483ef119a465bf17a96dec3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451355
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-11-18 17:19:07 +00:00
Robert Findley 23056f613e internal/lsp/cache: clean up getOrLoadIDsForURI
Address some TODOs in getOrLoadIDsForURI. In particular, after this
change files will be marked as unloadable if getOrLoadIDsForURI returns
fails to load valid IDs.

Change-Id: I1f09d1c7edd776e46bf8178157bcf9e439b9f293
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447742
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-18 17:16:15 +00:00
Robert Findley 5a4eba5af0 internal/lsp/cache: remove support for invalid metadata
Remove support for keeping track of invalid metadata, as discussed in
golang/go#55333.

Fixes golang/go#55333

Change-Id: I7727f43e2cffef610096d20af4898f326c5a8450
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447741
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-11-18 17:16:01 +00:00
Hana (Hyang-Ah) Kim 32a17c01dd gopls/internal/lsp/mod: fix unaffecting vuln diagnostics msgs
When there is no affecting vulns, we should not add the
warning-level message. This bug made informational diagnostic
messages look like

  "example.com/mod has vulnerabilities used in the code: .
example.com/mod has a vulnerability GO-2022-0493 that is not used
in the code."

Also, add a test case that checks the code with only non-affecting
vulnerability.

Change-Id: I88700a538495bc5c1c1a515bd1f119b2705964a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450276
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-18 15:58:55 +00:00
Bryan C. Mills dea100b118 internal/testenv: skip tests that need export data for std if 'go tool compile' does not exist
Now that .a files are no longer being preinstalled for
standard-library packages (#47257), tests that require the export data
from those files must have access to 'go list -export' in order to
generate and load export data from the Go build cache.

`go list -export` does not work without a Go compiler, so assume that
tests that need the 'go' command also need the compiler.

This may cause the tests currently failing on the android-.*-emu
builders to instead be skipped, since the test harness does not copy
the compiler to the execution environment.

For golang/go#47257.

Change-Id: Ie82ab09ac8165a01fc1d3a083b1e86226efc469d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451597
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-17 20:46:33 +00:00
Bryan C. Mills ba373eed34 playground/socket: eliminate an arbitrary timeout in TestLimiter
Fixes golang/go#55238.

Change-Id: I17fe3865f7ec4d8889cdf71497b10a2ad0b41c11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451598
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-17 19:28:33 +00:00
Bryan C. Mills 3d085f3fce gopls/internal/lsp/lsprpc: eliminate arbitrary timeout in TestEnvForwarding
Fixes golang/go#56804.

Change-Id: I1df083bbc4f8c7a41d08ec85fceaa018d26b2f8b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451599
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-17 19:20:03 +00:00
Robert Findley 434d569df7 gopls/internal/lsp/regtest: improve documentation
Start turning the regtest package documentation into more of a guide for
new users. Along the way, move runner options into a separate options.go
file, for discoverability.

Change-Id: I18dec7c632df3e491d166a00959b9b5648d9ddf0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450677
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-11-17 16:35:59 +00:00
Alan Donovan ce26db4201 go/analysis: add Pass.TypeErrors field
The result of type checking is a package (types.Package), type
annotations on syntax trees (types.Info), and zero or more type
errors (types.Error).  Hitherto we had assumed that analyzers don't
need access to type errors, but in fact it turns out to be useful:
for example, analyzers can look at broken code and suggest quick
fixes to repair the mistakes.

This change adds a Pass.TypeErrors field that holds the errors
produced during type checking. It may be non-nil only when the
Analyzer.RunDespiteErrors flag was enabled. Similarly, it adds
a TypeErrors field to go/packages.Package.
(The existing Packages.Error field loses important details.)

Gopls was already using analyzers in this way, (ab)using its privileged
position in the x/tools repo. This change removes the need for such hacks.

We expect that all analysis drivers that support RunDespiteErrors will
in due course populate the Pass.TypesErrors field. This change updates
the go/packages-based driver to do so; no changes were needed to
unitchecker since it does not support RunDespiteErrors.
In the meantime, not populating this field is not expected to cause
any compatibility problems.

Fixes golang/go#54619

Change-Id: Ia7c72242e332782e8919a4c30b2107c37bcec9ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/425095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-11-16 21:35:14 +00:00
Robert Findley b0ad6b2e07 gopls/internal/regtest/misc: fix use of the AfterChange API
Fix a broken build due to a change in the AfterChange API.

Change-Id: I9719a4c7721c768e2704655c80cd510386255b3e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/451236
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-11-16 15:56:32 +00:00
pjw 89856a4c91 gopls/semantic: semantic tokens for type parameters
Fixes confusion in the code for recognizing type paramenters. also, in
f := func() {}; defer f()
the second f is now tagged as a function

Fixes golang/go#56529

Change-Id: Ida37e7fb1caa0bec86376cc24ebfad5c1228a905
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448375
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-16 14:49:29 +00:00
David Chase 6e8da3febb internal/pkgbits: port small optimization from compiler to tools
Tools version of https://go.dev/cl/435336
I believe this helped the compiler (though I don't see the benchmark).
We probably need benchmarks for tools, too.

Change-Id: I3450ecb82fcef7050f28a4cffcbc224972680f36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450678
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-11-15 20:28:31 +00:00
David Chase 06fb723d2f internal/gcimporter: port memory reuse optimizations from Go tree
original CL was https://go.dev/cl/433037
"cmd/compile: introduce "temporary" readers for more storage reuse"

Change-Id: I8989ae45b17a84451d29c7dc95b8ab2a06b6f153
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449499
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
2022-11-15 20:27:34 +00:00
Florian Zenker fc702c522d internal/gcimporter: fix performance regression for unified IR
flattenImports used to traverse the transitive closure of all imports by
recursively visiting all imported packages. This is a lot of redundant
work, because flattening happens for every package, the recursion is not
necessary and this change removes the recursion.

Change-Id: Id5a1b3b15ef3ce8e0fc6c945b5484b3dd06bd6b6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450755
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Florian Zenker <floriank@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-15 19:01:52 +00:00
Robert Findley 1cb4c17983 gopls/internal/regtest: make AfterChange do the awaiting
The only expected use of the AfterChange helper is in the pattern
env.Await(env.AfterChange(...)). Simplify this pattern by having
AfterChange do the awaiting.

Change-Id: I832d619e8d44daae952f250e7aef69eba4e6715a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450676
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-15 16:13:28 +00:00
Robert Findley 0c71b564b9 gopls/internal/lsp: fix diagnostic suppression when folders change
Diagnostic suppression used the view-relative snapshot ID to avoid
publishing stale diagnostics. When the layout of views changes due to a
didChangeWorkspaceFolders notification, this suppression is broken as
snapshot IDs reset to 0. Fix this (hopefully temporarily) by introducing
a globally monotonic snapshot ID.

Fixes golang/go#56731

Change-Id: Ib108b1436e800cf5a45fbba298c9975a2cf1d735
Reviewed-on: https://go-review.googlesource.com/c/tools/+/450275
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-11-15 00:02:48 +00:00
Bryan C. Mills e3b3c0100d go/pointer: break TestInput into subtests and update skips
TestInput is fiendishly slow and memory-hungry. Breaking it into
subtests reveals that the vast majority of that cost can be attributed
to a single test case: "testdata/a_test.go".

Update the address-space-based skip to skip only that one input, skip
it under the race detector (it is timing out on the new
"linux-amd64-longtest-race" builder), and run the remaining inputs in
parallel (to reduce test latency now that we've better identified the
culprit).

Updates golang/go#14113.
Updates golang/go#54630.

Change-Id: I105cfa173edc74692eaa41efd50ae08eeacf0d7d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449518
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-11 16:02:45 +00:00
Alan Donovan 13648cdeaf gopls/internal/lsp/cache: use Package.FileSet where possible
This change adds a FileSet field to Package, and uses it in
preference to Snapshot.FileSet wherever that is appropriate:
all but a handful of places.

For now, they must continue to refer to the same instance,
but once we do away with the Snapshot's cache of parsed files,
there will be no need for a global FileSet and each Package
will be able to create its own. (Some care will be required
to make sure it is always clear which package owns each
each token.Pos/ast.Node/types.Object when there are several
in play.)

Updates golang/go#56291

Change-Id: I017eb794ffb737550da6ae88462d23a8f5c1e1e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448377
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-11 15:24:32 +00:00
Sasha Melentyev 8f3241104a cmd/stringer: replace ioutil with os
Change-Id: I16c8556a90a775e5e3addb2f5907cba04d9c4bb1
GitHub-Last-Rev: 12dc5e78722f0512dbcb5fcedbf9d88b952b33a0
GitHub-Pull-Request: golang/tools#408
Reviewed-on: https://go-review.googlesource.com/c/tools/+/439516
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-11 15:19:20 +00:00
Alan Donovan 3c3713e6a5 gopls/internal/lsp/cache: use typed strings (PackagePath et al) throughout
This changes uses the string types to enforce better hygiene
of conversions. Fishy conversions were flagged with TODO comments.
Perhaps some of these contribute to bugs in our support for vendoring.

Also, the function formerly known as ImportPath is now UnquoteImportPath.

Change-Id: Ia6bf8749908d881fb0a62cb6c98f7dd00563a69e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449497
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-11 03:59:42 +00:00
Hana (Hyang-Ah) Kim 004d1181ca gopls/internal/lsp/mod: simplify ModVulnerabilityDiagnostics
Classify the unaffecting/affecting vulnerabilities as we
iterate over the vulnerabilities to generate info/warning
level diagnostics, instead of iterating over the list twice.

Change-Id: Icfac41c3897d443c368f0292279ca936daffe24e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448978
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-11 00:41:33 +00:00
Hana (Hyang-Ah) Kim 4a8413c694 gopls/internal/lsp/mod: deleted unused function pkgVersion
Change-Id: I85cabd92a1ee28f60ad355c4f44577e0ccc0bd07
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448977
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-11-10 23:41:08 +00:00
Hana (Hyang-Ah) Kim bc08991678 gopls: sync golang.org/x/vuln@3af8368ee4fe
golang.org/x/vuln/exp/govulncheck API was significantly
changed. The previous Main is gone, and we need to use
Source. The returned data types changed significantly
too.

Change-Id: Ic702ffe9a94a8ddd1867a0f2766bb49e2133d3a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448975
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-11-10 23:14:17 +00:00
Robert Findley d66e9b4ac8 internal/typesinternal: update go/types error codes for 1.20
Change-Id: I4b1d4a7769e90801856cfa15e860b899a3bf62dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449496
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-10 22:27:59 +00:00
Alan Donovan 6f99366264 gopls/internal/lsp/cache: don't pass snapshot.fset to go/packages
...since we do our own parsing.

Change-Id: Id762cca408692b9535b8bb36017d6719180e5bb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449498
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-10 22:17:42 +00:00
Cherry Mui d56532ab0e cmd/compilebench: make it work without installed .a's
Currently compilebench relies on installed .a files for std and
cmd, as it runs the compiler and linker directly. For the upcoming
Go 1.20, compiled .a files will not be installed. Don't rely on
them. Instead, build importcfg file and pass it to the compiler
and the linker.

Verified that this approach still works with previous versions of
Go (1.19 and 1.18).

For golang/go#47257.

Change-Id: Ie0eb9541fb995649e5b68d4481a5acfbdfe8f2a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448118
Reviewed-by: Michael Pratt <mpratt@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-10 18:37:12 +00:00
Gopher Robot 502c634771 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: Ie52140f20343bd6dd2b73662fce64c8065f5a80b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/449096
Auto-Submit: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Gopher Robot <gobot@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-09 17:16:50 +00:00
Bryan C. Mills bd04e329ae internal/jsonrpc2_v2: eliminate a potential Accept/Dial race in TestIdleTimeout
The only explanation I can think of for the failure in
https://go.dev/issue/49387#issuecomment-1303979877 is that maybe the
idle timeout started as soon as conn1 was closed, without waiting for
conn2 to be closed. That might be possible if the connection returned
by Dial was still in the server's accept queue, but never actually
accepted.

To eliminate that possibility, we can send an RPC on that connection
and wait for a response, as we already do with conn1. Since the conn1
RPC succeeded, we know that the connection is non-idle, conn2 should
be accepted, and the request on conn2 should succeed unconditionally.

Fixes golang/go#49387 (hopefully for real this time).

Change-Id: Ie3e74f91d322223d82c000fdf1f3a0ed08afd20d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448096
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-11-09 14:00:02 +00:00
Bryan C. Mills d41a43b94f internal/jsonrpc2_v2: fix a potential deadlock when (*Conn).Close is invoked during Bind
This fixes the goroutine leak reported in
https://build.golang.org/log/ae36d36843ca240e9e080886417a8798dd4c9618.

Fixes golang/go#46047 (hopefully for real this time).

Change-Id: I360e54d819849a35284c61d3a0655cc175d81f77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448095
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-09 13:57:32 +00:00
Arsen Musayelyan 3057465037 gopls/doc: Add plugin for Lapce to gopls documentation
Add [Lapce](https://lapce.dev) Go plugin to `gopls` documentation

Change-Id: I58ec42d69708b519cfba3de1cdee269ffecdbbc4
GitHub-Last-Rev: 37762df491e6e7a5797606025357fcfed28be56d
GitHub-Pull-Request: golang/tools#413
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448235
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-09 13:30:16 +00:00
Robert Findley ba92ae1711 internal/persistent: avoid incorrect map validation due to multiple keys
Fix the test failure demonstrated in the following failed builder:
https://build.golang.org/log/d0511c583201e8701e72066985ebf950d9f5511d

It should be OK to set multiple keys in the validated map. Support this
by keeping track of seen and deletion clock time. There are still
potential problems with this analysis (specifically, if a map is
constructed via SetAll), but we ignore those problems for now.

Change-Id: I5940d25f18afe31e13bc71f74d4eea7d737d593d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448696
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-08 21:01:57 +00:00
Angus Dippenaar 9474ca31d0 gopls/doc: clarify `go work use`
I felt a bit confused on my first reading of the docs for using `go work`.

It wasn't clear to me if the `tools` argument in `go work use tools tools/gopls` was an alias or a directory name, so I thought this might make it very clear to understand for first time users.

Change-Id: I9c5a04a8928207b53acfb36ce7add8ca5f033d46
GitHub-Last-Rev: 49e125d83e40f06239f3a24c92f16258a25305c3
GitHub-Pull-Request: golang/tools#409
Reviewed-on: https://go-review.googlesource.com/c/tools/+/441415
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-08 17:28:46 +00:00
Alan Donovan 003fde144e internal/gcimporter: use nondeprecated go/packages mode bits
I meant to do this in the first CL, but was prevented by
a bug which I have since reported and linked to from the code.

Change-Id: I651e728c535cdeb0885eae4d510fda3c24518dcf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448376
Auto-Submit: Alan Donovan <adonovan@google.com>
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-11-07 21:25:05 +00:00
pjw 50506576b8 gopls/fake: add semantic token modifiers to fake editor
This change will make it possible to do semantic token regtests.

Change-Id: I9963c60f61af30f973a2ee4cd32aaa5545bdc4ec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448296
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-07 18:28:08 +00:00
pjw 88a3548304 gopls/coverage: repair coverage.go
Coverage.go computes the test coverage from running all the gopls tests.

This CL accounts for the changed source tree (internal/lsp is gone)
and new actions returned by go test -json ('pause' and 'cont').

Change-Id: I970b3ec107746ce02e3dcdcad9f8c19cffad8d11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448295
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-07 18:26:12 +00:00
Robert Findley 8e0240af74 internal/regtest/workspace: permanently skip TestDeleteModule_Interdependent
This test is flaky, likely due to some race in the
experimentalWorkspaceModule logic. Since we're about to delete support
for that experimental feature, simply skip the test to stop the flakes.

Leave the test as an artifact, as it will be deleted as part of the
clean up of experimentalWorkspaceModule. No need to delete it before
then.

Updates golang/go#55331
Fixes golang/go#55923

Change-Id: Ic17485e42e335459df462af00a2088812ecfb5f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448116
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-11-07 14:31:53 +00:00
Robert Findley fe725d9349 gopls/internal/regtest: simplify awaiting diagnostics from a change
When awaiting diagnostics, we should almost always wrap expectations in
a OnceMet(precondition, ...), so that tests do not hang indefinitely if
the diagnostic pass completes and the expectations are still not met.

Before this change, the user must be careful to pass in the correct
precondition (or combination of preconditions), else they may be
susceptible to races.

This change adds an AllOf combinator, and uses it to define a new
DoneDiagnosingChanges expectation that waits for all anticipated
diagnostic passes to complete. This should fix the race in
TestUnknownRevision.

We should apply a similar transformation throughout the regression test
suites. To make this easier, add a shorter AfterChange helper that
implements the common pattern.

Fixes golang/go#55070

Change-Id: Ie0e3c4701fba7b1d10de6b43d776562d198ffac9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/448115
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-07 14:31:48 +00:00
Alan Donovan 3c8152e28a internal/gcimporter: optimize dependency lookup
The old code based on packages.Visit traversed in a
deterministic order, and didn't stop when it found its
target (the 'return false' only prunes that subtree).
This CL replaces it with a precomputation of the
PkgPath-to-*Package mapping.

The performance difference is small for this test but
it nearly dominates on a larger input (e.g. k8s).
Example code shouldn't steer users into asymptotic traps.

Change-Id: I19f4fc2c25da3d2ae00090704df30a54d8516bf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447958
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-11-05 17:57:31 +00:00
Robert Findley 39c2fd8bff internal/lsp/cache: simplify importsState modfile hashing logic
While checking for changes to go.mod files in the importsState, there is
no reason for special handling based on workspace mode: we can simply
hash all active modfiles. This moves us towards an improved API for the
workspace: it should simply be responsible for tracking active modfiles.

This also incidentally avoids the panic reported in golang/go#55837.

Fixes golang/go#55837

Change-Id: I8cb345d1689be12382683186afe3f9addb19d467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447956
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-11-04 18:06:00 +00:00