Commit Graph

6507 Commits

Author SHA1 Message Date
Hana (Hyang-Ah) Kim 033cbfc76d internal/typeparams: run go generate with go1.18.2
And fix a minor issue in copytermlist.go --

copytermlist.go replaces type names from go/types with
qualified type names. Use of token.NoPos (filled with
ast.NewIdent) however confuses the go/format printer.
As a result, while transforming

  func (x *term) includes(t Type) bool

to

  func (x *term) includes(t types.Type) bool

go/format printer failed to compute the end position of
the parameter list, concluded RPAREN should be in a
different line from the parameter list, added a comma,
and printed

  func (x *term) includes(t types.Type,) bool

Reuse the replaced node's position instead. (not 100%
correct, but better than NoPos)

Change-Id: Ia34e11562cc80c68dcf4b921ffffd926971c2215
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405536
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-11 13:38:50 +00:00
Robert Findley bc0e26ea12 internal/typeparams: remove examples in favor of x/exp/typeparams
The internal/typeparams directory contains an initial draft of the
documentation later published under the golang.org/x/exp/typeparams
module. Remove this draft to avoid confusion.

Change-Id: I1f40468f99c0d2885e8fc380c75669f654ba971e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405260
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-10 12:58:44 +00:00
Zvonimir Pavlinovic b87ceec0dd go/analysis/passes/httpresponse: inspect enclosing context of resp, err
The resp, err results of, say, http.Get can immediatelly be passed to a
helper function that checks err and returns resp. In that case, it is ok
for defer to occur immediately after.

The checker currently assumes that a call to, say, http.Get is the only
call made when a resp is returned. The fix is to check if the original
call is made as a part of another (helper) call and, if so, punt.

For golang/go#52661

Change-Id: If9dc4815013476de381fe69548d1fb9c04aa9fd9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404656
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-09 19:02:05 +00:00
Daniel Martí 313af968cc go/ast/astutil: make Apply follow TypeParams fields
It completely ignored the TypeParams fields in FuncType and TypeSpec.
I was confused why one of my tools, which looks at *ast.Ident nodes,
saw the identifiers where type parameters were being used,
but not the identifiers where they were being declared.

We use the ForFuncType and ForTypeSpec helpers, just like in the rest of
the package, for consistency and backwards compatibility with Go 1.17.

Add a regression test as well.

Change-Id: I00b2dfe5e04d92d63e6d5e91c6466598c865ed0b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405194
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-09 18:45:38 +00:00
Robert Findley d303668635 internal/lsp/cache: use cached parsed files for symbols, if available
Optimize building the symbol index for a file, in two ways:
 - use the cached full parse tree, if it already exists
 - if it doesn't exist, optimize parsing by skipping both comments and
   object resolution, which aren't necessary for symbols

This results in around 3x faster initial indexing of symbols. In my
manual testing, indexing of Kubernetes went from 16s->5s, and indexing
of x/tools went from 2.4s->700ms.

Also fix a typo in gopls/internal/regtest/bench/bench_test.go.

Fixes #52602

Change-Id: I0893e95410be96e94e5e9dee7a3aab30b59c19c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403679
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-05-09 17:04:06 +00:00
Robert Findley 0fb1abf25a internal/lsp: factor out go/token wrapper into a safetoken package
This avoids an import cycle that prevented these wrappers from being
used in the lsppos package.

Change-Id: I9eedd256db983dfcf962edba39e3d4f3a1aabdeb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403680
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-09 17:03:37 +00:00
Robert Findley cde25b3a5f internal/lsp/lsppos: add helpers for mapping token positions
For use-cases that work only with token.Pos and protocol.Position, the
span package is unnecessarily indirect, and inefficient. It also loses
information about newline termination, and handles positions within CRLF
line endings incorrectly.

The lsppos package was written to bypass this complexity, but had
limited use and lacked tests.

