Commit Graph

2591 Commits

Author SHA1 Message Date
Bryan C. Mills b766c284d5 internal/jsonrpc2: make Serve wait for all connections to close
Also eliminate a goroutine leak in case of connection timeout.

Change-Id: I82c1a8352658353ef5d0ba4e7ce9e617ce7b42a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236750
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: Ian Cottrell <iancottrell@google.com>
2021-11-08 20:32:21 +00:00
Robert Findley 1ae27d3d3d internal/lsp/cache: don't offset invalid positions
The zero value of token.Pos is special: it determines IsValid(), which
has semantic significance in many places.

offsetPositions, which adjusts positions after AST mangling, was
adjusting all positions -- including invalid positions. As a result it
was making invalid positions valid, leaving a nonsensical AST.

Fix it to skip invalid positions.

Change-Id: I844f243f9a4a3f98ace32fe30e934410d11142dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/361614
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: Suzy Mueller <suzmue@golang.org>
2021-11-05 15:19:55 +00:00
Bryan C. Mills 68536facc9 internal/testenv: treat linux-riscv64-unmatched as a slow builder
For golang/go#49321

Change-Id: I36e1b26a52956b6b2a9a2a655934aba853759162
Reviewed-on: https://go-review.googlesource.com/c/tools/+/361155
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-03 20:13:57 +00:00
Bryan C. Mills 4d06874119 internal/testenv: treat dragonfly-amd64 as a slow machine
Updates golang/go#45216

Change-Id: I9e714582c4d8c3c7ce7571359d7f9bbe2c6c9497
Reviewed-on: https://go-review.googlesource.com/c/tools/+/360735
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-02 15:33:01 +00:00
Peter Weinberger 351c04c5a1 /internal/lsp/source: apply directory filters to workspace symbols
Apply Options.DirectoryFilters when searching for workspace symbols.
The natural way to implement it would lead to an import loop, so
the working code was moved from cache to source.

Fixes golang/go#48939

Change-Id: Iccf32bc8327ba7845505a6a3de621db8946063f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/359514
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: Suzy Mueller <suzmue@golang.org>
2021-10-30 12:32:06 +00:00
Robert Findley 96715ada81 internal/lsp: check for invalid URIs in definition
URI.Filename() panics on non-file URIs. Just pass UnknownKind to
beginFileRequest to allow handling template files.

Fixes golang/go#49223

Change-Id: Ic2add49d3d0c04855bf25583712102a50fb425ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/359734
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-10-29 19:33:54 +00:00
Robert Findley d5520c2912 internal/lsp/source: check for nil objects in call hierarchy
Fixes golang/go#49125

Change-Id: Id91415377240ab87aeaddb9d668281509d073510
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358549
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-10-27 16:11:50 +00:00
Sean Liao e1e2965795 all: update install commands to go install pkg@version
Updates golang/go#43684
Updates golang/go#49101

Change-Id: I2f0c7920bcd6ce0429f1b7bdda3747bf376775f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357714
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-10-27 02:41:01 +00:00
Pontus Leitzler 244f92ec88 internal/lsp: do not send semantic tokens that client doesn't support
LSP clients tells gopls which token types it supports using
SemanticTokensClientCapabilites, and when gopls ran into an unsupported
token type it still did send that token with the first supported type
(i.e. encoded token type 0).

This change makes gopls omit tokens where the token type isn't one of
the client supported ones.

Change-Id: Ic3b6eeb56d67e773e75365660d301f5332f3ab44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358874
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-26 18:33:39 +00:00
Robert Findley 1050b5ce2e go/analysis/passes/composite: update for generics
Warn about unkeyed composite literals via literals of type parameter
type.

Updates golang/go#48704

Change-Id: Ia75139b56cb73288c133bd547d71664464015813
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357756
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-25 21:11:43 +00:00
Robert Findley bcc6fa839d internal/typeparams: guard against generics in stdlib tests
Add a new package internal/typeparams/genericfeatures, factoring out the
check for usage of generics from the usesgenerics checker. For tests
operating on the standard library, this allows us to explicitly detect
usage of generics, rather than relying on a hard-coded list.

To make this work, I switched the go/ssa standard library test to use
go/packages rather than go/loader. This resulted in finding 457 packages
versus 676 (likely due to tests), but my assumption is that this is
still enough coverage.

