Commit Graph

6380 Commits

Author SHA1 Message Date
Hana 877ec07e2d internal/lsp/cache: remove unused code
Change-Id: I7bafb1555ab7d35b9c49138c915b6c6c781e92c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392656
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: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-17 13:53:34 +00:00
pjw 85d68bc98d internal/lsp: update LSP stubs, including provisional InlayHints
There are also new InlineValue RPCs.

Change-Id: I4ba6d4c112760a5c5a199287843c61071a7f59a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390334
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Kortschak <dan@kortschak.io>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-16 22:16:36 +00:00
Heschi Kreinick fb5dfde700 internal/imports: update stdlib index for 1.18
Updates golang/go#38706.

Change-Id: I3e99e4dbe731b51a24e84c4381f440d3bc4cd4e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393379
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-16 21:19:09 +00:00
Robert Findley d67eab4bce go/types/objectpath: break cycles through type parameters in find
When searching for objects, we naively traversed through type parameter
constraints. This leads to infinite recursion when there are cycles
through type parameter constraints.

Break these cycles by tracking type parameter names that have previously
been encountered. This ensures we walk type parameter constraints at
most once. Note that if the desired object was not found on the first
search of the constraint, there is no need to search again.

For golang/go#51717

Change-Id: Ifcdf4b138a0e95441e485bbb9ee21c01b04eaed4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393376
Trust: 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>
Reviewed-by: Robert Griesemer <gri@golang.org>
2022-03-16 21:09:13 +00:00
Peter Weinbergr 77aa08bb15 internal/completion: default to regular completion for f.Fuzz without f.Add
Change-Id: I7a05dba3f4a68c2075ebdf078e9e0ee6cfd97f28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393019
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-16 01:41:57 +00:00
Robert Findley 6799a7ae92 internal/lsp/source: canonicalize objects in reference/rename requests
With generics, instantiated object may have differing pointer
identities. Fix references/rename requests for instantiated
methods/fields by using a canonical object identity of (pos, pkg, name).

Fixes golang/go#51672

Change-Id: I0021ca562b8a74dadb616cf6864cb0bdd0165cc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392480
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-15 13:54:34 +00:00
Josh Humphries 54a569a9db internal/imports: use first quote when matching import path
This fixes the regexp used to extract the import path from a line of code
when inserting newlines to split a sequence of imports into groups.

By using a non-greedy match, the regexp now functions correctly in the
face of an extra quote after the import path (such as when there is a
trailing comment that includes a quote).

Fixes golang/go#51671

Change-Id: Id7fd0b1d794f989d8f3d47336c5b5454cddd6237
GitHub-Last-Rev: b934371fa6d9ded902deac2268658b4485d9ce70
GitHub-Pull-Request: golang/tools#365
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386914
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-15 00:13:15 +00:00
Robert Findley 40370f8a2a go/internal/gcimporter: add a test case for issue 51219
Based on CL 387814, construct a reproducer for issue 51219 using
x/tools/go/internal/gcimporter.

Confirmed that this fails without the fix in CL 392475.

Additionally, this CL includes some minor cleanup:
 - no need to take two passes in testExportSrc, as
   IExportVersionGenerics and IExportVersionGo1_18 are the same
 - remove skips that are no longer needed.

Fixes golang/go#51219

Change-Id: Ia76fe9038aab7a2b9efc8429dc211b03adbb5560
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392734
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-14 21:01:25 +00:00
Suzy Mueller 24806f2a30 go/analysis: add tests check for calling *F methods in fuzz func
The only *F methods that are allowed to be called from the function
passed to (*F).Fuzz are Named and Failed. This check looks for
other methods and will report errors.

Change-Id: I30ec546d11f9e9b38ee673c5a0e7cf0fde8ca922
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390974
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-14 20:31:55 +00:00
Robert Findley dff7c5f22f go/internal/gcimporter: guard against infinite recursion with recursive
type parameters

This is a partial port of CL 386335 to x/tools. I have not yet been able
to reproduce the crash in a test.

For golang/go#51219

Change-Id: I262e6a9dba936b18513ee5f11a2a72d4155d3833
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392475
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-14 20:05:58 +00:00
Abhinav Gupta 49d48a0b4c go/analysis/passes/composite: allow InternalFuzzTarget
Add InternalFuzzTarget to the allowlist for the composites analyzer.
Other testing-internal struct types produced by the testmain generator
are already in there.

