Commit Graph

825 Commits

Author SHA1 Message Date
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 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
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
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
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
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
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
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
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
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
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
Robert Findley ec044b1a47 gopls: update dependencies following the v0.10.0 release
Update selected dependencies following the v0.10.0 release, excluding
sergi/go-diff and x/vuln.

Gofumpt@v0.4.0 requires go1.18, so link it selectively following the
pattern of staticcheck. While at it, clean up some things related to the
wiring of staticcheck and gofumpt support. Notably, in VS Code error
messages do not support formatting such as newlines or tabs.

Add a test for the conditional Gofumpt support.

For golang/go#56211

Change-Id: Id09fdcc30ad83c0ace11b0dea9a5556a6461d552
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446736
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 16:52:27 +00:00
Alan Donovan 2b29c66d7e internal/gcimporter: API for shallow export data
This change adds an internal API for marshalling and
unmarshalling a types.Package to "shallow" export data,
which does not index packages other than the main one.
The import function accepts a function that loads symbols
on demand (e.g. by recursively reading export data for
indirect dependencies).

The CL includes a test that the entire standard
library can be type-checked using shallow data.

Also:
- break dependency on go/ast.
- narrow the name and type of qualifiedObject.
- add (test) dependency on errgroup, and tidy go.mod.

Change-Id: I92d31efd343cf5dd6fca6d7b918a23749e2d1e83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447737
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@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-04 16:27:25 +00:00
Hana (Hyang-Ah) Kim a77a1fb995 gopls/internal/lsp/mod: fix vulncheck hover message
This fixes multi-paragraph vulnerability description rendering.

Change-Id: I2960c5f3a839fb4161ae5e25d3e88b5a7345b65d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447736
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-11-04 14:59:01 +00:00
Hana (Hyang-Ah) Kim 4ada35e5cb gopls/internal/lsp: handle modVulncheckSource in diagnosticSource.String
Change-Id: If6ebdfa2db3de8915842cf09da279d8ea7fa9b97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447735
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-04 14:58:54 +00:00
Robert Findley e5f03c1041 gopls/doc: clean up README and add a release policy
Clean up some broken links and stale documentation in gopls/README.md,
and add new documentation for the gopls release policy.

Fixes golang/go#55267

Change-Id: I9c7ed1f1d3949025f3c02edb69b475cf34f214eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446863
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-11-03 20:32:59 +00:00
Robert Findley d5e9e3592c go/analysis/passes/loopclosure: enable analysis of parallel subtests
Remove the internal guard preventing the loopclosure analyzer from
checking parallel subtests.

Also, improve the accuracy of the parallel subtest check:
 - only consider statements after the final labeled statement in the
   subtest body
 - verify that the *testing.T value for which T.Parallel() is invoked
   matches the argument to the subtest literal

Fixes golang/go#55972

Change-Id: Ia2d9e08dfa88b5e31a9151872025272560d4b5e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447256
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-03 17:48:16 +00:00
Alan Donovan 32e1cb7aed gopls/internal/lsp: clarify control around diagnostics
This CL includes some clarifications while trying to
understand the performance of the initial workspace load
and analysis. No significant behavior changes.

Server.diagnose:
- Factor the four copies of the logic for dealing
  with diagnostics and errors.
- Make the ActivePackages blocking step explicit.
  Previously mod.Diagnostics would do this implicitly,
  making it look more expensive than it is.
Server.addFolders:
- eliminate TODO. The logic is not in fact fishy.
- use informative names and comments for WaitGroups.
- use a channel in place of a non-counting WaitGroup.

Also, give pkg a String method.

Change-Id: Ia3eff4e784fc04796b636a4635abdfe8ca4e7b5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445897
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-01 21:03:16 +00:00
Robert Findley feeb0ba914 gopls/internal/lsp/cmd: fix deadlock when opening a file
Rename (*connection).AddFile to openFile, which is more accurate, and
fix a deadlock resulting from holding a Client lock while issuing a
Server request.

Fixes golang/go#56450

Change-Id: Ie6f34613e1e10e3274c3e6728b12f77e3a523b89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446856
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: Alan Donovan <adonovan@google.com>
2022-11-01 17:35:21 +00:00
Robert Findley 6e9dc865e2 gopls/internal/lsp/source/completion: fix panic in completion on *error
Fix a panic during completion on variables of type *error. As a
predeclared type, the error type has nil package. Fix the crash
resulting from this oversight, as well as a related crash in the tests
analyzer, from which the new completion code was adapted.

Fixes golang/go#56505