Change-Id: I6ba32fb4068dd7f5eedb55c2081c642665ed124a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355972
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: Tim King <taking@google.com>
2021-10-25 20:36:35 +00:00
Robert Findley 18096c5ad9 go/internal/gcimporter: add support for the Go 1.18 export data version
Add support for accepting the Go 1.18 export data version (2) to the
x/tools gcimporter, while preserving support for generic code at version
1.

For now, the exporter still outputs version 1.

For golang/go#49040

Change-Id: Ic4547e385ced72b88212d150bf16acaf200a010e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358034
Trust: Robert Findley <rfindley@google.com>
Trust: Dan Scales <danscales@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: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-10-25 14:51:03 +00:00
Robert Findley affba5001c internal/lsp: temporarily strip subscripts from generic hover
To enable removing subscripts from go/types without breaking x/tools
tests, temporarily normalize test hover strings to strip subscripts.

Change-Id: I373122150e9ca889e2dcbc77875fe1b0dbbe3e15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358014
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: Robert Griesemer <gri@golang.org>
2021-10-23 12:53:38 +00:00
Suzy Mueller 6f2254e651 internal/lsp: adjust extract function range if block statement
If the selected region is a block statement, gopls
does not return a valid function extraction. This
change adjusts the range to be the statements inside
of the selected block statement.

Fixes golang/go#48963

Change-Id: I9b1fb5005f961f30c1fa0333cd1f2050ed5eedef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357615
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-10-22 02:18:41 +00:00
Rebecca Stambler 4ea6123e07 internal/lsp: don't add multiple views for the same folder
When we add a view, we should check if we already have a view for the
given folder.

Updates golang/go#48844

Change-Id: I0de27d420e2b4df3b33b913ae27b108bab6b7d12
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356933
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-10-19 23:27:41 +00:00
Rebecca Stambler 9f721e8f47 internal/lsp: fix data race in Templates code
The snapshot should be locked before iterating through the files.

Fixes golang/go#49072

Change-Id: I1bc805cbb760a9ad113064603863f030ef0ddda7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356911
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: Peter Weinberger <pjw@google.com>
2021-10-19 21:17:55 +00:00
Pontus Leitzler 1feb683013 internal/lsp/analysis/infertypeargs: reduce diagnostic range
When infertypeargs suggested an edit that kept at least one argument the
diagnostic sent to the editor included comma and whitespace(s).

In editors/IDEs that highlight the range it looked a bit odd. This
change reduce the diagnostic range to start at the first unnecessary
argument.

Change-Id: Ib091f8ff150c66d1d8ee4f82bda8b1b37202eeba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356989
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-19 20:35:15 +00:00
Suzy Mueller 98f6e0395b internal/lsp: disable fillstruct for type params
Do not suggest fixes for types that require type params
or that have fields that require type parameters.

Change-Id: I68059956a7d38be0ffa3f79230615437ccc5788f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353109
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-10-15 14:09:01 +00:00
Robert Findley ce04ca3bf6 go/internal/gcimporter: normalize implicit interfaces in export tests
The export data format does not yet support capturing whether interfaces
are implicit, so normalize them for the purposes of comparing type
parameter constraints.

Change-Id: I678fb5f5fe6481b9a1479176ca056a31d17bbd77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355971
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: Matthew Dempsky <mdempsky@google.com>
2021-10-15 00:16:20 +00:00
Robert Findley 3a269dc41f internal/typeparams: copy the term list algorithm from go/types
Add a go:generate script to sync the term list algorithm from go/types
into the internal/typeparams package. This allows us to experiment with
the API for type sets without committing to it in go/types.

Expose this algorithm via a new NormalizeInterface function, which
returns the normal form of an interface.

Change-Id: Idfe3b485cc29f67937f8d4a447e41d477be0b8e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351830
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: Robert Griesemer <gri@golang.org>
2021-10-14 22:21:32 +00:00
Robert Findley e69ba9dc00 internal/lsp/cache: fix incorrect detection of useless code
Our logic to detect whether suggested fixes delete unnecessary code did
not take into account suggested fixes that have a command.

Fixes golang/go#48938

