Commit Graph

6106 Commits

Author SHA1 Message Date
Zvonimir Pavlinovic 4100dac8a1 go/analysis/passes/deepequalerrors: add typeparams test
This CL adds a test for the assign pass that involves use of generics.

Update golang/go#48704

Change-Id: I1aa51aed24d63d42b6b0150d64925b97dfd59a92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357412
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Cherry Mui <cherryyz@google.com>
2021-10-21 17:03:18 +00:00
Amelia Downs 9b675d0446 gopls/doc: remove bad gopls cli link
This link for "more information" just points to the same doc.

Change-Id: Ib9fee88d5dc9225a91547bd9e7c677e8989ca1a8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357369
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@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-20 20:41:51 +00:00
Robert Findley cbf1d01b28 go/internal/gcimporter: avoid setting unnecessary lines in fakeFileSet
As discussed in golang/go#46586, the gcimporter spends large portion of
time just validating fake lines.

Fix this by only setting the lines we need. Benchcmd results for
TestImportStdLib:

name              old time/op         new time/op         delta
TestImportStdLib          1.11s ±40%          0.57s ±58%  -48.17%  (p=0.000 n=18+18)

name              old user-time/op    new user-time/op    delta
TestImportStdLib          1.24s ±46%          0.71s ±61%  -42.84%  (p=0.000 n=18+18)

name              old sys-time/op     new sys-time/op     delta
TestImportStdLib          249ms ±64%          139ms ±47%  -44.19%  (p=0.000 n=19+18)

name              old peak-RSS-bytes  new peak-RSS-bytes  delta
TestImportStdLib         80.1MB ±24%         86.6MB ±13%   +8.06%  (p=0.001 n=20+20)

Fixes golang/go#46586

Change-Id: I5ef99ea9f242fc80d2d17750a8d9b28f7fc71245
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357291
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-20 18:48:51 +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
Robert Findley 81f084edce go/internal/gcimporter: remove support for type parameters subscripts
Now that the compiler no longer includes subscripts in its export data,
we can remove support for parsing them in the gcimporter.

Make this change, as well as add support for exporting the new names to
iexport.go (tests fail if these changes are made in separate CLs). This
proved a bit tricky to debug, so along the way add some hooks for easier
tracing of import/export.

Fix a bug in iimport.go where rparams were being shadowed, and fix the
export tests to actually compare methods.

Change-Id: Ie08aa5e5ee971d357d352b8f4a4673f6d2a38779
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356534
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>
2021-10-19 23:13:35 +00:00
Rebecca Stambler 3a9f390381 gopls: update generics instructions to mention go.mod go directive
Fixes golang/go#49079

Change-Id: I5d5428980f4f3a3da234f9bc543a488407d1ec2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356934
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-19 22:56:52 +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
Rebecca Stambler 288d0b3f79 gopls: tidy go.mod file for go1.18
Change-Id: I3190d3bd34aa0d6c7fb8af9f729ff4d550aaa027
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355973
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>
Trust: Alexander Rakoczy <alex@golang.org>
2021-10-15 02:45:22 +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
Peter Weinberger 88e80df821 cmd/stringer: add a few tests using instantiated generic types
The added tests are in a subdirectory of testdir that is looked
at only if typeparams.Enabled is true, but some test helper routines
needed to be modified to cope with files in a subdirectory.

Change-Id: I82c22a8ba74a1e4a1a2c8669c2271449d5fcaf3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355313
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: Ian Lance Taylor <iant@golang.org>
2021-10-14 12:38:31 +00:00
Hana acac93965f go/analysis/passes/bools: add typeparams test
testdata/src/typeparams is similar to testdata/src/a but
uses type parameters. This checks analysis report's error
messages correctly display type information.

Change-Id: I7a8054879556903be537374d209d71a62bff45fa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353629
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@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-14 00:44:41 +00:00
Damien Neil ac2ed988c3 go/analysis/passes/printf: warn against using non-error interface values with %w
CL 217180 permits passing interface values to any format verb, since
we have no way of knowing if the underlying type implements
fmt.Formatter. Restore the previous behavior of reporting an error
for passing a non-error value to %w.  The %w verb requires an error
argument, and the risk of false positives is small.

Fixes golang/go#48931

Change-Id: I83a6c9ed252976476f12372a490779336a1f536f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355730
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-13 22:21:08 +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
Eric Chiang 0b930fbaf4 cmd/goimports: recommend go install instead of go get in docs
go get now logs a warning when using it to install globally. Prefer go
install @latest instead.

Change-Id: I9478771e70c58202847a6dfeaaf63e1b88301d84
Reviewed-on: https://go-review.googlesource.com/c/tools/+/355251
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
2021-10-12 19:23:00 +00:00
Guodong Li c83725bbd8 go/analysis/passes/loopclosure: add typeparams test
testdata/src/typeparams is similar to testdata/src/a but
uses type parameters.