Change-Id: I0707924d0666b238821fd14b6fc34639cc7a9c53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446815
Auto-Submit: 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>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-11-01 16:24:04 +00:00
Robert Findley 70a130ebec gopls/api-diff: simplify the api-diff implementation
Simplify the api-diff implementation to use `go run` and cmp.Diff. The
latter is more maintainable and produces more readable output, due to
supporting line diffs for multi-line strings.

For golang/go#54459

Change-Id: I11c00e9728ce241aef8f9828f3840b4202294a9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444799
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-31 20:33:45 +00:00
Alan Donovan 3566f695a7 gopls/internal/lsp/source: minor space optimizations
Memory profiles show heavy allocation for the stack
and the function closure of FindDeclAndField.
This change moves both outside the loop, reducing
this function's fraction of allocation from 6.7%
before to 5.0% after, and reducing running time
by 3-7% on these benchmarks.

before
BenchmarkStructCompletion/completion-8               100          10432280 ns/op
BenchmarkImportCompletion/completion-8              1350            921785 ns/op
BenchmarkSliceCompletion/completion-8                100          10876852 ns/op
BenchmarkFuncDeepCompletion/completion-8             142           7136768 ns/op
BenchmarkCompletionFollowingEdit/completion-8         63          21267031 ns/op

After
BenchmarkStructCompletion/completion-8               100          10030458 ns/op
BenchmarkImportCompletion/completion-8              1311            918306 ns/op
BenchmarkSliceCompletion/completion-8                100          10179937 ns/op
BenchmarkFuncDeepCompletion/completion-8             150           6986303 ns/op
BenchmarkCompletionFollowingEdit/completion-8         63          20575987 ns/op

Change-Id: Ia459e41ecf20851ff4544f76ad7b415a24606cd1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446185
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-31 19:44:01 +00:00
Bryan C. Mills 7cdb0e7352 internal/jsonrpc2_v2: rename Serve to NewServer and eliminate its error return
Serve had a misleading name and signature: it did not actually block
on serving the connection, and never returned a non-nil error.

Updates golang/go#56281.

Change-Id: Ia6df0ba20066811b0551df3b3267dff2fffd7881
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443678
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:39 +00:00
Bryan C. Mills 28e9e509a6 internal/jsonrpc2_v2: eliminate error return from Bind
Also make (*Connection).Close safe to call from Bind.

A jsonrpc2_v2.Server has no good way to report an error from Bind.

If the Server saves the error to return from its own Wait method, that
might not ever actually happen: Wait waits for in-flight connections
to complete, but if some existing connection stays up then Wait will
not return.

If the Server goes ahead with establishing the connection and installs
its own Handler, that Handler needs to decide whether to serve the
error from Bind or something more opaque, and at that point Bind may
as well return a handler that makes that choice more precisely.

If the Server merely logs the error and closes the Connection, then
the Bind method itself may as well do that directly too.

It seems to me that the only winning move is not to play. Only Bind is
in a position to decide how to handle its errors appropriately, so it
should not return them to the Server.

Updates golang/go#56281.

Change-Id: I07dc43ddf31253ce23da21a92d2b6c0f8d4b3afe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443677
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@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-31 15:32:37 +00:00
Bryan C. Mills eabc3a08b7 internal/jsonrpc2_v2: eliminate isClosingErr
Also implement and use the Shutdown method, which was mentioned in a
doc comment in CL 292169 but not actually present at that time.

With proper synchronization, we don't need heuristics to determine
whether an error is due to a connection or listener being closed.
We know whether we have called Close (and why), and we can assume
that if we have called Close then that is probably the reason for
any returned error.

Fixes golang/go#56281.

Change-Id: I5e0ed7db0f736ca8df8cd8cf556b674e7a863a69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443675
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-31 15:32:17 +00:00
Alan Donovan f1c8f7f8d5 internal/lsp/source: optimize filter regular expression
When the default filter glob changed to **/node_modules,
the performance of BenchmarkWorkspaceSymbols was observed
to degrade by an astonishing 20%.

(CPU profiles of the benchmark reported that the Disallow
functions percentage had increased only slightly, but these
measures are misleading since the benchmark has a very
CPU-intensive set-up step, so all the percentages are
quotients of this figure, masking their relative importance
to the small region during which the benchmark timer is
running.)

This change removes the unnecessary ^.* prefix from the
generated regular expression. Really the regexp package
ought to do this.

Also, minor cleanups and tweaks to the surrounding code.