Change-Id: I70d2bebbf7059236525117cc1f454ef726162a96
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355769
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2021-10-14 14:04:14 +00:00
Rebecca Stambler 378b9e1d59 internal/lsp/analysis: add typeparams tests for nonewvars and noresultvalues
Also, change the way we test fillreturns to match the other analyzers.

Change-Id: If2124775c583524ff61017452bf065965a6cc97e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353171
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-10-13 04:56:02 +00:00
Rebecca Stambler 24389d4d0c internal/lsp: use the correct dynamic registration booleans
I mistakenly used DynamicConfigurationSupported for all capabilities,
not just the workspace/configuration one.

Fixes golang/go#48600

Change-Id: Ie9b205d89da6e4d110a5310b31fc1ba22f2b5383
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352055
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-10-13 03:12:54 +00:00
Robert Findley 074820e17b go/analysis/passes/usesgenerics: a new analysis to detect generic code
Add a new "usesgenerics" analyzer to report uses of features related to
generic programming.

This analyzer may be used to temporarily guard other analyzers until
they may be updated to support generic features.

Along the way, update the typeparams API to return the Info.Instances
map, rather than provide indirect access, so that it can be iterated.

Fixes golang/go#48790

Change-Id: Ia3555524beff6e19f0b9101582205e26e757c8da
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355009
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: Tim King <taking@google.com>
2021-10-12 22:26:24 +00:00
Rebecca Stambler 94178a22b2 internal/lsp: use source.Offset instead of tok.Offset
This isn't strictly necessary for some of the cases, but it's better to
use it in all cases. Also added a test to ensure that we avoid
(*token.File).Offset in all of gopls--test was probably overkill, but it
was quick to write.

Change-Id: I6dd0126e2211796d5de4e7a389386d7aa81014f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353890
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: 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-10-12 22:12:04 +00:00
pjw 18fa840216 internal/lsp/semantic: prepare for generics
Semantic tokens will now return typeParameters if the client will accept
them. If the user is not using go1.18, then generic code will not type
check and gopls will not recogize type parameters. If gopls has not
been compiled with go1.18 only some uses of type parameters will be
recognized. In any case the code uses internal/typeparams
to see through IndexListExprs.

There is a global parameter semDebug which should be false in
checked-in code. I use it to see how semantic token decisions are
made; it is for debugging. But there are a lot of small code changes
to restrict logging to a few places.

There is also an unexercised stub to fix a bug where some functions
are misclassified as variables. This will be activated in a future CL,
as it will also change the golden test files.

Change-Id: I5107e67ae25e825b0cdc4c1a744877ce97ba609b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352570
Trust: Peter Weinberger <pjw@google.com>
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>
2021-10-11 15:23:58 +00:00
Peter Weinberger 2dc275501c internal/lsp/protocol: update LSP definitions and stubs
There are some (presumably provisional) new RPCs, PrepareTypeHierarchy,
SuperTYpes, and Subtypes. ServerCapabilities has a corresponding field
TypeHierarchyProvider, and the client has TypeHierarchy which is
a TypeHierarchyClientCapabilities

The name of the return type of ApplyEdit has been changed from
ApplyWorkspaceResponse to ApplyWorkspaceResult.
(its content has not changed, just the name)

srver_gen.go and its generator helper/helper.go needed a small change
to avoid using _ as an argument.

Change-Id: I8fc828e69659e0333af686ec1dd138b0c09c1c62
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353169
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-10-05 16:44:45 +00:00
Peter Weinberger 36e7bf96e1 internal/lsp/analysis/unusedparams: add tests for generics
using the typeparams convention.

Change-Id: I42094b75bd43937bdae099473d6241de887456b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353289
Trust: Peter Weinberger <pjw@google.com>
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>
2021-10-04 22:28:37 +00:00
Rebecca Stambler db89b5a197 internal/lsp: handle nil pointer in fixInitStmt
I'm going to make a follow-up CL to create a source.Offset function
that will always check inRange, and we should use that everywhere
instead of token.Offset, which is pretty prone to panicking.

Fixes golang/go#48763

Change-Id: Ia81309400d15a28c133f4b3d41c6239231c2532d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353889
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-10-04 19:52:26 +00:00
Robert Findley 942994fc75 internal/typeparams: use alias rather than indirection for IndexListExpr
Using aliases make it easier to translate code using the new APIs.