Fixes golang/go#51623

Change-Id: Ibf91d476ea781c97835157973efc97ce0f987665
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391875
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Jamal Carvalho <jamal@golang.org>
Trust: Michael Matloob <matloob@golang.org>
2022-03-14 14:50:06 +00:00
Tim King 198cae3729 go/ssa: split pkg() into different cases for *Package and *types.Package
Splits (*Function).pkg() into different cases for returning a *Package and the *types.Package.

Updates golang/go#48525

Change-Id: I1c59679c5acd898cf2009a2e3a0ea96b62f82a06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391334
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>
Trust: Tim King <taking@google.com>
2022-03-11 22:34:28 +00:00
Michael Matloob ee31f70645 internal/lsp: add completion for use directives
For golang/go#50930

Change-Id: I9def58e9406ee735c93e988de336dbfee37e6c95
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390054
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-10 23:20:43 +00:00
Michael Matloob 622cf7b338 internal/lsp/cache: copy workFile when invalidating workspace
to avoid losing workFile information when that happens. This fixes an
issue where diagnostics, hover, etc didn't show up after the initial
load when some changes were made to go.work files.

Change-Id: I42e2dcfd94a5b4726856ab0a4d8dfc9c1efc48b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391257
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-10 22:50:41 +00:00
Tim King e7a12a333d go/ssa: add type substitution
Adds a type substitution cache for substituting type parameters.

Updates golang/go#48525

Change-Id: I4f864b914f3237e7aae9b4bc1529d3bd7bd4540f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390154
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-10 22:31:14 +00:00
Robert Findley c773560c36 internal/lsp/cache: set GOWORK=off when mutating modfiles
Commands will fail with -mod=mod when GOWORK is set. Explicitly set it
to off.

Fixes golang/go#48941

Change-Id: I39f9d95526ca6f3b0414ff273cecd443d69afa61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391518
Trust: 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>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-10 21:45:24 +00:00
Peter Weinberger 613589de97 internal/lsp: more precise completions for *testing.F fuzz methods
The argument to f.Fuzz is determined, up to the names of arguments,
by the types of the arguments to f.Add. Inside the function argument
of f.Fuzz, only f.Name and f.Failed are allowed.

(The fset passed to fuzz was for debugging. When the change seems solid
it can be removed.)

Fixes golang/go#51089

Change-Id: Icf8b8cdfd29e499bcc605a358ca9edaef5baa835
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387615
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-10 19:52:31 +00:00
Suzy Mueller 9f99e956bf go/analysis: add analyzer for f.Add
Calls to f.Add must have arguments of the same types
as the function signature passed to f.Fuzz (excluding testing.T).
This checks that all calls to f.Add in a function declaration
have the same number and types.

This will have some false positives, because it does not check
to see if the call to f.Add is a no-op.
This happens if f.Add is called after or in f.Fuzz.

This can be fixed by adding a heuristic for when f.Add is a noop.
There also should maybe be an analyzer that reports these noop
calls to the user.

Updates golang/go#51398

Change-Id: I49b2ed19cb55347abb9a48960b83b8376b7e6a1d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390614
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-10 18:38:22 +00:00
Hana 7b442e3cf4 go/callgraph/vta: fix package doc
A blank line prevented go doc from picking up the package doc.

Change-Id: I40ddb95d0e38ee0809a852205f399d18f9d68be3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391514
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: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-03-10 17:32:03 +00:00
Suzy Mueller 1670aadab3 go/analysis: fix bug with finding field type
There was a bug that attempted to index the type
parameters list using the parameter index.
Each field in the list can have multiple names declared so
we need to instead search for the appropriate field.

Fixes golang/go#51577