Change-Id: I806aad810ce2e7bbfb2c9b04009d8db752a3b10d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446177
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-10-28 18:07:06 +00:00
Robert Findley e074ef8db8 gopls/internal: don't show a warning if the Go version is undetected
CL 445581 inadvertently removed suppression of the Go version error if
the Go version was undetected. Add it back, with a test.

Fixes golang/go#56465

Change-Id: I352369096280c8d3423a7345123ec9309359fb58
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446175
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-10-28 15:53:15 +00:00
Hana (Hyang-Ah) Kim 7fba77ce5d gopls/internal/lsp/source: remove deprecated settings from EnableAllExperiments
VSCode Go Nightly uses `allExperiments` setting which triggers
calling this option. It doesn't make sense to add the settings
that are scheduled to be deleted.

Change-Id: I443d7b1722feafee04b6c63a06ff514a396c5d50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/446095
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-27 22:55:48 +00:00
Robert Findley 42cb7bed6e gopls/internal/lsp: improve the Go version deprecation message
Improve the Go version deprecation message to be a warning at 1.13-15,
and provide better instructions for making it go away. Clarify support
in the gopls README.

Change-Id: I6b08e0bd698f5c085eee7a851a130c53affb8ab5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445581
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Auto-Submit: 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-10-27 13:53:43 +00:00
Alan Donovan 2af106efed gopls/internal/hooks: fixes to diff disaster logic
Previously, the disaster logic in the new diff implementation
would "encrypt" the before/after files using a monoalphabetic
substitution, which has been insecure since the 9th century.
Instead, save plain text, in file with mode 0600, and invite
the user to audit the file before sharing it with us.

Also, separate the two files using a NUL byte, not a newline,
which is highly ambiguous.

Also, in the JSON diff stats writer:
- print a warning if we can't create the log file.
  (The previous code was subtle--it stored a nil *os.File in
  an io.Writer, which caused Writes to fail with an error,
  in effect, silently.)
- Don't hold the mutex around the write operation.
- Fix minor off-by-one error (re: 15)
- Crash if JSON encoding fails; it "can't happen".

Change-Id: I9b6a4145451afd77594f0ef9868143634a9c4561
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445580
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-27 00:23:26 +00:00
pjw de675d5479 tools/gopls: argument in function bodies marked as parameter by semantic tokens
In func f(x int) int {return x;} the second x used to be marked as a
variable, but now is marked as a parameter, visually tying it to its
definition.

Fixes golang/go#56257

Change-Id: I8aa506b1ddff5ed9a3d2716d48c64521bdea0fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/445095
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-10-26 15:27:38 +00:00
pjw 3e1371fd13 gopls/internal: start on LSP stub generator in Go.
This is the first in a series of CLs implementing the new stub
generator. The code is intended to reproduce exactly the current
state of the generated code.

This CL has the final file layout, but primarily consists
of the parsing of the specification.

The LSP maintainers now provide a .json file describing the messages and
types used in the protocol. The new code in this CL, written in Go,
parses this file and generates Go definitions.

The tests need to be run by hand because the metaModel.json file is not
available to the presubmit tests.

Related golang/go#52969

Change-Id: Id2fc58c973a92c39ba98c936f2af03b1c40ada44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/443055
Reviewed-by: 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>
Run-TryBot: Peter Weinberger <pjw@google.com>
2022-10-26 13:02:30 +00:00
Hana (Hyang-Ah) Kim 121f889bbc gopls/internal/lsp/mod: merge vuln diagnostics to one, and add a hover
When a module contains multiple vulnerabilities, previously gopls published
one diagnostic message for each vulnerability. This change modifies this
behavior to publish only one vuln diagnostic for each module. This will
make the PROBLEMS panel more concise and readable. However, the information
about each vulnerability finding is useful, so we supplement this diagnostics
by sending a hover message in the module require line. An added benefit
of this approach is that, unlike the Diagnostics, VS Code supports rich
text rendering for Hover messages. So we can use markdown to add links and
necessary highlighting.

Before this change, go.mod require hover messages (e.g. go mod why result)
were associated only with the module path part, excluding the version string
part. But for vulnerability information hover message, I think it is better
to be applied to the entire module require line (both module path & version)
because they are information about the specific module/version. Currently
LSP hover returns only one hover, so we cannot use this different range only
to the vulnerability information hover. Thus, one side effect of this change
is that the module info hover message will be also shown to the version
part of each require statement.

Change-Id: Iccacd19fdebadc4768abcad8a218bbae14f9d7e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/444798
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>
2022-10-25 17:27:10 +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