Commit Graph

6507 Commits

Author SHA1 Message Date
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
pjw 9ffa3ad372 internal/lsp: Provide completions for test function definitions
In test files, function definitions starting with
Test, Bench, or Fuzz can be completed almost automatically.

For the snippets the user hits tab, completes the name, hits
tab again, and the function is defined, except (of course) for its
body.

Otherwise a completion that fills in the signature is proposed.

Where appropriate, 'TestMain(m *testing.M)' is also offered as
a completion.

Fixes golang/go#46896 and golang/go#51089

Change-Id: I46c05af0ead79c1d82ca40b2c605045e06e1a35d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385974
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-02-25 19:27:31 +00:00
Suzy Mueller b7525f4396 internal/lsp: hash go version into package key
The go directive affects type checking errors so
it should be included in the package key.

I manually tested that this fixes the issue in golang/go#51325

Fixes golang/go#51325

Change-Id: I109859ae65e7e4d5fdefc63a0a7a838117ee02cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387914
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-24 19:04:43 +00:00
Robert Findley 5210e0ca15 gopls: wire in LangVersion and ModulePath for gofumpt formatting
If available, pass the LangVersion and ModulePath provided by
go/packages to gofumpt. This allows gofumpt to apply additional
formatting rules that require this information.

Also add a regression test for gofumpt formatting.

Fixes golang/go#51327

Change-Id: I47c8c96d595d62e1c444285ce69ce6a4e61fa74c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387634
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Daniel Martí <mvdan@mvdan.cc>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-24 18:08:50 +00:00
Robert Findley e6ef770939 go/types/typeutil: don't recurse into constraints when hashing tparams
When hashing signature type parameters, we recursed into their
constraints in an attempt to improve the accuracy of the hash
(signatures are considered identical modulo type parameter renaming).

This introduces a mechanism for infinite recursion via recursive
constraints, as reported in golang/go#51314. To fix this, we can hash
just the type parameter index and rely on types.Identical for
de-duplicating map entries.

Fixes golang/go#51314

Change-Id: Ifd7596d978b98293391bbe64f72f1da2b2a5d51c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387754
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-24 14:31:55 +00:00
Robert Findley 258e473066 internal/lsp/source: disable the useany analyzer by default
This analyzer was written at a time when any was only allowed in
constraints, and usage of any vs interface{} was more likely to be
confusing.

Any is now allowed anywhere, and so it is inconsistent to suggest it
only for constraints. However, we can't suggest any over interface{}
everywhere, as that would be incredibly noisy.

Perhaps we should remove this analyzer, but for now simply change it to
off by default.

Change-Id: Ib9726bdb835808d69827c6cd8e4a58dc5d83ad0e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387614
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-02-23 15:44:43 +00:00
Matheus Alcantara b7d29496b7 internal/lsp: don't store diagnostics for builtin.go
Fixes golang/go#44866

Change-Id: I9606df932c1b35d91816306fbcb48edc5b023b30
GitHub-Last-Rev: e6f525ed46a08ac77eac3af295c2be684405e88b
GitHub-Pull-Request: golang/tools#364
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386219
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>
Trust: Nooras Saba‎ <saba@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-02-23 15:43:26 +00:00
Daniel Martí 4f21f7a508 gopls: update gofumpt to v0.3.0
Also add a TODO inside the format.Options expression,
as we are not currently wiring up some information from the main go.mod.
The TODO comment contains a summary of what should be done.

Change-Id: Ibace6c36de4b729b5ba8b347f6f48f0a8fda695e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387374
Trust: Daniel Martí <mvdan@mvdan.cc>
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-02-23 14:43:16 +00:00
Michael Matloob 3e31058cd7 internal/imports: update to permit multiple main modules
Now that there there can be multiple main modules due to workspaces in
cmd/go, update internal/imports to no longer assume that there will be
exactly one main module.

Change-Id: I9d044df612fbeaba73b8fc3dbbec0395b54ecba2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386254
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Trust: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-22 17:36:43 +00:00
Suzy Mueller 43f084e593 internal/typesinternal: update typesinternal for 1.18
This CL adds the error codes introduced in
1.17 and 1.18.

Change-Id: I5646a2cdfe2b1a86756f3e9beb8b9c781d7cbccf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386874
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-02-22 16:42:18 +00:00
Robert Findley 897bd77cd7 internal/gocommand: remove support for -workfile
Remove support for passing the -workfile flag now that the go command no
longer supports it.

Updates #51215

Change-Id: I95d73fb1a3a6d9bcfaaae5e22e44722118d12c03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386536
Trust: Robert Findley <rfindley@google.com>
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-02-18 14:51:54 +00:00
Zvonimir Pavlinovic e6a7e13388 go/analysis/tools/internal/checker: add support for RunDespiteError
When there is a syntax or type error, we should run the analyzers that
have the RunDespiteError flag set to true, if any. The current code just
skips any analysis whatsoever.

For golang/go#51014

Change-Id: I5c3e5f3d9e2e8d791e9996b9114bb719e89daf30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/383974
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 18:43:27 +00:00
Robert Findley adcfb65266 internal/lsp/source: use the object as the hover source for type params
Use the type name object as the signature source for type parametes, as
it it efficiently formatted as "type parameter <name> <constraint>".

Fixes golang/go#51116

Change-Id: I3042ff248402dae833e3197c6ac320c2bd103c07
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385018
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:38:34 +00:00
Robert Findley 411d04022e internal/lsp/source: clean up the interface to hover information
Clean up the relationship between HoverContext and HoverJSON so that
HoverContext is more clearly responsible for collecting comment and
signature nodes, and HoverJSON is more clearly a DTO for the hover RPC.