Change-Id: Iff4671eb71fc0a4f207f3d0f8835f30ae99bf275
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391235
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-09 23:03:58 +00:00
Tim King fd72fd66f6 go/ssa/interp: adding external functions for tests
Adding additional external functions to be available for go/ssa/interp's testdata.
These functions are used by main files in $GOROOT/test/typeparams/*.go

Updates golang/go#48525

Change-Id: I80b280e2efb4616d24b50ccf3d2aefa7b486a893
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390294
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-09 22:54:42 +00:00
Suzy Mueller b105aac570 internal/lsp: use regexp to add go mod edit -go quick fix
Fixes golang/go#51086

Change-Id: Iebe51355e016809442af37debf140d9ba2f3317a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390615
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Suzy Mueller <suzmue@golang.org>
2022-03-09 21:08:21 +00:00
Robert Findley 03d333aa5e internal/lsp: add snippet completion for function type parameters
Fixes golang/go#51544

Change-Id: I29cf2a0fe878eed263b406ff3ebf1eaeffe10e4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390854
Trust: 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>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-03-09 15:55:38 +00:00
Russ Cox 94322c4f17 go/internal/gcimporter: pass -p to compiler in test
An upcoming Go 1.19 change will make -p required
when invoking the compiler. Fix this test to add it.
(See CL 391014.)

Change-Id: I874e6e2c3a03e1368ccfe2c770a694824c254c5b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391034
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-09 15:42:41 +00:00
Robert Findley b59c441bdb internal/lsp/cache: always consider go.work files for ws expansion
If a go.work file is present, we activate the workspace mode regardless
of the experimentalWorkspaceModule setting.

Fixing this also revealed a long-standing bug in traversing parent
directories. Amazingly I have no recollection of this bug being
reported, but it is far more likely to be hit with go.work files, when
users regularly open nested subdirectories.

Fixes golang/go#51477

Change-Id: I310a11b14f3bbc18fdd604c5c0ec33d7ee8f1174
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389300
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-07 16:11:49 +00:00
Bryan C. Mills e155b03a0e cmd/getgo: exec main from TestMain instead of running 'go build' in tests
This was noticed from
https://build.golang.org/log/da703ece9e1626eaeabf485e1a3a8180a6bde512,
but I suspect not relevant to the getgo test failure observed there.

Updates golang/go#28387

Change-Id: I1a156e780beabb13b4df6fd5313d4785aeb26e97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390075
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-04 20:37:47 +00:00
Michael Matloob e562276505 internal/lsp: add hover for go.work use statements
Show the module path of the module being used.

For golang/go#50930

Change-Id: I90a67e12182ffb457876b1fbc95aeb56ff632878
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389301
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-04 19:55:36 +00:00
Michael Matloob 121d1e448f internal/lsp: report diagnostics on go.work files
Report diagnostics on use lines where the directory doesn't have a
go.mod file, and on syntax errors in go.work.

For golang/go#50930

Change-Id: Idab36b43d86c4842f8eecd5c071ce0587e6f27b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389317
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-04 18:29:58 +00:00
Bryan C. Mills 0eabed704f cmd/file2fuzz: exec main from TestMain instead of running 'go build' in tests
This may address a test hang observed in
https://build.golang.org/log/da703ece9e1626eaeabf485e1a3a8180a6bde512.

At the very least, it should make the test much more efficient.

Change-Id: I6a41f9704c8a95276c904f0aee57c4521d642ea7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/390074
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-03-04 18:26:08 +00:00
Daniel Martí 19fe2d77ce gopls: update xurls dependency, remove \b workaround
Update to v2.4.0, which brings optimizations and minor improvements.

Upstream fixed the issue with word breaks in v2.3.0,
released back in July 2021. For more, see:
https://github.com/mvdan/xurls/issues/49

In short, ASCII TLDs now require a word break in Relaxed again.
Note that non-ASCII TLDs don't require one, as that just breaks them.
So, in that sense, this is making non-ASCII TLDs work in gopls again.

Plus, we avoid wasting CPU cycles at init time by rebuilding the regexp.

Change-Id: Iddb34827b61594fa1f911143f1d7e2c67a6658c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389814
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-04 09:11:28 +00:00
Marwan Sulaiman 3ce772872c internal/lsp/source: support stubbing concrete type params
This CL adds support for generating method stubs for named types
that have type parameters and want to implement an interface.
See internal/lsp/testdata/stub/stub_generic_receiver.go for an example.
Note, this CL does not yet support type params on interface declarations.

Updates golang/go#37537

Change-Id: I2a2a18d364b2b489e2fbd8a74dfed88ae32d83b5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389654
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
2022-03-03 22:52:16 +00:00
Michael Matloob 3286927895 internal/lsp/cache: construct workspace even when go.work has error
Before this change, newWorkspace would fall back to other workspace
types if there was an error parsing go.work files, or one of the
workspace modules did not exist. Instead, in those cases, newWorkspace
now successfully builds a *workspace with an error set.

This respects the user's intent when working with a go.work file so that
gopls can surface a diagnostic with the error.

Change-Id: Icfc2cad270111c03d53137fa8f1b2ee9b75093c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389314
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-03 21:30:30 +00:00
Tim King 09e02016f1 go/ssa: determine whether a type is parameterized.
Adds a type visitor to ssa that determines whether a type is parameterized or not.
Adapted from go/types/infer.go.

Updates golang/go#48525

Change-Id: I06285c6753ba8c5aab2dfe418556fdcf2b2f9437
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386317
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-02 23:25:03 +00:00
Tim King e43402d285 go/ssa: changes Package.values to objects.
Changes the Packages field named values (map[types.Object]Value) to a field named objects (map[types.Object]Member).

This is in preparation for generic functions. Generic functions are expected to be package level Members but not Values in the v0 implementation.

Updates golang/go#48525

Change-Id: I4c283fd3b715eeccad377346adc3ba718a1b741f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386814
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-02 22:41:01 +00:00
Tim King a972457a5f go/ssa: adds *types.Info field to ssa.Function.
Adds a *types.Info field to ssa.Function. This field is used for building the function instead of fn.Pkg.info. This allows for building a Function after its containing Package finishes its create phase. Building an instance of a generic function from another package requires this.

Updates golang/go#48525

Change-Id: I294f71bb5d513e4076efebf05b718ec75a47312a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386634
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-02 21:27:47 +00:00
Tim King fc479468e8 go/ssa: Move BasicBlock operations into block.go
Move the BasicBlock related functions and methods into their own file.
Miscellaneous cleanup.

Updates golang/go#48525

Change-Id: If1c89cf53a4dba25d0c8b703e53c79eb27957f9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386316
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Tim King <taking@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 20:04:29 +00:00
Suzy Mueller 7103138b8b gopls: add regtest for edit go directive quick fix
Change-Id: Id02a51b8513e11c688a1da9e7e1af66481d4881e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389255
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 18:52:17 +00:00
Suzy Mueller 4a5e7f0db6 internal/lsp: correctly apply file edits for edit go directive
Fixes a bug where the go mod edit -go=version file edits
are never actually applied.

Change-Id: Id055b0fad3399a00e1245556eb39073f15be09d9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389216
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 18:47:53 +00:00
Tim King 6a6eb596e7 go/ssa: Put type canonicalization on own mutex.
Put Program level type canonicalization on its own Mutex. With generics, canonical types are requested whenever instantiating a type. This simplifies when canonical types can be requested at the cost of maintaining two typeutil.Hashers.

Updates golang/go#48525

Change-Id: I2376a43e43f410d10a6d87158816e728aba746ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386315
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Tim King <taking@google.com>
2022-03-02 18:21:00 +00:00
Robert Findley afc5fce285 gopls/doc: address additional comments on workspace.md
This CL addresses an additional comment from CL 388994, changing the
example to move the go.work file outside of the repo.

For golang/go#51206

Change-Id: I576615f9bbcc676f3f78a959ad509b9dbab3b00e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389234
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 17:29:27 +00:00
Robert Findley abbbcaf758 gopls/doc: update the documentation for workspaces to suggest go.work
For golang/go#51206

Change-Id: I6d2b137afe0222d0ef8e87869111b148931d4fac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388994
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 15:39:07 +00:00
Simon Drake 72442fe040 gopls: update neovim documentation for imitating goimports
The existing example is no longer recommended as it can have unintended
consequences; for example, if it is run while the cursor is in an
incomplete struct, it will fill in all struct fields.

This is described more at https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-866632451

Change-Id: I3640ddb747a69c864675c0483032037a5e777d59
GitHub-Last-Rev: 2335f017eb967785da28ddb1bc48fb820d59a07e
GitHub-Pull-Request: golang/tools#371
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389194
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-02 15:07:28 +00:00
Bryan C. Mills ffa170dc4a internal/jsonrpc2_v2: fix a racy map assignment in readIncoming
If a call request comes it at the same time that a response becomes
ready for another call (either via an explicit Respond call or the
return from a Handle call), the map read and deletion for the response
could race with the map assignment for the new (incoming) call.

Change-Id: Ifd81dbc490486251e81c7eeae438806356f514af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388595
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-01 21:32:50 +00:00
Simon Drake 625c871d3c gopls: update neovim documentation for using go.work
For golang/go#50955

Change-Id: I8882239868d060a444466a466d30c3de9aaa31ef
GitHub-Last-Rev: 6395f147165c7947eae50719fb03e65d95a4debf
GitHub-Pull-Request: golang/tools#370
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388576
Trust: Nooras Saba‎ <saba@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: 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-03-01 19:24:28 +00:00
Than McIntosh fb3622a928 signature-generator: add Go func signature fuzzing tools
Add a new subdirectory 'signature-fuzzer' to the x/tools/cmd
directory, with contents:

  internal/fuzz-generator      Guts of the signature fuzzer
  fuzz-driver                  Simple driver for the fuzzer
  fuzz-runner                  Test harness for doing iterative fuzzing

This set of tools is primarily of interest to compiler developers as
opposed to end users. The fuzzer generates random Go code with
"interesting" randomly chosen function signatures (random numbers of
parameters of randomly generated types), then emits code to call these
random functions with known inputs, as well as code that checks to
make sure parameter values were passed correctly and that returns
worked.  The generator tries to include odd scenarios and corner cases
(e.g. reflect calls, recursion, blank params, zero sized types, etc)
so as to explore all the nooks and crannies of the compiler.

This fuzzer was used during the bringup of the new register ABI (as
part of Go 1.17) to identify odd corner cases and flush out bugs. It
may be useful in the future if we have to support new ABI versions or
bring up register ABIs on new architectures.

See the README.md for more details.

Change-Id: Icbc89ddd07c3909a44a005deab43720c7a0dffde
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350329
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-01 16:32:20 +00:00
Bryan C. Mills 5d35a75079 internal/jsonrpc2_v2: clarify documentation
For golang/go#46520

Change-Id: Id9cdb539ae6f16e03d02f3b00b0b5ee06042a42f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388594
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-01 14:55:09 +00:00
Robert Findley abc106cd59 gopls/integration/govim: build gopls using go1.18rc1
Govim tests expect error messages to use 'any', so build gopls using the
RC.

For golang/go#51056

Change-Id: I0f8cab5d7eea3efbbd5b3f3dd9918e85831c2d50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388436
Trust: 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>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2022-02-28 21:15:24 +00:00
Suzy Mueller c2ddf3dda2 internal/lsp: add quick fix for unsupported feature
Adds a command to run go mod edit -go to allow
users to easily upgrade their go directive.

Doing this change also revealed that changing
the go directive does not invalidate the type check
data and there may be stale diagnostics for a package.

Updates golang/go#51086

Change-Id: I659a216059c489a88e29cd51b944c3a0274f3700
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386875
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-28 18:28:20 +00:00
Hana 0e44f7a8a7 gopls/doc/advanced.md: correct commands for unstable version build
`go get golang.org/x/tools/gopls@master ...` resulted in warning messages like:

go get: installing executables with 'go get' in module mode is deprecated.
        To adjust and download dependencies of the current module, use 'go get -d'.
        To install using requirements of the current module, use 'go install'.
        To install ignoring the current module, use 'go install' with a version,
        like 'go install example.com/cmd@latest'.
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

Change-Id: I1299983604c27e333f02af875826b5dd4d170068
Reviewed-on: https://go-review.googlesource.com/c/tools/+/388074
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-28 18:07:53 +00:00
Tim King acdddf6756 go/ssa: allows right operand of a shift to be signed.
Removes the forced conversion of the right operand of a shift to an unsigned type. This allows for clients to correctly model the runtime panic when a signed shift count is negative.

Fixes golang/go#51363

Change-Id: If59000eeb503fd45cdc6d4143dcc249242e7a957
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387995
Trust: Tim King <taking@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Trust: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-25 23:02:25 +00:00