Change-Id: I9887569a3ba1d5b1434ac6cc185485433aca7090
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352898
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: Robert Griesemer <gri@golang.org>
2021-10-01 20:36:29 +00:00
Robert Findley 13c407cf48 go/ast/inspector: add support for the new IndexListExpr node
IndexListExpr nodes were being skipped by go/ast/inspector, due to not
having a type value. Add this value, along with a test that we can
inspect the new constructs in generic code.

Use a type alias in the typeparams package to achieve this, following
the pattern for new go/types nodes.

Change-Id: I894a9415a93806cc6dbb92cf190b2bdab368d5df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352896
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: Robert Griesemer <gri@golang.org>
2021-10-01 19:30:53 +00:00
Suzy Mueller 6f5fd9bf41 internal/lsp: add parameterized slice test for simplifyslice analysis
Add a test for a parameterized slice to make sure that the simplify
slice analysis still finds the simplification.

Change-Id: I20d5f064bcae60c752f0dee53472dd5db0b18a89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352089
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: Robert Findley <rfindley@google.com>
2021-10-01 15:56:03 +00:00
Robert Findley 2189684b10 internal/typeparams: use NewSignatureType, IsMethodSet, and Context
Update the internal/typeparams API proxy following CL 352615, CL
352616, and CL 353089.

Change-Id: Ib65a1876c7820945189e1dc953e1a82e98547a09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352852
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-10-01 15:55:45 +00:00
Robert Findley 1c35f2a5d7 internal/lsp/analysis: quick-fix to remove unnecessary type arguments
This CL adds a new infertypeargs analyzer, which finds call exprs where
type arguments could be inferred, and suggests a quick fix to simplify
them.

Along the way, may two changes to the supporting frameworks:
 - Initialized types.Info.Instances in go/packages
 - Fail analysis tests run with suggested fixes if formatting the
   resulting source fails.

Change-Id: Ib15e5bd7c26aa293c5fc18a4cff6bc047e9e31d2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351552
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-09-29 19:22:48 +00:00
Rebecca Stambler 7d467dcfbb internal/lsp: support go.work outside of experimental
This change handles the case of the user creating a go.work file
during the gopls session. It also defaults to go.work/gopls.mod being
used outside of experimental mode, so that you don't have to both set
a setting and have a file.

Change-Id: If118cd2fc95c1b5600a6c06217a3b61605b11e28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/342170
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-09-29 19:20:39 +00:00
Rebecca Stambler d42c92b465 internal/lsp/analysis/fillreturns: skip any parameterized functions
Type parameters don't have default values, so for now, we just skip them
in fillreturns. I think we should still be able to handle functions
whose return values are all concrete types though.

Change-Id: I1fe4c0d46cd564ff71647294d6cc935762bbd9d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352910
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-09-29 16:42:30 +00:00
Robert Findley 5dbd5e40d5 internal/typeparams: filter out API diffs related to types.Environment
This is a temporary work-around to allow the x/tools TryBots to pass on
the Go repo.

Change-Id: I122dfd0f2c034add913c859136ca6c08f916dde3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352897
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-29 15:31:12 +00:00
Robert Findley df9a164fb3 Revert "internal/typeparams: hide go1.18 API usage behind a build constraint"
This reverts commit 0df0ca0f43.

Reason for revert: we've tagged x/tools@v0.1.7, and want to use the new APIs again.

Change-Id: I5c6f2075833948cc21896d1746e0c51cc0712bb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352855
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
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>
2021-09-28 23:30:19 +00:00
Robert Findley 0df0ca0f43 internal/typeparams: hide go1.18 API usage behind a build constraint
Temporarily hide usage of the new go/types API, so that we can safely
tag x/tools@v0.1.7 without risk of further breakage when these APIs
change.

Updates golang/go#48632

Change-Id: Idba02d09644622b3d973a684a76514c86eefa17f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352854
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-28 22:34:40 +00:00
Rebecca Stambler 7898fe60e6 internal/lsp/analysis: move implementmissing logic into undeclared
I missed the TODO in undeclaredname to add support for functions, so
really this belongs in that analyzer. This removes a fair bit of code.
However, the type error analyzers don't really work with the go/analysis
testing framework because the suggested fixes are split from the
diagnostics, so I moved the tests into the gopls tests.

