Commit Graph

6048 Commits

Author SHA1 Message Date
Zvonimir Pavlinovic ecbcf3a282 go/callgraph/vta: improve support for function value flow
Nodes involving function types should be treated the same way as the
nodes involving interfaces. This was not the case earlier, causing vta
to miss producing edges for, say, struct fields that are functions. This
CL addresses that.

Change-Id: I1f6969868babfd0eeec8991f7403192d4ba0afe3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350732
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-09-22 15:47:37 +00:00
Francesco Renzi b98090b833 internal/lsp/analysis/implementmissing: add analyzer
This adds an analyzer that provides suggested fixes for undeclared name
errors on function calls, implementing a stub of the fuction (with an
empty body). As of now this doesn't try to guess returned types but
only parameters.
Generated functions are appended at the end of the file where these type
errors occur.

Updates golang/go#47558

Change-Id: Iaef45ada6b7b73de1fbe42e5f7e334512b65e6c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348829
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-21 20:35:14 +00:00
Robert Findley 0d12d39b86 internal/typeparams: update to the new Instances API
This CL updates the internal/typeparams package with the new API from CL
349629, switching Info.Inferred to Info.Instances.

Change-Id: I8f98dc39c844ef8891863c08b747f63924ab1c53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351250
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-21 18:37:00 +00:00
Robert Findley fe076c893b internal/typesinternal: document ReadGo116ErrorData
Change-Id: I5afe3e4d3f137758da404e779d6bc9b0a57b6a02
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351089
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-21 03:32:29 +00:00
Robert Findley 91c880c34d go/internal/gcimporter: add support for exporting the 1.18 export format
This CL adds support for the Go 1.18 export format to iexport.go. This
support is based on cmd/compile/internal/typecheck/iexport.go, though
with a different types API and adjusted to build at Go versions below
1.18.

Specifically, this CL adds support for both column details in positions,
and generic types and functions. Along the way, some minor adjustments
are made to aid in debugging and testing.

Notably, after this CL the export data version produced by
go/gcexportdata will depend on the Go version used to build.

As part of this change, TestIExportData_stdlib is unskipped for Go 1.18.

Fixes golang/go#48392

Change-Id: I1b218e0acd4864de5c7b89706192273bc7850ffa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351029
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-09-21 02:24:06 +00:00
Robert Findley d2417d5c08 gopls/doc: add instructions for the new "kokoro rerun" feature
Change-Id: Idb7ed8ab7f736cac10be1e9d5592e1ffb3f048eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/351090
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>
2021-09-20 19:55:18 +00:00
pjw 464a8874ca internal/lsp/templates: replace panic by logging
There were two panics that cannot happen (meaning they are inconsistent
woith my understanding of the documentation). These are being
replaced by logging, as if they happen, they will happen deterministically
again if the user restarts gopls and does the same thing.

Change-Id: Ia405ad2883cedcf3de6cb1376eedb0f9250c61e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350110
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-20 18:36:32 +00:00
pjw a0016a2ade internal/lsp/diagnostics: avoid erroneous error message for orphaned files
If the user changes the extension of a go file while editing,
the existing code complains 'No packages found for open file'.
This error messsag is not helpful and this CL avoids it.

Change-Id: Idf426f1ce8b83b23757f81aa1f322fea86df9d82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350789
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-09-20 15:08:51 +00:00
Pontus Leitzler 7559231edc internal/lsp/command: fix typo in comment
Fix a typo in docs for MarshalArgs in internal/lsp/command.

Change-Id: Ib11a31f27b4ebb03b6eecd996ccf600154cd3cd0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350551
Reviewed-by: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Trust: Pontus Leitzler <leitzler@gmail.com>
2021-09-19 16:34:52 +00:00
Rebecca Stambler 2758b0478a gopls/api-diff: create api-diff command for gopls api
This change adds a command that can be used to see the difference in
API between two gopls versions. It prints out the changes in a way that
can be copy-pasted into the release notes.

Also, only run the copyright test with 1.18. I wanted to do this before
to use filepath.WalkDir, but now it also doesn't work with generic
syntax (it doesn't use packages.Load, so doesn't respect build tags).

Fixes golang/go#46652

Change-Id: I3670e0289a8eeaca02f4dcd8f88f206796ed2462
Reviewed-on: https://go-review.googlesource.com/c/tools/+/327276
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-09-17 17:58:44 +00:00
Zvonimir Pavlinovic aba0c5f15e go/callgraph/vta: optimize scc type initialization
During type propagation, initial types for an scc are two times stored
to a map: once they are computed and the second time when they are saved
to the type set of the scc. This CL ensures only one traversal is done.

