Commit Graph

6429 Commits

Author SHA1 Message Date
pjw 1f763dfd2e internal/lsp: add semantic tokens for arrows in declarations
Fixes: golang.org/#52024

Change-Id: Ib79a839f9bdeaef1250925add69dea3ae32e1cae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397479
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
2022-04-07 14:52:22 +00:00
Tim King b3e0236d65 go/ssa: Track created functions in the builder.
Changes the builder to be stateful and track the Functions that were created while building the current Package [or MethodValue]. Additional bookkeeping is now done whenever a synthetic functions is created.

Adds an additional state to Function to track if it is done with the BUILD phase.

Moves (*Program).needsMethods from emitConv to a postprocessing phase in package BUILD phase.

Clarifies that anonymous functions are done at the same time as their parent.

Updates golang/go#48525

Change-Id: I09d1ed2abc95d252029917f49f783a3cfd9f0a78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396876
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>
2022-04-06 22:00:21 +00:00
Zvonimir Pavlinovic 673165911b go/ssa: adds position info to implicit field selection instructions
Fixes golang/go#51986

Change-Id: I1fa5868d70ae53f57b6c2bc0c4dbe4ac524b89e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396495
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
2022-04-06 18:19:46 +00:00
Peter Weinberger 74cea6e8cb internal/imports: ignore some line directives
This is a minimal fix for the reported panic. The existing code
used FileSet.Position() where it should have used FileSet.PositionFor(, false).

gopls does this in lots of places; each use of Position() needs to
be thought about.

x/tools/go/ast/astutil/import.go:273,274 is another example.

Fixes: golang/go#51916

Change-Id: I42de6affca2c97c09efb7974a9e44322556b3ffd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/398395
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Peter Weinberger <pjw@google.com>
2022-04-06 14:24:15 +00:00
Suzy Mueller 37acb39970 internal/lsp: run vulncheck in specified dir
The directory for the vulncheck command is passed
as an argument. Use the specified directory
in the configuration.

Change-Id: I1824b308701fd30548efa8bec7452de1fdf76bb9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/398394
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-04-05 17:18:24 +00:00
Dan Kortschak 4077921f14 all: fix spelling
Change-Id: I13cf73d7e043dda1a06c28bb09e413a76a68df1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391934
Reviewed-by: 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>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-04-04 19:50:34 +00:00
Dylan Le ff66cbef33 internal/lsp: remove unused parameters from moduleAtVersion
Change-Id: I16ed074188fa5f670894778a89cea1a500ec5c7f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397416
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 Findley <rfindley@google.com>
Trust: Cherry Mui <cherryyz@google.com>
2022-04-04 16:32:51 +00:00
Bryan C. Mills 7d125fe075 cmd/callgraph: expand windows/arm64 skip to the whole platform
This test produces apparent file corruption on all of the
windows/arm64 builders. I suspect that this is a low-level bug (in
either the platform itself or the Go standard library on
windows/arm64).

Since windows/arm64 is not yet a first-class port, this test can be
skipped for now. However, if windows/arm64 becomes a first-class port
the underlying file-corruption bug should be investigated and fixed.

Updates golang/go#50706.

Change-Id: I0bc80cefee50895d40acc658286eb7ef8790493a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397996
Reviewed-by: Russ Cox <rsc@golang.org>
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>
2022-04-04 15:58:39 +00:00
Pontus Leitzler 153e30b3c7 internal/lsp/lsprpc: only propagate explicit GOWORK when using remote
When using gopls remote, existing go env vars are injected in the
initialize message. Setting GOWORK explicitly will impact cmd/go
invocations, for example "go list" during package load. The reason it
impacts is that gopls manually sets PWD to fix paths returned by cmd/go
if the working directory is inside a symlinked directory.

By only propagate GOWORK when it is explicitly set we will ensure that
the behavior is the same when running with or without remote.

See golang/go#51823.

Fixes golang/go#51825

Change-Id: I6280aa7d8208e5aee269f19356668c7713e9f0a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/394054
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-04-01 20:25:27 +00:00
hiroebe cda13e227d internal/lsp: fix incorrect line and start of semantic tokens
Current implementation returns incorrect result when some of the items are skipped, because positions could be relative to a skipped item. Instead, each position must be relative to the previous item added to the result.