Add tests, and an wrapper API that operates on token.Pos. Also fix
source.TestTokenOffset to not panic, and add a temporary exemption of
the new token.Offset usage.

This change also fixes position calculation in the case of empty file
content. The mapper now finds position (0, 0) at offset 0 of an empty
file.

Change-Id: I639bd3fac78a127b1c8eddad60b890449901c68c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403678
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-09 17:02:03 +00:00
Hana 22b709631a internal/lsp/cmd: change vulncheck to directly call the hook
Instead of invoking the command through the LSP custom command,
call the vulncheck command hook directly. That reduces the extra
overhead of bringing up the full gopls server & package loading.
The vulncheck hook loads packages again any way, so the benefit
of running the check inside gopls's custom command framework
is not huge any more.

Still `gopls vulncheck` is useful - editors don't need to install
another binary for vulncheck feature, and it will output the
result in the format easier to handle than what `govulncheck`
currently offers.

Updates golang/go#50577

Change-Id: Ia21e6d7e0c37c4a1b02dc8bbca860143524c3d1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404574
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-06 16:33:28 +00:00
Hana 72a884b2d6 gopls: update golang.org/x/vuln dependency
v0.0.0-20220503210553-a5481fb0c8be

Ran GOWORK=off go mod tidy -compat=1.16

Change-Id: I06914ae341648b7ef6035ec45f955ec7bfa49566
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399040
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 16:33:10 +00:00
Robert Findley d7e01c038e internal/lsp/source/completion: use typeutil.Map for short-circuiting
While working on golang/go#52715, I discovered an infinite recursion in
gopls' completion logic: eachField assumes a finiteness of type pointers.

It is almost certainly a go/types bug that type-checked types expand
infinitely, but nevertheless we should use the more accurate
typeutil.Map for short-circuiting our search.

Change-Id: Ib1c7125e624f42882869acd4e0476e317d4da056
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404335
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-06 16:24:14 +00:00
Tim King d299b94661 passes/copylock: suppress reports on Offsetof and Alignof
Suppress false positives on calls to builtins unsafe.{Offsetof,Alignof}.
Similar to the already suppressed Sizeof, these do not execute their
arguments and thus do not copy.

Fixes golang/go#52700

Change-Id: I2ad461df4c270b97cbd1271403935501f8ae25c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404234
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-05-05 17:30:08 +00:00
Suzy Mueller 30fbd19e84 internal/lsp: fix fillstruct for structs with unsafe.Pointer
Provide a default value for unsafe.Pointer in fillstruct.

Fixes golang/go#52640

Change-Id: I10a1878fbf53b082f83f44e0ba2788ead14439d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403535
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 17:08:12 +00:00
Alan Donovan 0ebacc111e internal: remove pre-go1.12 conditionally compiled files
Change-Id: I496ad24654990341eae9508587e950abde05b540
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404334
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-05-05 16:48:28 +00:00
Alan Donovan 45c8a71312 internal/tool: implement structured help command
'gopls help cmd...' is redirected to 'gopls cmd... -h'.
The tool.Run operation for each subcommand already has
logic to show the usage message when it parses a -h flag.

Examples:
   $ gopls help
   $ gopls help remote
   $ gopls help remote sessions

Fixes golang/go#52598

Change-Id: I5135c6e7b130d839f880d0613534ac08de199bcf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403677
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-04 22:58:41 +00:00
Bryan C. Mills d27d783e99 cmd/godoc: expand skips in TestWeb
After CL 403534, another TestWeb failure was observed in
https://build.golang.org/log/24cca44e99d848317a6bb73b6d15528b500e5643.
This change expands the skips to try to cover more of the cases
where cmd/godoc might hang.

For golang/go#50014.