Change-Id: I7f6babae6a1130721c467e33da4f2d23462116d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350160
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-09-17 16:17:54 +00:00
Marwan Sulaiman 1a7ca93429 internal/lsp/source: update SuggestedFixFunc to accept source.Snapshot
As part of the work for implementing method-stub code generation,
this CL updates the function signature of source/command.go's SuggestedFixFunc
so that a command can operate on the entire source.Snapshot to analyze
and change multiple packages and their files.

Updates golang/go#37537

Change-Id: I8430b2189ce7d91d37ab991f87ba368245293e56
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279412
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-15 18:56:22 +00:00
Rebecca Stambler 76d4494227 internal/lsp: fix panic in find references on Error
Our find references don't support (error).Error, but in this case, find
references actually panicked.

Fixes golang/go#48400

Change-Id: I68d6ea93528dc5425f59f0e952f03081c5a7847a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350132
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-15 17:19:52 +00:00
Robert Findley 4ba3eff04f gopls/doc: remove -tags=typeparams from generic build instructions
As of CL 349949, this is not longer necessary.

Change-Id: Ie89a7771f5873c4acea54f4c2507b76ec9832706
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350089
Trust: Robert Findley <rfindley@google.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-15 14:06:14 +00:00
Robert Findley 02e5238467 go/internal/gcimporter: rename instType to instanceType
This was suggested in CL 349949, and is done in the standard library in
CL 350031.

Change-Id: I3e7e3a5f56026ec5a9df7acab3079dc92ea07efb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350032
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-15 09:43:47 +00:00
Robert Findley 0cffec9e30 go/internal/gcimporter: update iimport.go to support type parameters
This CL pulls in the latest changes from go/internal/gcimporter, while
avoiding breaking the build on older go versions. To help maintain
compatibility with older Go versions while minimizing the diff with the
standard library importer, the internal/typeparams package was
significantly expanded.

I decided to use type aliases in the internal/typeparams package on Go
version >= go1.18, and placeholder types on Go version < go1.18. This
reduces the amount of copying needed in the APIs, though it might not be
the best decision if we ever decide to export this package.
Documentation was also updated to be more concise and specific to the Go
version being used.

In order to actually fix the x/tools Trybot for packages using generics
in the standard library, we need to switch from the 'typeparams' build
constraint to the 'go1.18' build constraint. This means if we make any
additional API changes in go/types we'll have to submit them with a
broken x/tools Trybot and then immediately fix the x/tools build.

Change-Id: Ifa0b1c37b89dc549ee295fa3a959f03deda86e56
Reviewed-on: https://go-review.googlesource.com/c/tools/+/349949
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-15 00:13:36 +00:00
Robert Findley 5492d01d98 internal/lsp/testdata: update inferred.go to use hoverdef
Change-Id: I0245a594680c8aaf6e2664eafd97ed8ad5ce0ac3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350029
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-14 23:55:15 +00:00
Robert Findley 92077074d4 go/internal/gcimporter: skip TestIExportData_stdlib on go1.18
This test will fail on Go 1.18 once standard library changes are
introduced that use generics. Skip it until iexport.go has been updated
to support generics.

Updates golang/go#48392

Change-Id: I0f779689daaf2bc3127affff633c883ed9d7289b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/349954
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-14 22:36:57 +00:00
Jean-Hadrien Chabran cd7c003cd3 internal/lsp: add support for hovering runes
Enable to hover runes found in basic literals in various forms.
When a rune is found, the hover message provides a summary composed of a
printable version (if it exists) of the rune, its codepoint and its name.

Behaviour varies slightly depending on the basic literal: rune literals
always display the summary when hovered, string literals only display it
when an escaped rune sequence is found to avoid providing unnecessary
information, and finally number literals only when expressed as a
hexadecimal number whose size ranges from one to eight bytes.

Fixes golang/go#38239

Change-Id: I024fdd5c511a45c7c285e200ce1eda0669a45491
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321810
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-14 22:22:34 +00:00
pjw 258ee27c37 internal/lsp/template: implement completions for template files
The suggesteds completions are based on a superficial parse of all
the template files in the package. The code errs on the side of too
many suggestions.