Change-Id: I3c1a68d37bf0c9cfc1bccfe6f76c25b536224293
GitHub-Last-Rev: 6eedc7cbcc27f47ed5742b340f4438291ab70863
GitHub-Pull-Request: golang/tools#376
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396715
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Trust: Suzy Mueller <suzmue@golang.org>
2022-03-31 23:32:26 +00:00
Robert Findley 41787c4fe7 gopls: run go mod tidy -compat=1.16 to fix the 1.16 build
Change-Id: Idfa5fbd41720d6f12084fc351774fed5dc68c488
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397356
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-31 21:49:24 +00:00
Charlie Vieth b9a48075ea internal/gopathwalk: remove unnecessary call to os.Lstat
internal/gopathwalk.walk remove an unnecessary call to os.Lstat when
checking if a symlink should be traversed. And remove a call to
filepath.EvalSymlinks that should be unnecessary as we are using
os.Stat to compare files.

Change-Id: Ie5ad1cb99cbd6d62f08f2b482a3e84b6fe41114d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/392095
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
2022-03-31 05:33:07 +00:00
Tim King 8e193c2ba9 go/ssa: removes conversion of index value in Index and IndexAddr to int
Removes the forced conversion of the Index field in Index and IndexAddr to type int. ssa/interp now intprets indices as int64s instead of ints.

Converts untyped indices for strings to ints before the lookup.

Fixes golang/go#50949

Change-Id: Ib5d7f1ad28728d16c8e0a8411014d1209c62a3f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/387996
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-30 17:49:40 +00:00
zhangyunhao 9d8009b6b7 go/analysis: validate report if analyzer.Run is empty
The Run function is necessary for an analyzer, if left a nil Run, the runner will panic in run-time(singlechecker.Main, etc).

Change-Id: Ibbeea2d8c740f73e6c083647df6ded445036e272
Reviewed-on: https://go-review.googlesource.com/c/tools/+/329451
Trust: Carlos Amedee <carlos@golang.org>
Reviewed-by: 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-30 03:52:37 +00:00
Tim King 761e51fea3 go/ssa/interp: Adds reflect.DeepEqual model for interp testing
Implements reflect.DeepEqual() for testing interp packages. Adds test that exercises this.

Fixes a nil pointer dereference in ext۰reflect۰Value۰Elem in interp.

Updates golang/go#48525

Change-Id: Ib32e96d37aa5c85cefe59e9514d4e162d7f7011e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/391314
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-29 21:53:41 +00:00
Hana e342718dfc gopls/internal/vulncheck: skip vuln entries without callstacks
Vulnerability entries that do not have call traces are
considered false-positives by govulncheck.

Change-Id: I50d7fc815723038e904805213cd039a05934a469
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396434
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: Jamal Carvalho <jamal@golang.org>
2022-03-29 17:29:50 +00:00
Robert Findley b22bc85c18 gopls/doc: update stale documentation on generics
Change-Id: I01b7bad40e466ef04450aae84d51b5cf47fa4a0e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/396435
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-29 16:50:19 +00:00
Russ Cox e693fb4172 go/internal/gcimporter: fix IImportBundle error text
When called from IImportBundle, the current code returns
a message saying:

	cannot import "" (actual error) ...

That looks like the user has somehow caused an invalid import path
to be passed, which is not the case. Skip the wrapping in the bundle case.

Change-Id: I6cdb83911d18501895671fc70d87c2519f0570a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310514
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 21:22:34 +00:00
Russ Cox ed5a15cbaa go/internal/gcimporter: replace assert with more helpful panic
If this code is misused, the result of the assert is

	panic: assertion failed

This CL replaces the panic text with a useful message.

Change-Id: I3710ebe975e7f1e907b0378e9c67dd0c224492fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310513
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 21:22:33 +00:00
Russ Cox f4515dde79 go/packages: fix load with NeedTypes but not NeedImports
Fixes golang/go#45584.

Change-Id: I65238cc3bdc640bb044c615a5699e8d3cfa39db0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310512
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 21:22:31 +00:00
Russ Cox 11930bd9d7 go/packages: fix handling of NeedExportFile in go list
If we need the export file, can't use -find,
which stops the go command too early.

Change-Id: I82adca728e3e8a2435cddad14cfed97665ea4234
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310510
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-25 21:22:29 +00:00
Russ Cox e0095ae32c go/packages: fix precedence typo in needtypes calculation
I haven't figured out exactly how to exercise it,
but the code as written is clearly wrong.

Change-Id: I8849bc37210d08ad8ae3bc857a84ae55b34908a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310511
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 21:01:57 +00:00
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