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

5845 Коммитов

Автор SHA1 Сообщение Дата
Pontus Leitzler 49064d2332 internal/lsp: report used semantic token order in registerCapability
The semantic token legend sent to the client in registerCapability
wasn't the one used when encoding semantic tokens.

If a client sent clientCapabilities support for token types and token
modifiers that wasn't ordered exactly as gopls defined them, all
semantic tokens was encoded incorrectly.

We now instead report the order used for encoding as legend in the
registerCapability request to the client.

Fixes golang/go#46244

Change-Id: I8273c9ed9d1f97a93c162d709f30df38bfd576aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321029
Trust: Pontus Leitzler <leitzler@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-05-19 16:08:23 +00:00
Rob Findley a0f4b7b83e internal/lsp/lsprpc: implement cancellation using jsonrpc2_v2
Use the jsonrpc2_v2 Preemption option to support request cancellation.

Also fix the TestRequestCancellation to actually test request
cancellation, and add a V2 version of this test. For now, the
ForwardBinder is not exercised.

Factor out test set-up and tear down.

Change-Id: Ic104e922fa2d0ae570b69c3928e371175db28a9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321014
Trust: Robert Findley <rfindley@google.com>
Trust: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2021-05-19 14:12:35 +00:00
Rob Findley f451690e36 internal/lsp/lsprpc: partial integration of the jsonrpc_v2 library
Update the protocol package to allow wrapping the jsonrpc2 API, and add
wrappers for v1 and v2 of the API, so that we may switch between them.

Add simple bindings for the lsprpc package for jsonrpc2_v2 package, and
get them working well enough to pass a version TestClientLogging test.
This seemed like a reasonable checkpoint.

Also add some type safety to client closing: all LSP clients must
implement io.Closer.

Change-Id: Ib2e6906e0db0c94102a7e794de932d6b61d54670
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320850
Trust: Robert Findley <rfindley@google.com>
Trust: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2021-05-19 14:12:23 +00:00
Rob Findley 17b3466692 internal/jsonrpc2_v2: consider ErrClosedPipe as a closing error
There was already handling in isClosingErr for errors from Stdin/Stdout
and TCP connections. Add handling for io.Pipe closing errors.

Change-Id: I8d171ab49a3fffe0fca9f0482f6b92d61b1fae1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320849
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2021-05-18 18:21:53 +00:00
Rob Findley 6da3d7ace9 internal/lsp/source: re-parse if needed when collecting identifier info
With the new ParseExported logic, we can lose some unexported fields on
exported structs. This can lead to misleading or malformatted hover
information.

Fix this by ensuring we always extract the Spec from a full parse. Since
this path is only hit via user-initiated requests (and should only be
hit ~once per request), it is preferable to do the parse on-demand
rather than parse via the cache and risk pinning the full AST for the
remaining duration of the session.

For golang/go#46158

Change-Id: Ib3eb61c3f75e16199eb492e3e129ba875bd8553e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320550
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-18 02:12:20 +00:00
pjw 8f301ca0d3 internal/lsp: more careful error handling for semantic tokens
The implementation now returns fewer errors to the client. The LSP
specification restricts errors to 'exceptions', so gopls no longer
returns errors if parsing or typechecking fails.