Change-Id: Ib32d4151a53505d227b4225be4f87754a542e980
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385017
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:38:22 +00:00
Robert Findley 45aeaf7b04 internal/lsp/source: improve the heuristics for linkable identifiers
We should not offer links to variable or type declarations in function
scope. Improve our heuristics to check that the declaration object is
actually reachable from the package scope.

Also push down handling of private import paths, so that the
HoverJSON.importPath field can be removed.

Change-Id: I6edb3be3c37f479667c838beb49f97e7167b47a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385016
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:38:11 +00:00
Robert Findley a317113201 internal/lsp/source: fix hover on generic type declarations
Hover on type specs was using the RHS of the type declaration and then
later rebuilding the declaration syntax. It was thereby dropping type
parameter lists.

Fix this by capturing the entire *TypeSpec for the signature, and
simply dropping comments from the node before formatting, so that they
are not duplicated.

Change-Id: I58724e65bd1f2aada1a5c04e4c61a059bed8357a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385015
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:37:50 +00:00
Robert Findley 1f3875c379 internal/lsp/source: begin to refactor hovering with a HoverContext type
The logic to resolve hover information is hard to follow, due to various
indirection building up the HoverInformation struct, and the lack of a
definition for HoverInformation.source. Incrementally refactoring to
solve these problems is a tricky; as a first step, split out that
information which is shared with completion and signature help into a
new type.

Also refactor FormatHover to be a bit more uniform.

Change-Id: Ib4f30e5f7cd085a3280c31836df3840ee3466b4d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385014
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:37:24 +00:00
Robert Findley fd59bdfe0d internal/lsp/source: adjust object position when formatting full AST
Thread through an adjusted object position when we format an re-parsed
AST that wasn't type-checked to produce the object. Also remove some
unnecessary handling of the object type.

Fixes golang/go#46158

Change-Id: Ic8bee2bb4cb992d577d085599213fca1deab3b4e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/384697
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:37:03 +00:00
Robert Findley cda4201ef0 internal/lsp/source: simplify Identifier.enclosing
Receiver base types are either *Interface or *Named, never *Struct.
Absent a comment, I don't know why we had handling for *Struct, so just
delete it.

We only care about the enclosing type if it is named, so track a
*TypeName rather than an arbitrary Type.

Change-Id: I729c85b935a35da429b975327b56d81dc56773cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/384696
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-17 17:36:57 +00:00
Frediano Ziglio 59f1f2c5a8 cmd/goyacc: reduce array sizes using smaller base types
These arrays can be quite large, reducing the size of them
save lot of space reducing cache usage and file size.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Change-Id: I446088627bc135cb47f6bee919e147b24d1ad848
Reviewed-on: https://go-review.googlesource.com/c/tools/+/374434
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Ian Lance Taylor <iant@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-02-16 20:47:08 +00:00
Hana c6776771dd internal/lsp/cache: let Session.getGoEnv query GOWORK
This will make GOWORK value appear in the gopls log
when initializing the workspace. This CL does not include
GOWORK in `environmentVariables` (in view.go) (yet).

Change-Id: I16224d1ac50ac8209def008966371c6be858d05a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/385894
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: Heschi Kreinick <heschi@google.com>
2022-02-16 20:15:32 +00:00
Bryan C. Mills 9095d109eb go/analysis/passes/tests: fix a missed rename from CL 374495
The function printAcceptedFuzzType was renamed to
formatAcceptedFuzzType after PS6 of CL 374495, but the rename was
missed in one spot and didn't get caught by TryBots.

Updates golang/go#50198

Change-Id: Ib51d26b8c159dbdc3beeac9c7c98f19690e82228
Reviewed-on: https://go-review.googlesource.com/c/tools/+/386314
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-02-16 20:10:33 +00:00
Marwan Sulaiman 70c3ea29e2 gopls,internal/lsp: Implement method stubbing via CodeAction
This CL adds a quickfix CodeAction that detects "missing method"
compiler errors and suggests adding method stubs to the concrete
type that would implement the interface. There are many ways that
a user might indicate a concrete type is meant to be used as an interface.
This PR detects two types of those errors: variable declaration and function returns.
For variable declarations, things like the following should be detected:
1. var _ SomeInterface = SomeType{}
2. var _ = SomeInterface(SomeType{})
3. var _ SomeInterface = (*SomeType)(nil)
For function returns, the following example is the primary detection:
func newIface() SomeInterface {
	return &SomeType{}
}
More detections can be added in the future of course.

Fixes golang/go#37537

Change-Id: Ibb7784622184c9885eff2ccc786767682876b4d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274372
Reviewed-by: Heschi Kreinick <heschi@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-02-16 19:42:34 +00:00
Nooras Saba 2ff4db7dab go/analysis/passes/tests: Check malformed fuzz target.
This will validate that first letter after FuzzFoo() should be uppercase
Also, following validation will be performed for f.Fuzz() calls :
	1. f.Fuzz() should call a function and it should be of type (*testing.F).Fuzz().
	2. The called function in f.Fuzz(func(){}) should not return result.
	3. First argument of func() should be of type *testing.T
	4. Second argument onwards should be of type []byte, string, bool, byte,
	   rune, float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16,
	   uint32, uint64

For golang/go#50198

Change-Id: I540daf635f0fe03d954b010b9b5f8616fd5df47a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/374495
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2022-02-16 18:26:19 +00:00