Commit Graph

6507 Commits

Author SHA1 Message Date
Russ Cox e30967270c go/packages: rename NeedExportsFile to NeedExportFile
I'm going to use NeedExportFile in the go/gcexportdata example,
and we might as well start with the correct spelling.
Leave behind a deprecated alias to preserve compatibility.

Change-Id: Id26e5db58cb59a01ed7904ab801a894ea76edd9e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310509
Reviewed-by: Austin Clements <austin@google.com>
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 19:08:41 +00:00
Hana 54af36eca2 internal/lsp: handle invalid URL args in command params
beginFileRequest returns a nil error when file request url is
not a valid file url format. This is reported with a separate 'ok'
boolean return value.

This bug caused custom gopls commands to return success with
an empty result, instead of reporting the problem as an error.

Change-Id: I8eed39368087fa9928bcc68853225ea432f500d2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395814
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Jamal Carvalho <jamal@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-25 15:45:26 +00:00
Robert Findley 707beb0c63 internal/lsp/source: descend into fields and field lists in qualifyExpr
We do a lot of gymnastics to format var types, working around the lack
of alias tracking in go/types. As part of this, we clone and qualify
expressions. In this case, we were not qualifying identifiers that were
contained within fields or field lists.

Fix this by updating our expression traversal to include *ast.Field and
*ast.FieldList.

Fixes golang/go#50539

Change-Id: I6531c6a51aa402bd784778b8bedaa3dccee75af0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395678
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-25 15:26:50 +00:00
Hana 1e5ae8399a internal/lsp/command: remove unnecessary json struct tag
Different naming style for Vuln type is unnecessary.
And, we can safely assume that ID is not empty.

Change-Id: Ifd43b671c814796af0110bad05642187bb1ea655
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395677
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-24 22:38:08 +00:00
Hana b7db7eb670 internal/lsp/cmd: add vulncheck command
Usage: gopls vulncheck <package_pattern>

It prints json-encoded command.VulncheckResult in stdout.

Change-Id: I752b3f06d7c6b2c7de68bd1221283205955c383f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395676
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-24 22:38:00 +00:00
Hana c62a3b326e gopls/internal/vulncheck: limit the included callstack count
There can be a thousand callstacks. Currently the limit is 64.

Maybe we can do a better job to filter and choose the important
callstacks. For example, if we analyze A, B, C packages,
and get three callstacks when we want to report only 1,

  A -> B -> V
  C -> B -> V
  B -> V

one can favor B->V because that's where fixing needs to happen.

Change-Id: I0d27a74fd8743629b6845c8d01b01320442d4cd7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395674
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-03-24 22:31:57 +00:00
cuishuang 78ff15e680 tools: fix some typos
Change-Id: Iaad847631b9d5ee40558fcf9d51f4dfa99600e6b
GitHub-Last-Rev: 6fcb64f8d9a093e7bd949e5d28bd1176c27005c0
GitHub-Pull-Request: golang/tools#372
Reviewed-on: https://go-review.googlesource.com/c/tools/+/389595
Run-TryBot: Ian Lance Taylor <iant@golang.org>
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: Ian Lance Taylor <iant@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-24 22:24:35 +00:00
Hana f23240f570 gopls/go.mod: switch to golang.org/x/vuln/vulncheck
Instead of golang.org/x/exp/vulncheck

Change-Id: I9f0f1b84433409ad2053fec247a5f50a2e274142
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395694
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-03-24 22:11:06 +00:00
Robert Findley 4adadedf93 internal/lsp/source: handle empty strings in directoryFilters
Avoid a panic when a directoryFilters entry is empty.

Fixes golang/go#51843

Change-Id: I50948894ce60d83441c3fc698c2e7d80d1d2b50e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395675
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-24 21:16:24 +00:00
Robert Findley 2536df952b internal/lsp/source: include builtin name in hovered signature
Make builtin hover consistent with signatureHelp by reusing the
BuiltinSignature function. To simplify this, just precompute the builtin
signature. In later CLs we can pre-compute all signatures and eliminate
the signatureSource indirection.

Fixes golang/go#51811

Change-Id: I1babe64ba41f636bf455074a23ad6dac5539fb89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395294
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-24 20:26:13 +00:00
Hana cd31eaad03 internal/lsp/command: add RunVulncheckExp
This is a command that runs govulncheck-like analysis.
This is highly experimental and can change any time,
so we mark it with the "Exp" suffix. Once the interface
becomes stable, we will rename this command.

It returns VulncheckResult that can be encoded as
a JSON message. The result includes all potentially
affecting vulnerabilities, and sample traces.

This feature is currently available only when gopls
is compiled with go1.18. Otherwise, the command will
return an error.

Updates golang/go#50577
Updates golang/vscode-go#2096

Change-Id: Ia37b0555f7bf98760292c9f68e50fb70dd494522
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395576
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-24 19:25:58 +00:00
Hana 4737f45953 internal/lsp/command: add VulncheckArgs/Result types
And move types defined in gopls/internal/vulncheck
to internal/lsp/command so VulncheckResult can use them.

Another approach considered is to encode Vuln as a
json raw message. However, presenting the data structure
in gopls api documentation is too nice to give up.

Updates golang/vscode-go#2096
Updates golang/go#50577

Change-Id: I8587d19f9c47cf786dacaae8cfe1727c77cda711
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395575
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-24 19:25:44 +00:00
Hana 84a0321117 doc/generate.go: handle non-empty JSON tag correctly
When the JSON struct tag is present, we should trim the option part.

