Commit Graph

6126 Commits

Author SHA1 Message Date
Robert Findley 1b02aa2bfe go/analysis/passes/shift: update for generics
Warn about shifts that exceed the width of a type in the type parameter
type set.

For golang/go#48704

Change-Id: If16650b0c7214415f650884014eda9690d8da11a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357758
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-27 19:33:07 +00:00
Rebecca Stambler 08f2e89cd5 gopls/api-diff: fix api-diff command for Go 1.18
Also add some better error reporting.

Change-Id: I9363ac324fc8ad89ccc77491a9e6399506ec8dcb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356930
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-27 16:48:55 +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
Zvonimir Pavlinovic 591e12a7fb go/analysis/passes/cgocall: add typeparams test
This CL adds a test for the cgocall pass that involves use of generics.

Updates golang/go#48704

Change-Id: I521708d607c5f32ca24fe370b7d6436147bae6a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358695
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-10-26 22:24:36 +00:00
Guodong Li 26dbf47d51 go/analysis/passes/lostcancel: add typeparams test
testdata/src/typeparams is similar to testdata/src/a but
uses type parameters.

For golang/go#48704

Change-Id: Id6911e0e18b31a0de917835e4bf83c50adea1599
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358694
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Guodong Li <guodongli@google.com>
2021-10-26 22:00:36 +00:00
Rebecca Stambler 96266072c4 all: update dependencies post-release
Change-Id: I1c48c94a133b6543a26a1803220c5c0fbbcc821e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357035
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-26 18:40:06 +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
Guodong Li c4ead46007 go/analysis/passes/httpresponse: fix a testing issue
Fixes golang/go#49160

Change-Id: Ie22f45626df37b4d701feedaf0ba4516505bfbfe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358698
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-26 15:46:18 +00:00
Guodong Li 903c757bd1 go/analysis/passes/httpresponse: add typeparams test
testdata/src/typeparams is similar to testdata/src/a but
uses type parameters.

For golang/go#48704

Change-Id: I91b101bda6e1da5b2de6830896a4b13508f31322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358696
Trust: Guodong Li <guodongli@google.com>
Run-TryBot: Guodong Li <guodongli@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-10-26 02:02:46 +00:00
Robert Findley f916b54a17 go/analysis,go/ssa: initialize the types.Info.Instances map
Update a couple places where we should initialize the
types.Info.Instances map:
 - The unitchecker may be used with analyzers that expect the Instances
   map to be populated.
 - go/ssa will eventually support instances.

Change-Id: Id3dafe57430e5710ee91215a9586b09a87470b15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357757
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 21:11:49 +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
emahiro 5a40697724 tools/gopls: use `go install` instead of `go get`
Fixes: golang/go#49114
Change-Id: I39c5bee4168862af2aa5a29a96d45cad3e0dd9f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358074
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Nooras Saba‎ <saba@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-10-25 20:40:31 +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 fc8b4caee7 go/internal/gcimporter: stub support importing/exporting constant kind
Add placeholder support for importing/exporting constant kind in the Go
1.18 export data format.

Also eliminate the redundant iimport.iexportVersion field.

For golang/go#45837

Change-Id: I94dbcadde0fae55788ce1a139a2760276f644630
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358035
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-25 14:51:39 +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
Hana 316ba0b740 go/packages/packagestest: skip nested module directories in copying
MustCopyFileTree is used to construct a module representation based on
a real directory tree and its output consumers (e.g. Export) assume the
output contains only files that belong to the module. If the real
directory contains nested module directories, they need to be trimmed
to satisfy the assumption.

This CL implements this trimming logic - a directory containing go.mod
is excluded from copying if the directory is not the top-level directory.

Change-Id: Ib09d4d74e120b502e338a021042d4d5e00719f23
Reviewed-on: https://go-review.googlesource.com/c/tools/+/358037
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-22 20:09:16 +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
Dominik Honnef baf4e38fc7 go/gcexportdata: limit reader to the export data section of the archive
When given an archive, NewReader can figure out the size of the export
data and there is no need to read the entire file, which includes
object code for the package in addition to export data.

We could make the same change in gcimporter.Import but choose not to,
as the function has no users.

Fixes golang/go#48954

Change-Id: I11e8e448c3133465f0e6ab01b3532da3732387af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357209
Trust: Dominik Honnef <dominik@honnef.co>
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-21 19:57:13 +00:00
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