Change-Id: If3f08da69a68dc00c399b89ffb2c4f049114aeb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403849
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-04 21:37:12 +00:00
Alan Donovan 4911e4af7d internal/testenv: remove darwin/arm case from NeedsGoBuild
This function was derived from internal/testenv.HasGoBuild
in the standard library, which has since been updated
(in https://go-review.googlesource.com/c/go/+/260719)
to permit darwin/arm64 builds.

Change-Id: Ifc793b52b65ee3eedb2f41fbcbfbe36a20cfdbcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403795
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 20:40:54 +00:00
Pontus Leitzler 54c7ba520b go/analysis/passes/asmdecl: add build tag for loong64
The arch "loong64" doesn't exist before go 1.19 causing a "unknown
architecture" message printed to stderr when asmdecl is imported.

A build tag now prevents "loong64" from being checked in earlier
versions of go.

Fixes golang/go#52646

Change-Id: Ibc83ce02d92cfb709a773ca758b21a80516a399c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403874
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 16:24:46 +00:00
Alan Donovan b4c45006d2 README: restructure and update
Update the README file to remove stale information
and describe the most important packages and tools
in the repo, to help users find their bearings amid
the plethora of obscure or obsolete things.

Also, consolidate the Contributing information at the end.

Change-Id: I499c7c62bff142529063df0fc65d9b3da3978379
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403676
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 14:51:12 +00:00
Robert Findley 556c550a38 internal/lsp/cache: invalidate packages that have added files
When a file is new or its package name has changed, we should invalidate
all packages for files in the current directory, not just packages
previously containing the file.

Fixes golang/go#52500

Change-Id: I9fc9857a7abcd4e730068871c899d274e1736967
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401795
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-05-02 22:20:22 +00:00
Robert Findley 4a3fc2182a internal/lsp: only linkify urls with http, https, and ftp schemes
Fixes golang/go#43990

Change-Id: I0ea26d521b2432238b05c26bfaccef6fc773dcf2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393854
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-02 22:00:12 +00:00
Bryan C. Mills 04fc2ba822 cmd/godoc: skip TestWeb if waitForServerReady fails
This test fails frequently, with a failure mode that is difficult to
diagnose. (golang/go#50436 may help with that eventually.)

For now, skip the test to reduce noise on the build dashboard.

For golang/go#50014.

Change-Id: I182be5c705846631c983bd5b6c51ab90b71a216a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403534
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-02 20:36:24 +00:00
Tim King 6872d3b8cd passes/unusedwrites: Add TODO for how to handle generics.
Adds a TODO to explain how to support generics, e.g. fn._Instantiations() should be included once available.

Refactors the run() function to make this simple in the future.

Updates golang/go#52503

Change-Id: Iec84f9bf200cab1026b19e1962165102be0a85ef
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403355
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Guodong Li <guodongli@google.com>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Guodong Li <guodongli@google.com>
Auto-Submit: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-02 19:39:36 +00:00
Tim King 7c895e061b pointer: Adds unit tests for pointer with type parameters.
Adds tests for pointer that test pointer flows through type instantiations.

Updates pointer_test.go to support one probe per instantiation. This is due to there being one copy of a Function per instantiation.

Updates golang/go#48525
Updates golang/go#52504

Change-Id: Ia750cd37ddf1aaf55342ff8464f12e96e7e1030f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402276
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Guodong Li <guodongli@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Guodong Li <guodongli@google.com>
2022-05-02 19:18:49 +00:00
Tim King ddadc42f5a guru: Add a TODO list to the guru cmd.
Adds a TODO list for the guru cmd. The main goal is document know
issues that we have not addressed.

Updates golang/go#47326
Updates golang/go#52503

Change-Id: I126b0f06081b606124d89a13f8805fa1ac6e56e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403354
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-02 17:10:57 +00:00
Tim King c39ac6a12f callgraph/vta: Removes dead return statement (misc cleanup).
Change-Id: Ie95810f8118eb8602b89b753d1567d8f50aaefd7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403356
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Auto-Submit: Tim King <taking@google.com>
2022-05-02 15:58:56 +00:00
Robert Findley aaffface24 internal/lsp/source: avoid panic in HoverIdentifier
Fixes golang/go#52211

Change-Id: I2ab5dbba4bb06092a234269d1ee65493f60fc6fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399622
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-29 18:06:40 +00:00
Russ Cox c862641ee9 cmd/digraph: only print non-trivial sccs
In 'digraph sccs', do not print trivial single-node components.
This is more useful because it distinguishes nodes with self-loops (printed)
from nodes without (not printed).

Also remove an unnecessary TODO about map[string]bool vs map[string]struct{}.
The savings is at most 5% and if we really cared about storage we would probably
not use a map at all.

Change-Id: I6049b3c0f99a913c65f08c6c40e77ae99d1ba8c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396834
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-04-29 02:53:01 +00:00
Dmitri Shuralyov 6fff1af1a8 go/analysis/passes/errorsas: update testdata for new warning
A new testdata file was added since CL 339889 was authored.
Update it in the same way for the new warning.

Updates golang/go#47528.
Fixes golang/go#52613.

Change-Id: I17d06c602eeabcc4ddc8514d5e444acdb714ab94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403034
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Tim King <taking@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-04-29 02:22:32 +00:00
Damien Neil 115b454b56 go/analysis/passes/errorsas: warn if errors.As target is *error
Passing an *error as the second parameter to errors.As always matches,
making this test:

	var e error
	if errors.As(err, &e) { ... }

equivalent to:

	e := err
	if err != nil { ... }

Warn when the second parameter to errors.As has type *error.

Fixes golang/go#47528.

Change-Id: Ia0e25003493f3b349ab500f0b4d08c2acf88b328
Reviewed-on: https://go-review.googlesource.com/c/tools/+/339889
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-04-28 23:10:42 +00:00
Zvonimir Pavlinovic 60b4456604 go/callgraph/static: adds tests for (instantiated) generics
Updates golang/go#48525

Change-Id: If460999912fecad626ec8cbace251dd6a0358196
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402695
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <alan@alandonovan.net>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-04-28 21:23:06 +00:00
Zvonimir Pavlinovic a37ba1418f go/callgraph/cha: adds tests for (instantiated) generics
Updates golang/go#48525

Change-Id: Id568e0b188dd045356f556cb9d759a775c8c5a04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402474
Reviewed-by: Tim King <taking@google.com>
2022-04-28 16:03:58 +00:00
Zvonimir Pavlinovic dcaea06afc go/callgraph/vta: adds tests for (instantiated) generics
Updates golang/go#48525

Change-Id: Ia84365d7f48f804f2b397782789706ef6d1d4b86
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402274
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2022-04-26 20:03:23 +00:00
Muir Manders b44fad8412 lsp/completion: fix func literals with type params
Give placeholders for type params in func literal completions. For
example:

    func foo[T any](func(T) T) {}
    foo(<>)

Will now give "func(<T>) <T> {}" where <> denotes a placeholder.

Change-Id: Iadde73ed6b88e1410c28dfa33a20ab6a51235c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400616
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-26 14:19:52 +00:00
Muir Manders 5bb9a5ecb1 lsp/completion: fix literal completions with type params
In cases like:

    type foo[T any] struct{}
    func bar[T any](foo[T]) {}

    bar[int](<A>)
    bar(<B>)

At <A> we will now offer "foo[int]{}". At <B> we will now offer a
snippet "foo[<T>]{}" which lets the user fill in the type arg.

Note that we have no knowledge of type inference, so you can be left
with superfluous type args after completion.

Change-Id: Ia7d63284f3317d9367864fdae3e3f9ae68fdff1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400615
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-04-26 02:30:39 +00:00
Muir Manders 0941294088 lsp/completion: further improve generic func arg ranking
In cases like:

    func foo[T int | string](T) {}
    foo[int](<>)

Previously at <> we would favor int and string candidates. This is
because go/types doesn't instantiate foo in this case (for some
reason). Work around the issue by using types.CheckExpr to re-check
the *ast.CallExpr.Fun. CheckExpr seems to do a better than a full type
check in the face of errors.

Updates golang/go#52291
Updates golang/go#52503

Change-Id: Ide436428f3232db2e06ea3cc22ea250edbf28685
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400614
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-26 02:29:50 +00:00
Robert Findley c9035635c7 internal/lsp/cache: don't cache parsed files when checking for metadata
changes

In principle, we should only parse through the cache when in workspace
mode, else we risk pinning AST in memory that we'll never need.
Alternatively: when unsure we should default to NOT parsing through the
cache.

For now, just update the logic to check for metadata changes to not
memoize its result.

Change-Id: I200af9ffb3353ba8065e46100a588dce6239dc66
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401794
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-25 23:52:26 +00:00
Tim King 825b661007 nilness: add unit test for generic instantiation.
Adds a unit test for generic instantiation to nilness.
Currently the expected behavior is to ignore the instantiation
as it is not added to builssa's SrcFuncs result.

Updates golang/go#52463
Updates golang/go#48525

Change-Id: I7b214aae88c8aa26605abb5019591178f76a7cbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402054
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tim King <taking@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-04-25 23:21:56 +00:00
Tim King 2548a8b1f5 ssautil: Add unit tests that set ssa.InstantiateGenerics
Updates golang/go#52463
Updates golang/go#48525

Change-Id: I07cac2c9ad8d08a96cd14d4c729b14cf224d7f2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402055
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tim King <taking@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-04-25 21:36:24 +00:00
Tim King ae12e8f2c7 ssa: switch lblocks to types.Object
Switches lblocks from *ast.Object to types.Object. Removes a user from the infrequently used *ast.Object.

Updates golang/go#52463

Change-Id: I1a21ab55b7136f4891f6aa2f76459880ace389c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402034
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-04-25 21:36:22 +00:00
Dylan Le 559469ae16 internal/lsp: render package documentation when hovering over a package import
Update FindHoverContext to retrieve & render package documentation for a hovered package. Add a regtest for this hovering feature.

Updates golang/go#51848

Change-Id: If57396d59be9c4cf7e09b64e39832de6f996c7ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400820
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Dylan Le <dungtuanle@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-25 17:29:41 +00:00
Muir Manders fa7afc95f2 lsp/completion: improve generic func arg ranking
In cases like:

    func foo[A int|string](a A) {}

    foo[_](<>)

We now prefer ints and strings at <> by matching against the type
constraint. Note that even if "_" is replaced with "int", we still
prefer strings since the type checker doesn't seem to want to
instantiate foo unless the params check out.

Change-Id: I0e7acfef0775752a96fcfe23e7e2e3d939820eee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394017
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Auto-Submit: Peter Weinberger <pjw@google.com>
2022-04-22 20:11:24 +00:00
Tim King d567bc1c22 go/ssa: monomorphize generic instantiations.
Monomorphize the instantiation of generic functions. Applies type
substitution while building the function instantiation.

Adds a new BuilderMode, ssa.InstantiateGenerics, to enable
monomorphization. InstantiateGenerics is turned on by the flag 'G' in
tools that specify the BuilderMode.

Adds a parameterized field to Program to detect when a MethodValue is
parameterized.

Thunk creation creates new MethodExpr selections. Adds a new methodExpr
type to construct a MethodExpr from outside of types, and selection
interface to generalize a *methodExpr and *types.Selection.

Tests x/tools/go/ssa/interp against the runnable examples in
$GOROOT/test/typeparam/*.go. Some additional models to support files.

Misc. cleanup:
- adding (*canonizer).instantiateMethod to create a canonical
  representative of a method.
- documenting builder.go
- adding (*subster).types that applies type substitution to a list.

Updates golang/go#48525

Change-Id: I885a4223900feaa3664e35caf8618d11ba16a2a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/356315
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-22 17:17:20 +00:00
Tim King 5d7ca8a1b5 go/ssa: return nil on parameterized types on MethodValue.
MethodValue now checks if a type is parameterized types and returns nil instead of proceeding. Parameterized types are not runtime types so they should not have method sets created or be added to Prog.methodSet. This is similar to what MethodValue previously did for interfaces.

Updates golang/go#48525

Change-Id: Ib9026ddc0167fd71afd3e5c194aadf20411b9cdf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400515
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-04-20 20:19:07 +00:00
Robert Findley 48a2cc8a0d x/tools: remove dependency on golang.org/x/xerrors
Now that golang.org/x/xerrors is no longer used, we can eliminate it as
a dependency. Also update x/mod to eliminate an indirect dependency on
x/xerrors.

Fixes golang/go#52442

Change-Id: Ia3087a64e70f132f2813aa28d28d8397e5ecfded
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401099
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-04-20 16:11:36 +00:00
Robert Findley 235b13d9b8 cmd/godoc: remove usage of golang.org/x/xerrors
Go 1.12 has not been supported for a while, so it seems safe to replace
usage of xerrors with the native support for wrapped errors in the
standard library introduced in Go 1.13. Remove this usage as a step
toward eliminating the xerrors dependency from x/tools.

If there is any reason to continue to use xerrors, please let me know.

For golang/go#52442

Change-Id: Ic1e5c14f4074b4685a926e884649b9032aaa0f53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401098
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-20 16:11:05 +00:00
Robert Findley b22f048f6f internal/jsonrpc2*: remove usage of golang.org/x/xerrors
As of golang/go#50827, gopls no longer needs to build at Go 1.12. This
was the only reason to continue using xerrors in the jsonrpc2 libraries.

Remove this usage as a step toward eliminating the xerrors dependency
from x/tools.

For golang/go#52442

Change-Id: I1a0a1bbf57e6606c66b99b27439adf6f65c26a60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401155
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-04-20 16:10:40 +00:00
Robert Findley bcfc38ff69 go/packages: remove usage of golang.org/x/xerrors
As of golang/go#50827, gopls no longer needs to build at Go 1.12. I
believe this was the only reason to continue using xerrors in
go/packages.

Remove this usage as a step toward eliminating the xerrors dependency
from x/tools.

For golang/go#52442

Change-Id: I8f7396491be58606be6a648ebbf2180bdbc907b5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401154
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-20 16:10:13 +00:00
Robert Findley 37590b385d gopls: remove usage of golang.org/x/xerrors
As of golang/go#50827, gopls no longer supports building at 1.12, and so
usage of golang.org/x/xerrors can be replaced with the native support for
error wrapping introduced in Go 1.13.

Remove this usage as a step toward eliminating the xerrors dependency
from x/tools.

For golang/go#52442

Change-Id: Ibf459cc72402a30a6c2735dc620f76ed8a5e2525
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401097
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-20 15:33:22 +00:00
Matthew Dempsky e854e0228e go/ssa: fix miscompilation of <<= and >>= statements
Unlike other binary operations, the RHS operand of a shift operation
does not need to have the same type as the LHS operand. In particular,
for "x <<= y" and "x >>= y" statements, coercing y to have the same
type as x can lead to miscompilation.

Fixes golang/go#52342.

Change-Id: I3ff139afa18f5637d527bd4a0b10d6b40ce53ab4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400394
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2022-04-19 22:48:11 +00:00
Michael Matloob c02adccb15 go/packages: ask for EmbedPatterns and EmbedFiles if needed
If the NeedEmbedPatterns or NeedEmbedFiles bits are set, then ask the go
command for the respective field in the JSON output. This fixes the
builder failure caused by golang.org/cl/393017

Change-Id: Ic659e59e7576141024c330f64201fe6c04edc032
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401095
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2022-04-19 20:39:06 +00:00