Change-Id: I1c9162cdb836ce1797939475188254c4c697ebda
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395577
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-24 19:25:29 +00:00
Hana 4460e9bc64 gopls/internal/vulncheck: copy x/vuln/cmd/govulncheck/cache.go
This is a utility that manages vulnerability information
local cache.

Updates golang/vscode-go#2096
Updates golang/go#50577

Change-Id: I1903a529adda499d078156c3f1ba38bfab75a958
Reviewed-on: https://go-review.googlesource.com/c/tools/+/395574
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: Jonathan Amsterdam <jba@google.com>
2022-03-24 18:41:54 +00:00
Hana 9fd677e179 gopls/internal/vulncheck: add cmd that runs govulncheck-like analysis
It is similar to the command line tool govulncheck, but takes
configuration parameters from the given snapshot and runs from
the root directory of the snapshot.

Currently we define result types in this package. When it is
wired to gopls to implement a custom command, they will be moved
to the internal/lsp/ command definition package.

This functionality will be offered only when go1.18+ is used
to build gopls.

Updates golang/go#50577
Updates golang/vscode-go#2096

Change-Id: I08ab6b408d0a40a86cfefff919ab670aa6b2859b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392538
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-03-23 19:01:26 +00:00
Zvonimir Pavlinovic b169789a50 go/ssa: add position information for switch case conditions
This allows better reporting in passes, such as nilness.

Updates golang/go#31008

Change-Id: Ie188844b550bf2b924747f3ac476dd6feeda6d6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394694
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-03-23 18:18:29 +00:00
Robert Findley 9814b1bf69 gopls: update settings link to code lenses
Make the change from CL 334209 in the source.

Change-Id: I923d857b77552d6c8d100ce97b6b86f29fbc4934
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393857
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-23 18:02:45 +00:00
Chris Koch 87a8611856 x/tools/go/packages: add Embed support
Add EmbedFiles and EmbedPatterns to the exported set of information in
the Package struct. Available on Go 1.16+, everywhere that go:embed is
available.

Fixes golang/go#50720

Change-Id: Ie84402ace1151fedaaa2a81c881d0e3d1e3ed9a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/379974
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Michael Matloob <matloob@golang.org>
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-22 21:30:29 +00:00
Muir Manders 1428e83b47 lsp/completion: fix bogus generic func conversion
For example:

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

    var _ int = fo<>

Previously at <> we would complete to "int(foo[A int|float64](a A))".
We added the int() type conversion because the returned type param A
was convertible to the expected "int" (i.e. both "int" and "float64"
can be converted). This is a premature suggestion, though, so fix by
suppressing such type conversions for type parameters.

Fixes golang/go#51780.

Change-Id: I63e3bd401a4d9927b9261659812c521c02e33d94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394016
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>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-22 17:37:31 +00:00
Muir Manders cbdab0337f lsp/completion: fix bogus type param candidate
In this example:

   func foo[A []int | []float64]() {}

   foo[<>]

When completing at <> you were getting the creative candidate
"[]int | []float64". This came from some code that makes the expected
type available as a candidate if it wouldn't otherwise be found by a
lexical search. I tweaked the code in this case to instead look at
each structural type in the type constraint rather than the constraint
as a whole. In the above example you now get the candidates "[]int"
and "[]float64".

Change-Id: Ib8e422df3009cb4253ec66005b4a53851564c4e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394015
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>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-22 17:37:20 +00:00
Muir Manders 3a6cbd67dd lsp/completion: improve completion for func type params
Now when instantiating a generic function, we prefer type names that
are assignable to the corresponding constraint. For example:

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

    foo[<>]()

At <> we prefer the type names "int" and "string". Previously we had
no preference at all.

Updates golang/go#51782.

Change-Id: I7ed39ffa2bc4c63e9d320f47a58e139251712bb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394014
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>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-03-22 17:36:59 +00:00
Cherry Mui c717623e31 go/analysis/passes/asmdecl: define register-ABI result registers for PPC64
So "go vet" works for register-ABI assembly functions.

Change-Id: I875e613f22ead19ea30b7f9f6c70a665df109d4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394234
Trust: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-21 17:03:18 +00:00
Robert Findley 86b02b36c4 internal/lsp/cache: check for nil WorkFile.Go
Fixes golang/vscode-go#2121

Change-Id: Icf44c8bb4079c0bcba83a9512f939260bbb5b6de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393856
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-21 13:26:21 +00:00
Robert Findley 5ea13d0d89 internal/lsp/source: move doc links to the bottom of hover
Fixes golang/go#36992

Change-Id: Ie4b749ba6c094c4559a9b3a3e5b63c0b4cbc5dcf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393642
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-18 13:39:41 +00:00
Suzy Mueller 779dfa4fb2 internal/lsp: invalidate package on go.mod change with go.work
If a go.mod file is updated, the packages
in that module may have updated type check
errors since the go version can affect errors.

Fixes golang/go#51732

Change-Id: I3a8cd8b9ab267336ccc5c841a14c5ec5f6c986e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393534
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-17 21:30:21 +00:00
Peter Weinbergr c7b0e9aca6 internal/lsp/template: fix processing of multi-line tokens
Aside from the logic error, the root flaw was inadequate
test coverage.

Fixes golang/go#51731

Change-Id: I50787a951ab742700d9890b4b5232e90189cb8ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/393634
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: Suzy Mueller <suzmue@golang.org>
2022-03-17 15:18:29 +00:00
Hana e998cd2c59 internal/lsp: remove unused code
Change-Id: Id2a88b9826598de539aeea5c3983df279aa0c6c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392657
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:41 +00:00
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