Change-Id: I861a7ad531d2732fe698ee0ac46f23ad53b16812
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351333
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-09-28 22:17:57 +00:00
Pontus Leitzler 64bbad1f52 internal/lsp/debug: improve readability of session options
I find the session options page in gopls debug a bit hard to read. This
change aims to improve readability by:

- Sorting non-default options first (and alphabetically by name)
- Use bold text for option name
- Hide the "current value" if it's string representation equals the
  default value's string representation

Change-Id: I93606ae788b97e46dc1d3aff420bb58f4c4d9674
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352130
Trust: Pontus Leitzler <leitzler@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-28 20:53:23 +00:00
Suzy Mueller ba6b94c735 internal/lsp: add fields to anonymous struct info
Anonymous struct quick fixes should provide more information on
which struct they will fill. This adds the first fields of an
anonymous struct to the fill title.

Updates golang/go#48563

Change-Id: I42cee2e8b1b9405ac2e2e8cfb8deb2c7710c3056
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351591
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-09-24 21:18:44 +00:00
Robert Findley e1e06b8482 go/internal/gcimporter: temporarily skip the contraints package on the
unified builder

Temporary work-around to fix TryBots until the failure can be
investigated.

Updates golang/go#48595

Change-Id: Ifbc27fc4551195bd9c7427bab7a79076c6ba6392
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352050
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-09-24 19:46:05 +00:00
Rebecca Stambler 6d1e33f1d0 internal/lsp: handle panic in hoverRune by using token.Pos
All operations within a file should be in terms of token.Pos, until the
value must be returned.

Fixes golang/go#48492

Change-Id: I2adfcad8b4729386700c08ba4618e033bf7c3db5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351629
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: 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-09-22 23:41:20 +00:00
Robert Findley c8db761657 internal/lsp/cache: keep going on failed analyzers
A single failed analyzer should not prevent others from reporting their
diagnostics. This is especially relevant as we work on updating
analyzers to support generic code.

Change-Id: If1d958347649a99df92701fc4a4574cb7020596b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351550
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-09-22 22:01:15 +00:00
Robert Findley 284795867f internal/lsp/analysis: add a useany analyzer
Add an analyzer that checks for empty interfaces in constraint position,
that could instead use the new predeclared "any" type.

Change-Id: I6c11f74c479c2cba64b3b12e61d70d157f94393b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351549
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-09-22 22:01:06 +00:00
Francesco Renzi b98090b833 internal/lsp/analysis/implementmissing: add analyzer
This adds an analyzer that provides suggested fixes for undeclared name
errors on function calls, implementing a stub of the fuction (with an
empty body). As of now this doesn't try to guess returned types but
only parameters.
Generated functions are appended at the end of the file where these type
errors occur.

Updates golang/go#47558

Change-Id: Iaef45ada6b7b73de1fbe42e5f7e334512b65e6c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348829
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-09-21 20:35:14 +00:00
Robert Findley 0d12d39b86 internal/typeparams: update to the new Instances API
This CL updates the internal/typeparams package with the new API from CL
349629, switching Info.Inferred to Info.Instances.

Change-Id: I8f98dc39c844ef8891863c08b747f63924ab1c53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351250
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-21 18:37:00 +00:00
Robert Findley fe076c893b internal/typesinternal: document ReadGo116ErrorData
Change-Id: I5afe3e4d3f137758da404e779d6bc9b0a57b6a02
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351089
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-09-21 03:32:29 +00:00
Robert Findley 91c880c34d go/internal/gcimporter: add support for exporting the 1.18 export format
This CL adds support for the Go 1.18 export format to iexport.go. This
support is based on cmd/compile/internal/typecheck/iexport.go, though
with a different types API and adjusted to build at Go versions below
1.18.

Specifically, this CL adds support for both column details in positions,
and generic types and functions. Along the way, some minor adjustments
are made to aid in debugging and testing.

Notably, after this CL the export data version produced by
go/gcexportdata will depend on the Go version used to build.

As part of this change, TestIExportData_stdlib is unskipped for Go 1.18.

Fixes golang/go#48392

Change-Id: I1b218e0acd4864de5c7b89706192273bc7850ffa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351029
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: Matthew Dempsky <mdempsky@google.com>
2021-09-21 02:24:06 +00:00