Also, some internal routines that always returned nil errors no longer
return errors at all. The logging for the errors that //line directives
induce was too verbose, and has been turned off. (Many LSP requests
will fail if there are //line directives.)

Fixes golang/go#46176

Change-Id: I18b2cb164b55174f4edbc31e1376da7a8c505a1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319249
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-05-17 17:18:20 +00:00
Rob Findley 09ab05b0db internal/lsp: exit graceful for modfiles in semantic tokens
Change-Id: I86e6dbdd6e51af9b947c34fd04489ed34687b3c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319849
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-13 17:35:42 +00:00
Rob Findley cd1be5dbec gopls/internal/regtest: add a failing regtest for vscode-go#1489
Unimported completion computes invalid text edits with windows line
endings.

To enable this test, add support for windows line endings in the regtest
framework. Doing this required decoupling the txtar encoding from the
sandbox, which was a good change anyway.

For golang/vscode-go#1489

Change-Id: I6c1075fd38d24090271a7a7f33b11ddd8f9decf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319089
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-13 13:20:04 +00:00
Rob Findley 57c3a74c41 internal/lsp: get file URI from beginFileRequest in SemanticTokens
Unguarded calls to span.URI.Filename() can panic. beginFileRequest
handles this, so use the URI of the returned FileHandle instead.

Fixes golang/vscode-go#1498

Change-Id: Ie48c27854e4a8ed8cca52ff6547ff580eccb5fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319529
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-12 22:01:29 +00:00
Fernandez Ludovic 8287d5da45 go/analysis/passes/sigchanyzer: copy to avoid modifying the AST
The sigchanyzer pass suggests fixes, but it does that
by altering the channel declaration argument.
That causes the buildssa.Analyzer fail to fail,
along with crashing other passes that depend on it.

To fix this, we make a copy of the channel's declaration arguments,
and modify the copy instead.

Fixes golang/go#46129

Change-Id: I807d36abd49cd3ccc2cc9f907aa98349b2e3231f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319211
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-05-12 20:59:48 +00:00
Heschi Kreinick 9dfac01ddd internal/lsp/cache: add missing error checks
I wrote this code as if there was going to be a final error check after
all the type checking attempts, but ended up using the result inside the
attempts, errors would likely have resulted in panics. Just do normal,
non-clever error checking.

Change-Id: I665f34f7e6d1a2c3465543cbdc39a723a22a1095
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319371
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-12 16:42:30 +00:00
Jay Conrod be4aaae4cf all: update tests to use 'go mod download all' to populate go.sum
In anticipation of CL 318629, 'go mod download' without arguments will
not update go.mod or go.sum. Before 1.16, 'go mod download' would adds
sums for .mod files but not .zip files (which people didn't usually
notice). Many folks found the behavior of adding sums for .zip files
to be annoying.

This change alters tests to run 'go mod download all' to populate
go.sum files. This is equivalent to 'go mod download' without
arguments before CL 318629.

For golang/go#45332

Change-Id: I387d514176f798ae8f17b0b056194196718f57f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318811
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-05-11 20:42:14 +00:00
Heschi Kreinick cd1d0887dc internal/lsp/cache: trim more stuff in ParseExported mode
Despite the name, ParseExported only hollowed out declarations -- it
didn't actually drop any from the AST. This leaves a fair amount of
unexported crud behind. Unfortunately, there are a *lot* of ways to
expose an unexported declaration from an exported one, and it can be
done across files. Because of that, discarding unexported declarations
requires a lot of work.

This CL implements a decent attempt at pruning as much as possible from
the AST in ParseExported mode.

First, we analyze the AST of all the files in the package for exported
uses of unexported identifiers, iterating to a fixed point. Then, we
type check those ASTs. If there are missing identifiers (probably due to
a bug in the dependency analysis) we use those errors to re-parse. After
that we give up and fall back to the older, less effective trimming. The
pkg type changes slightly to accomodate the new control flow.

We have to analyze all the files at once because an unexported type
might be exposed in another file. Unfortunately, that means we can't
parse a single file at a time any more -- the result of parsing a file
depends on the result of parsing its siblings. To avoid cache
corruption, we have to do the parsing directly in type checking,
uncached.

This, in turn, required changes to the PosTo* functions. Previously,
they operated just on files, but a file name is no longer sufficient to
get a ParseExported AST. Change them to work on Packages instead. I
squeezed in a bit of refactoring while I was touching them.

Change-Id: I61249144ffa43ad645ed38d79e873e3998b0f38d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312471
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-11 17:48:41 +00:00
pjw 2db0265cb2 internal/lsp: in semantic tokens, better distinguish between types and variables
If A is a type, then in
type B {
  A
} it is a type, but in
type C {
  A int
 }
it is a variable (and similarly in function types). The old code got this wrong.

Fixes: golang/go#46068

Change-Id: Ib7320914de81d2b7377214f53f99f4fea25e00fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318749
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-11 14:51:35 +00:00
Rebecca Stambler 9cddb0ea22 all: update all dependencies except for sergi/go-diff and golang.org/x/net
Post-release dependency upgrade.

Change-Id: Icee97a77e003cb875f38fb04daab148bfb01c131
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317692
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-11 14:29:16 +00:00
Rob Findley 18795da840 internal/typeparams: a new helper library for working with generic code
Tools like gopls will want to add additional features to support working
with generic code, but need to continue to compile at older Go versions
that don't support type parameters.

This CL contains an initial draft of a helper library that may be used
to interrogate generic type information from go/ast and go/types without
having to guard the calling code with a build constraint.

I will use this library to implement some generics features for gopls.
Once we're confident in the API, it could potentially be exported as
x/tools/go/typeparams.

Change-Id: I0ad3050b57cf8d8e8dda7d350d18f5e50f4105ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317451
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-11 03:28:22 +00:00
Rob Findley 79d39ff544 internal/lsp/source/completion: avoid a panic in package completion
For golang/vscode-go#1486

Change-Id: I48939224778155964712192faf5a437ee10cd2e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318370
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-10 23:22:37 +00:00
Rob Findley fa05545715 internal/lsp/debug: add a facility to track known bugs
Sometimes users report issues related to edge cases in Gopls that aren't
reproducible. In some of these cases, we end up guarding against
conditions that shouldn't be possible, which is an unfortunately fragile
solution.

Add a new debug.Bug function to both annotate such branches as known
bugs, and help find them when they reoccur.  For now this just records
them in the debug server, but in the future we could send the user a
message to the effect of "hey, a known bug has occurred" for debug
builds of gopls.

Also included are some minor cosmetic fixes.

Change-Id: I95df0caf2c81f430661cabd573ce8e338fa69934
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318369
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-10 23:21:19 +00:00
Rebecca Stambler 5a667787ee internal/lsp: do not reinitialize the workspace for didOpen events
Previously, we would treat file opens/closes as workspace
reinitialization events.

Change-Id: Ib8ca490fe7a44768a757311b058093d0bf3888c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317450
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-10 21:57:30 +00:00
Pen Tree 0185c7ed42 internal/lsp: fix no definition when importShortcut is link
Fixes golang/go#45987

Change-Id: I59194f41eccdd3a0df6d9a3d0cc57008c40b1450
GitHub-Last-Rev: 832d6f864f
GitHub-Pull-Request: golang/tools#317
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318469
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
2021-05-10 21:56:33 +00:00
Jay Conrod ecb7392444 go/packages: in overlay_test, allow test variant in second_file case
When CL 241577 lands, 'go list -e' will include unparseable files
(like a file without a package declaration) in GoFiles in addition to
InvalidGoFiles.

This makes go/packages more tolerant of empty test files. With
CL 241577, if a file=src.go query is given when an empty _test.go is
present, packages.Load will return two matching packages: the library
under test, and the internal test package.

This CL broadens overlay_test.go so the new behavior doesn't break the
test.

For golang/go#39986

Change-Id: I14d019129465e928a3f60a2230edd2e2d1d74687
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317409
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-05-10 15:11:50 +00:00
Tom Freudenberg f05e912406 godoc/static: add gopher/pkg.png image
Replace the link to the gopher pkg.png from an online location
to a local file.

This will prevent any privacy issue on godoc so that there is no ping anymore to golang.org
when opening private documentation generated by godoc.

Another benefit is that it allows the image to load when godoc is used offline.

Last the img is placed to the upper section.

For golang/go#32011.

Change-Id: I1459bf2613251e3e12404087ea9083b64a4f70c2
GitHub-Last-Rev: c32ef9541e
GitHub-Pull-Request: golang/tools#315
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313097
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
2021-05-07 20:56:39 +00:00
Joe Tsai c0140e85e1 go/analysis/passes/printf: adjust error message
Rather than stating a neutral-sounding fact
(i.e., "Sprintf call has error-wrapping directive %w"),
make it more clear why this is wrong
(e.g., "Sprintf call has error-wrapping directive %w, which only operates with Errorf")

Change-Id: I3417423bcc09e6c9ede9993c33d8420ec57c2a08
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317431
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-05-06 19:28:34 +00:00
Shoshin Nikita d1ea2c78a5 internal/lsp/source: support typeDefinition for function/method's return values
Support typeDefinition for functions/methods that have only one return value
of a named type. The total number of return values doesn't matter.

Examples:

* func foo() X
* func foo() (X, bool, int)
* func foo() (*float64, *X, error)

Fixes golang/go#38589

Change-Id: I8840d667437300fd1250a13630e12a36601f0a60
GitHub-Last-Rev: 581d810af9
GitHub-Pull-Request: golang/tools#311
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313093
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-06 03:15:21 +00:00
Rebecca Stambler 08a4f343fb internal/lsp: handle exclude directives in multi-module mode
Add exclude directives to the workspace module go.mod file.

Fixes golang/go#44932

Change-Id: I93f587b321dc6b35e7df30ea39cf8f70f656d04c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317449
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-06 03:14:34 +00:00
Rob Findley f4a41298b9 internal/lsp/regtest: add a benchmark for didChange
Add a benchmark for the processing of workspace/didChange notifications,
attempting to isolate the synchronous change processing from
asynchronous diagnostics. To enable this, add a new type of expectation
that asserts on work that has been _started_, but not necessarily
completed. Of course, what we really want to know is whether the current
notification has been processed, but that's ~equivalent to knowing
whether the next one has been started. Really, it's off-by-one, but
amortized over e.g. the 100 iterations of a benchmark we get
approximately the right results.

Also change some functions to accept testing.TB, because in a first pass
at this I modified the regtest framework to operate on testing.B in
addition to testing.T... but that didn't work out as IWL is just too
slow to execute the benchmarks outside of the environment -- even though
we can ResetTimer, the benchmark execution is just too slow to be
usable. It seems like a fine change to accept testing.TB is some places,
though.

For golang/go#45686

Change-Id: I8894444b01177dc947bbed56ec7df80a15a2eae9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317292
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-06 02:57:18 +00:00
Muir Manders dd255f2351 lsp/source: enable experimentalPostfixCompletions by default
Leave the options flag so people can disable it for now if needed.

Updates golang/go#39507.

Change-Id: I78bbac157caa18c5d9a8e2ffe1a5c5eba4c6c30f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317389
Run-TryBot: Muir Manders <muir@mnd.rs>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-05-05 22:35:07 +00:00
Tim King 19496731f9 passes/stdmethods: warn when an Is, As, or Unwrap has the wrong signature.
Extend stdmethods to warn when a type implementing error has an Is, As, or Unwrap method with a different signature than the one expected by the errors package.

For golang/go#40356

Change-Id: Ia196bb83a685340d6dab216b87c8a4aa2846f785
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312829
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
2021-05-05 21:37:16 +00:00
Muir Manders 68c6cab8b7 lsp/completion: improve append() param type inference
In cases like:

    append([]string{}, foo<>)

we now prefer objects of type string at <>. Previously we had no
preference. In particular, we now try to infer the slice type from the
first append() arg instead of only from the outer context of the
append() call.

Fixes golang/go#43240.

Change-Id: I59dfa3b18892c5c87fc5ff53109f51f50ee03d26
Reviewed-on: https://go-review.googlesource.com/c/tools/+/316849
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-05 20:44:55 +00:00
pjw 250398d0b3 internal/lsp: add semantic tokens for comments and multiline strings
Fixes: golang/go#45860

Change-Id: Idad9d7c20ff0b92995220a6a7fbec28b5850d8db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315989
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-05 16:20:51 +00:00
Peter Weinbergr 7cab0ef2e9 internal/lsp: support template files
Provide some support for template files, implementing most of
https://docs.google.com/document/d/1clKAywucZVBXvL_v4mMhLQXso59lmQPMk1gtSpkV-Xw

Template support is controlled by the option 'experimentalTemplateSupport'
which defaults to false.

Most of the code is in a new 'template' package. Implemented are
semantic tokens, diagnostics, definitions, hover, and references,
and there is a stub for completions.

This code treats all the template files of a package together, so as
to follow cross-references.

Change-Id: I793606d8a0c9e96a0c015162d68f56b5d8599294
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297871
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2021-05-05 01:45:45 +00:00
Bryan C. Mills f03daeacec gopls/go.mod: upgrade to Go 1.17
This change was produced using 'go mod tidy -go=1.17'
with a go command built at CL 315210.

This activates lazy loading, and updates the go.mod file to maintain
the lazy-loading invariants (namely, including an explicit requirement
for every package transitively imported by the main module).

Note that this does *not* prevent users with earlier go versions from
successfully building packages from this module.

For golang/go#36460.

Change-Id: I117d8ae9ea605a4c78ee6a0816739e74b09b2e48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/316449
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-04 19:12:24 +00:00
Heschi Kreinick 42984c428e internal/lsp/regtest: run one quick fix at a time in TestUnknownRevision
There are two possible quick fixes for a missing go.sum entry, and the
regression tests always run all available fixes. That never made sense,
but I never got around to fixing it because it didn't cause a problem.

Now that it turns out to be the cause of the problem described in CL
315152, fix it and roll that CL back.

Change-Id: I49430429a99a412f43bd11b30afe8903db99a694
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315910
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-03 21:45:16 +00:00
Bryan C. Mills 19b1717ea5 go.mod: upgrade to Go 1.17
This change was produced using 'go mod tidy -go=1.17'
with a go command built at CL 315210.

This activates lazy loading for the x/tools module, and updates the
go.mod file to maintain the lazy-loading invariants (namely, including
an explicit requirement for every package transitively imported by the
main module).

I will send a separate CL to upgrade the gopls module, since it has
some awkward interactions with the Go 1.12 presubmit test
(golang/go#45919).

Note that this does *not* prevent users with earlier go versions from
successfully building packages from this module.

For golang/go#36460.

Change-Id: I1d2a6b28820fa6cb3d02162c14873643e4c689cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315570
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
2021-05-03 20:05:58 +00:00
Bryan C. Mills a1fbb68135 all: upgrade go.mod files to Go 1.16
This enables the narrower "all" pattern described in
https://golang.org/doc/go1.16#all-pattern,
eliminating some otherwise-unnecessary checksums.

For golang/go#36460.

Change-Id: Ia894b1c1d85f8d1317aebb816921e95e7c1da506
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315569
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-03 18:12:08 +00:00
pjw 062bf4eb8a internal/lsp: make ShowDocument RPC available to gopls
The window/showDocument RPC is now correctly classified as being
sent from the server to the client.

Change-Id: I659528af69662fb709242d326563d52070fd5702
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315990
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-03 16:38:18 +00:00
Rebecca Stambler 3e17c62e37 internal/lsp: warn users who have built gopls with go-diff v1.2.0
I considered having gopls not initialize at all, but VS Code Go
intercepts those error messages and they get buried. We should probably
fix that in VS Code Go, but for now just show a warning.

Updates golang/go#45732

Change-Id: I214974e5a96231c96b1583af8ac245de03cea5d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315852
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-03 16:36:24 +00:00
Rob Findley def02638c3 gopls: clarify policy with respect to support for older Go versions
Clarify that we have best-effort support for the last 4 major Go
versions, and that support for Go releases 3 and 4 versions ago may not
block releases and may be dropped if necessary.

Also explain that Kokoro CI is not automatically re-run when the result
is removed in Gerrit.

For golang/go#45919

Change-Id: Ic1480c9276dad9502aaf885b98bb9445deeed0c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/316349
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-03 16:07:20 +00:00
Rob Findley 7a6108e9b2 internal/lsp: don't use ast.NewPackage to build builtin
ast.NewPackage mutates the input files, making it difficult to avoid
races with our caching model. I had avoided a race resulting from cache
handle cancellation, just to run into another race in multi-session
servers.

But there's no reason to use ast.NewPackage when we only have a single
file. We can just interrogate the file scope wherever needed.

Fixes golang/go#45868

Change-Id: I521475b51ee3b1c3e408916affecafbc629b0191
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315629
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-04-30 20:08:34 +00:00
pjw edbe9bef04 internal/lsp/completion: indicate completion candidates that are deprecated
In LSP, CompletionItems can say if they are for deprecated names. This
CL implements that for items where the doc comments contain a line
starting // Deprecated.

Semantic tokens now similarly mark deprecated tokens, but in vscode
the default theme doesn't change the display, and the customization
options seem limited to:

    "editor.semanticTokenColorCustomizations": {
        "rules": {
          // only foreground, bold, underline, italic
          "*.deprecated": {"italic": true}
        }
    },

Change-Id: I93ccc227bf4e1e30a4f23b40da4d2cbafe1cd925
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313509
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-30 19:49:23 +00:00
Rob Findley 9b9633e07a internal/lsp/regtest: force GOPACKAGESDRIVER=off
There's no easy way to do this via the LSP, as go/packages reads from
the environment, so simply call os.Setenv.

Fixes golang/go#45866

Change-Id: Iae4e929d47ffef5ffe023ed1886d773a74fd836f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315649
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-30 16:06:43 +00:00
Bryan C. Mills 291330a8d1 gopls/internal/regtest/modfile: set an explicit go version in the TestUnknownRevision modules
For some reason the "bad" case of this test fails when the main module
is lazy. Since the go.mod file lacks a 'go' version directive, as of
CL 315210 it is upgraded to a lazy module the first time it is edited
by an invocation of cmd/go.

I don't know why this case doesn't exhibit the expected failure mode
when lazy loading is enabled — I guess it's because we attribute the
checksum error to the individual package that needs it instead of the
module as a whole? — but I can't follow this test well enough to
figure out whether there is actually a real problem for lazy modules
here. If there is, we can handle that by adding a new, separate test.

For golang/go#36460

Change-Id: I0949e1f9f5cb1b6c884706e50a9694232308387b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/315152
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-04-30 14:46:28 +00:00
Rebecca Stambler aec13729f1 gopls/internal/regtest: unskip tests for golang/go#37098
Now that this issue has been resolved, we can unskip the tests for it.

Change-Id: I610122a424bedd2cbd066ea9985239fc319e58ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313532
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-29 19:34:21 +00:00
Rob Findley 28c1392e35 internal/lsp: don't call PackagesForFile on builtin.go
Calling PackagesForFile on builtin.go loads is at a
command-line-arguments package, which has many type checking errors.

Add a new snapshot method IsBuiltin, which is used to avoid calling
PackagesForFile on builtin.go when diagnosing changed files or checking
for orphaned files. There may be other places where this should be used,
but this functionality can't reasonably be pushed down, as
PackagesForFile should always return something.

This exacerbated an existing race to building the builtin, because
ast.NewPackage unfortunately mutates the ast.File. Fix this by just
building the builtin package directly when building the handle. It
should be very fast.

Fixes golang/go#44866

Change-Id: Ie6c07478493fa011e92e6966289c2fa822d87b35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/314290
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-04-29 13:06:21 +00:00
Ian Lance Taylor 800adbe2e8 go/packages: enable TestIssue37098 for Go 1.17 and later
For golang/go#37098

Change-Id: I6edf1b4efca38fe9837ed944bc45c05c37099b4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313591
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-04-28 21:52:02 +00:00
Suzy Mueller 16b25d25b9 internal/lsp: print comments that would be lost during extract func
Due to the limitations of comments in ast, it is difficult to move
comments. The extract function feature currently does not handle
comments at all. This change instead prints the comments that would
have been lost above the call to the function, so that the user can
easily recover them. Otherwise, it was possible for users to lose
comments and not notice.

Updates golang/go#37170

Change-Id: I1e2d865f5deddefbb0417732490decbdfcde5f3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313211
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-28 01:46:37 +00:00
Pontus Leitzler 7c72a84860 go/analysis/passes/fieldalignment: clarify reported diagnostics in docs
It wasn't obvious that there are two different kind of diagnostics
reported by fieldalignment, one for struct size and another for pointer
bytes.

The documentation now mentions both types, and shows an example that
clarify what "pointer bytes" are.

Fixes golang/go#45541

Change-Id: Ia62fb05980ddddf52e579ac51459aaaed168cfa7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/314469
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-27 20:55:22 +00:00
Suzy Mueller 9ff864874f internal/lsp: add support for extracting non-nested returns
If there is a return statement that is guaranteed to execute in
the selection to extract to function, then the result of calling
the extracted function can be directly returned.

Updates golang/go#37170

Change-Id: I6454e4107d670e4a1bc9048b2e1073fc80fc78ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312469
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-27 20:37:52 +00:00
Shoshin Nikita d0768c9130 internal/lsp/source/completion: suggest only valid package names
Before this change directory names were used "as is" for package completion.
It could lead to invalid suggestions (for example, 'package 1abc' or package 'ab-cd').

This change adds a check whether a directory name can be used in a package path.
If the directory name is invalid, only 'package main' will be suggested.
Otherwise, the directory name will be normalized and will be used as a package name.

Note: normalized directory names contain only lower case letters and digits.

Fixes golang/go#44680

Change-Id: I4b710f90d1723c512e29dc3c248a1e681f1cd37f
GitHub-Last-Rev: 8ae69f1c6f
GitHub-Pull-Request: golang/tools#310
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313092
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-27 19:53:45 +00:00
Rob Findley 6397a11608 internal/lsp/debug: splice in updated servers rather than overwrite
Updating server info was racing with rendering debug templates, because
the state mutex only guards the servers slice, not the values contained
in that slice.

Switch to splicing in updated server data, rather than updating
in-place, to avoid the race.

Change-Id: Ia69895b49cf3f961c58db8e6512ce8b1f5911fd3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/314169
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-04-27 15:36:10 +00:00