Change-Id: Ia92f146089da4b1a3743c265181127ca886a71ad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/354701
Trust: Guodong Li <guodongli@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-11 22:57:32 +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
Zvonimir Pavlinovic 1af23bdac9 go/analysis/passes/assign: add typeparams test
This CL adds a test for the assign pass that involves use of generics.

Update golang/go#48704

Change-Id: I355e73130c54bdc2363c686a5b28fe3140a307b5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/354610
Reviewed-by: 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>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-10-10 13:37:52 +00:00
Tim King ee04797aa0 go/types/objectpath: canonical order for methods
The method ordering in types can depend on the parse order for types. In
order to make objectpath robust against this, simply encode all methods
with respect to a canonical lexicographical ordering.

Fixes golang/go#44195

Change-Id: I4177d9b4e094452f71d4db1813a5a36b54d0d70a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/354433
Run-TryBot: Tim King <taking@google.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-10-08 22:21:41 +00:00
Hana c5188f24a6 gopls/doc/advanced.md: update unstable version installation instruction
`go get` no longer builds/installs binaries in tip.

Updates golang/go#46880

Change-Id: I5673368a579d79f571adf5ca5c44c15b8101dbe9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/354169
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-10-07 21:15:04 +00:00
Hana d477ef3e90 go/analysis/passes/atomic: add a test that uses typeparams
This atomic check simply inspects whether sync/atomic.Add*
are used and LHS looks identical to the first arg of the call.
In the current implementation, this does not require handling
of type params. This test shows the addition of typeparams
doesn't crash the vet.

Update golang/go#48704

Change-Id: I79f9d782595f6bf2db82237afdbef1ffdf6f808e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353550
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@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-05 22:50:47 +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
6543 81efdbcac4 cover: add function to parse profiles from an io.Reader
Fixes golang/go#19404

Change-Id: I893fbb999bb8d0a6c62ab8752790fce75912be0c
GitHub-Last-Rev: 101a2f5bd6e2c2e278deafc8238fa4319a697541
GitHub-Pull-Request: golang/tools#331
Reviewed-on: https://go-review.googlesource.com/c/tools/+/336329
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
2021-10-05 03:23:35 +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
Rebecca Stambler ccaa907479 go/analysis/passes/unmarshal: allow unmarshalling to a type parameter
We can also unmarshal data to a type parameter, in addition to a pointer
and an interface.

This analyzer probably requires more discussion, but this solution
should be sufficient for now.

Updates golang/go#48704

Change-Id: I333f919109295e80a04e59df131713553cdbe612
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353210
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-10-04 03:19:02 +00:00
Robert Findley 0ebff1a957 go/ast/astutil: update PathEnclosingInterval to handle type parameters
Add support for the new generic syntax to PathEnclosingInterval, notably
the new IndexListExpr node and FuncDecl.Type.TypeParams.

Change-Id: I013a916a1617e5f08c8d1cb30501bf2bf253c742
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353150
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 21:26:43 +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
Robert Findley 58ad7eb1ab go/types/objectpath: add support for type parameters
This CL adds an initial draft of support for type parameters in the
go/types/objectpath package. For now, introduce two new operators:
 - the 'T' operator (type->type), which requires an integer operand and
   goes from *Named and *Signature types to the type parameter at the
   given index.
 - the 'C' operator (type->type), which goes from a *TypeParam type to
   its constraint.

Along the way, reorganize the path tests and update some errors messages
to consistently format the expected type with %T.

Fixes golang/go#48588

Change-Id: Ibdf03a86b7d8e24a8faa1f2fc42f2be8db20ca75
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350148
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: Tim King <taking@google.com>
2021-10-01 16:45:09 +00:00
Robert Findley 3883e4a549 go/internal/gcimporter: allow both prefixes and subscripts for tparams
Add some flexibility to the gcimporter while we work on adjusting the
compiler to identify type parameters with a path prefix, rather than a
numeric subscript.

Change-Id: Ia9d5b0d3daebf31b9181dce5127da637d40510ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353410
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>
2021-10-01 16:29:05 +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 Griesemer e89823e067 x/tools/go/internal/gcimporter: exclude a file from TestImportTypeparamTests
Matching change for the corresponding file in CL 353389.
To make the builds pass for now.

For golang/go#48424.

Change-Id: Id66837957ffec4e4b19faa0337a7587ea8bd6125
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353395
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-10-01 04:28:36 +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
Suzy Mueller d9648c9910 go/analysis: test errorsas analysis with type params
Add tests for the errorsas analyzer pass with type
parameters.

Change-Id: I96d62c9ef9f194c42bfbfadcae730bf6caa7040f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352989
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-09-29 17:29:23 +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
Robert Findley da36f796b4 go/internal/gcimporter: skip typeparam import tests on unified builders
CL 351855 introduced a typeparam test that imported the constraints
package. As reported in golang/go#48595, this package is currently
breaking with the unified export data format.

Updates golang/go#48595

Change-Id: I1b77955c767a2e890d8d8829cca6455a4e79c5ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/352853
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 21:42: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