Change-Id: If956ad548327be25517878aab70802cf62d42a50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/341649
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-14 19:06:02 +00:00
Cuong Manh Le 384e5daa59 go/ssa: keep the ops doc sorted alphabetically
Change-Id: I17cc3ed99eb066fce8d99b14e94c6ae32be36ba8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/349209
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2021-09-14 00:08:19 +00:00
Chitoku e7de6523a2 internal/lsp: produce "method" in place of "member" as per the spec
As per the current specification, the correct token name that represents methods is `method`. The current implementation does not produce the correct set of result and results in methods being incorrectly highlighted. Furthermore, the parameter names of interface methods are treated as `method` which is not true, so a fix has been applied to handle `ast.FuncType` being `parameter`.

Spec: https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#textDocument_semanticTokens

Change-Id: Id5d2fafe9f948a4a175ae19b4c94cca8f48a4b79
GitHub-Last-Rev: 9a3b65ca4dd3bb0542969c043a2042001c7fcb63
GitHub-Pull-Request: golang/tools#340
Reviewed-on: https://go-review.googlesource.com/c/tools/+/349449
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-09-13 21:01:54 +00:00
Cuong Manh Le 915f620947 go/ssa: fix slice to array ptr conversions for named type
When checking for slice to array ptr conversion, we need to check for
pointer elem underlying type, otherwise, for named type, the conversion
will panic.

This is the same as what cmd/compile and go/types do.

Fixes golang/go#48281

Change-Id: I9c35fd9a73ffd8b02917397c6a79629f63bb049b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348511
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2021-09-11 04:35:30 +00:00
Zvonimir Pavlinovic a568412ca0 go/callgraph/vta: fix call site computation bug
VTA was not considering call edges, while setting up interprocedural
type flow, that involve synthetic functions. This can lead to missed
call graph edges. This CL makes sure all callees given by the initial
callgraph are considered.

Change-Id: I61070a80af60c05493b6bece354d768ba18a9f3e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348729
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-09-10 17:11:27 +00:00
Rebecca Stambler 295a39ba3c internal/lsp: remove the TODO and add a test for the hover panic
Fixes golang/go#48249

Change-Id: I86da0f185f414848bf89243737668f1d427c3e4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348969
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-09-09 21:49:46 +00:00
Rebecca Stambler c163c3172e gopls: add more instructions for working with Bazel and gopls
Change-Id: I91854ea0ad61d1b4794eacaee581888fa851d176
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348430
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-09-09 13:25:25 +00:00
Robert Findley 076821bd2b internal/typeparams: update MultiIndexExpr to IndexListExpr
This type was renamed in CL 348609, based on discussion in the
go/ast proposal.

Change-Id: I3addcf1bb192ad03f59f599a7aec68a579178fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348629
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-09-08 23:54:26 +00:00
Koichi Shiraishi 2cae65cc5b internal/typeparams: follow changes to Type in the go/ast and go/types
As discussed on both proposals to CL 348375 (#47781) and
CL 348376 (#47916), Go core changed the 'T' word to 'Type'.
Follows those changes as well.

Change-Id: I52c354cdc7494aaf3c63bfb136efa86159175314
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348509
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-08 19:08:28 +00:00
Rebecca Stambler 0a6f080615 internal/lsp: check InRange before calling token.Offset
This shows up every now and then--maybe we need a wrapper function
around token.Offset to check the range.

Updates golang/go#48249

Change-Id: I9c60bc7cc61fcfb2f4e8c6963586d8b8fbb21835
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348429
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-08 17:59:29 +00:00
Robert Findley e5f719fbe6 internal/lsp/source: consider test variants when finding pkg from pos
When resolving a position to a package we must consider all packages,
including intermediate test variants. This manifests, for example, when
jumping to definition in a package that is imported as a test variant
(see golang/go#47825).

For now, fix this by threading through an 'includeTestVariants' flag to
PackagesForFile. This isn't pretty, but should be a trivially safe
change: the only effect will be to increase the number of packages
considered in FindPackageFromPos. Since we are discussing future changes
to the API for querying packages from the snapshot, now did not seem
like a good time to undertake significant refactoring.

A regtest based on the original issue is included.

This CL is joint with rstambler@golang.org.

Fixes golang/go#47825

Co-authored-by: Rebecca Stambler <rstambler@golang.org>
Change-Id: I4693ec69b50ed4acd569cff87883769c1edf332b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/347563
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-08 14:51:59 +00:00
Cuong Manh Le 3604566214 go/analysis/passes/testinggoroutine: fix panic in goStmtFun
For function declared in other files, the identifier denoted function
will be nil, cause the analysis panics. To fix this, we just skip that
identifier for now, until golang/go#48141 is resolved.

Fixes golang/go#48124

Change-Id: I87876505ee5964639ed3d1772d541c00d091ceb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/347089
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-09-04 01:07:09 +00:00
Johannes Altmanninger d39bbca0a3 gopls: consistently capitalize enum variants for symbolStyle
We use a case-insensitive comparison so this doesn't really
matter but it's a bit confusing that gopls/doc/settings.md and
internal/lsp/source/api_json.go were inconsistent here.  I'm assuming
the latter also shows up as user-visible documentation somewhere,
probably in the VSCode plugin.

Change-Id: I14fa5b9d062266b6de0397aafb36e0ad84730752
Reviewed-on: https://go-review.googlesource.com/c/tools/+/344353
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-03 18:04:29 +00:00
Johannes Altmanninger 4e109c5706 gopls: use new "codelenses" config key in docs over deprecated "codelens"
There is a TODO to remove the "codelens" alias. This updates an
example in the documentation to use the new name.

Change-Id: Id807e99f5ba1da663eae9660fb65521596b0c488
Reviewed-on: https://go-review.googlesource.com/c/tools/+/344352
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-09-03 18:01:36 +00:00
Dan Peterson 7391fc19fa gopls/doc: update generic code section of advanced.md
Since golang.org/cl/343732 was merged the dev.typeparams branch is no
longer needed, just Go at tip.

Change-Id: Ifb2e5220bc2f544d86cfa84d43d12d93e4e7fddb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/343967
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-03 17:12:04 +00:00
Rebecca Stambler 3b801c8b83 internal/lsp: exclude node_modules in the workspace root by default
It is unlikely that users want gopls operating on their node_modules
directories, so we should exclude them by default. If a user wants to
include them, they can override their directory filters setting.

This doesn't exclude *any* directory named "node_modules", so we still
need to implement golang/go#46438 to exclude node_modules completely.

Change-Id: I03c42208e62390dc35e44ac5176422ddf8dc53f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/347297
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-09-02 18:21:15 +00:00
Zvonimir Pavlinovic 8373dc3f73 go/callgraph/vta: document explicitly CallGraph assumptions
Change-Id: I0d04bff9ab84b26a0c0a8b643fa2c3cb113ba2f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/346591
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-08-31 23:48:18 +00:00
pjw 70fb962d80 internal/lsp/semantic: semantic tokens for imports of versions
For
import "a/bar/foo"
the existing code just decides the last component is the package name.
But for
import "a/bar/v2" this is incorrect, as the packge name is 'bar'.
The new code uses the result of parsing to derive the package name
from the import string.

That is, the package name was determined syntactically, it is
now determined semantically.

Fixes https://golang.org/issue/47784

Change-Id: Iccdd25e7e3f591e6514b1e0258e9e1879af9ff2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/343909
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-31 17:42:36 +00:00
Koichi Shiraishi 3e0d083b85 internal/typeparams: update for recent API changes in go/types
This fixes the build when run with -tags=typeparams.

Change-Id: I94861e7f46e396804740a8e3c24f164380903a69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/343129
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-08-25 16:32:36 +00:00
smasher164 c32dd46c00 internal/imports: update stdlib index for 1.17
$ go run mkstdlib.go

Updates golang/go#38706.

Change-Id: I0ad28f7d5e1fec2d1ccc3bc0f01f43a7d2f0d817
Reviewed-on: https://go-review.googlesource.com/c/tools/+/344629
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
2021-08-24 14:51:57 +00:00
Matthew Dempsky d4cc65f0b2 gopls/internal/regtest/codelens: avoid compiler bug
Because of how the compiler internally represents variable references,
it sometimes gets position information incorrectly for them. The
codelens test hits this issue because for

	var x string
	fmt.Println(x)

the diagnostic about "x" escaping to heap (which actually refers to
the implicit conversion to "interface{}" type) should be rightly
reported at the "x" identifier within the call arguments list.
However, due to the aforementioned compiler bug, historically we
reported the diagnostic at the "(" token instead.

In -G=3 mode, the compiler (correctly) report the diagnostic at "x"
instead; but with GOEXPERIMENT=unified, the compiler intentionally
matches the original -G=0 behavior and continues reporting at "("
instead.

This CL avoids the issue entirely by changing the line to
"fmt.Println(42)", which avoids the issue because the compiler always
correctly prints the diagnostic then at "42".

Change-Id: I22d4c756ae801489f3f16c440e4339bc9b115fb0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/343875
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-08-20 21:27:50 +00:00
Rebecca Stambler bf6c7f26e9 all: update dependencies after gopls/v0.7.1 release
Change-Id: Ifd3227e2c34798024820277b512f18768e125c38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/341809
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-18 17:22:40 +00:00
Chressie Himpel e32504ce15 go/analysis/passes/printf: fix %w for non-fmt.Errorf functions
Previously all functions that were named Errorf have been treated like a
fmt.Errorf-based function. But only fmt.Errorf (and functions based on
fmt.Errorf) accept the %w verb. Fix that.

Updates golang/go#47641.

Change-Id: Iec5d0ae674c7dc817e85291dcfa064303eafba7e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340409
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
2021-08-17 17:01:38 +00:00
Rebecca Stambler 96f147c242 internal/lsp/cache: fix flakiness of load progress reports
I'm not sure why there was a goroutine in the defer here, but I think
this should fix the flakiness of this test. I wasn't able to reproduce
the flake myself locally however, so I couldn't confirm. I'll leave the
issue open until it stops happening.

For golang/go#47508

Change-Id: Ie9fdc68d70fe1634c3ad001441cf3ce0d2693d17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/342674
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-17 14:56:21 +00:00
Rob Findley 6932d22acd internal/lsp/source: recursively search for qualified objects
When searching for references or renaming, we start from all packages
containing the current position. But as reported in golang/go#47564,
this fails if we're renaming an object in another package; we need to
start the search from the package containing the object definition.

This CL finds the missing packages by recursively searching all
locations we encounter. For now, this will cause us to consider the
object location, and may also help us behave correctly with respect to
build constraint variants in the future.

While at it, update the regtests to support renaming. This bug could
be exercised with marker tests, but it's good to have a regtest for
renaming anyway.

Fixes golang/go#47564

Change-Id: I5517e2aeaaa744fcc6b6b96ffbb0b2625b498ed5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340472
Trust: Robert Findley <rfindley@google.com>
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-08-17 02:54:26 +00:00
Zvonimir Pavlinovic 10bcabde7c x/tools/analysis/passes/printf: fix error message for unsuppported %w
The current error message for calls to functions that not support %w
formatting directive does not explicitly say what is wrong nor why using
%w is wrong. This CL makes the message more direct.

Fixes golang/go#47690

Change-Id: I6e42ab725e5e3a989a8505ec230b4bb6218079ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/342111
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2021-08-16 20:51:50 +00:00
Koichi Shiraishi 758a1a1db7 internal/typeparams: fix undefined *types.Named.TArgs method
Current tip Go runtime (7eaabae84d) haven't (actually removed)
implements *types.Named.TArgs() method.
Calculate and make targs using named.NumTArgs().

Change-Id: Ib6a61cf2f8da644f533891f9bbb30179f8a7df5c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/342229
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-08-16 16:11:44 +00:00
Rob Findley a55d5155d9 internal/lsp: export and move some objects related to metadata
In preparation for moving metadata related functionality to a separate
package, move around some types and export some symbols. This is purely
to reduce diffs in subsequent CLs, and contains no functional changes.

Change-Id: I24d4fbd71df78e4d7a84f6598cdf820b41d542a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/340729
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-08-15 15:51:49 +00:00
Rebecca Stambler 45389f592f internal/lsp: add support for go.work files in file watching
This will allow us to add more support for the workspace proposal.

Change-Id: Ie557121afe0c16989ac176dc9246d82661a20c44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/341811
Trust: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-08-13 16:57:31 +00:00
Cuong Manh Le 8fae06a885 go/analysis/passes/testinggoroutine: also inspect defined/anonymous functions
Currently, testinggoroutine only inspects functions literal invoked as
"go func(){ ... }()".

For defined or anonymous functions like "go f(t)" it didn't traverse the
function body. To fix this, on encountering those kinds of functions,
retrieve the definition node then inspect it.

Fixes golang/go#47470

Change-Id: I83b6eb3bf2689c66aee32f13d34002aa3cd175b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/338529
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-08-13 03:36:45 +00:00
Cuong Manh Le 3fce476f0a go/analysis: add slice to array pointer conversion to nilness
If we know that a nil slice is converted to a non-zero length array
pointer, warn user that this operation will always panic.

Updates golang/go#47326

Change-Id: Ic8adcc0255ddc621c5626dc5c525899b13e1c6b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/337709
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
2021-08-13 03:35:06 +00:00