Commit Graph

6538 Commits

Author SHA1 Message Date
Robert Findley 2bb78cf04e internal/lsp: add missing bug reporting, and panic during marker tests
Add additional bug reporting related to position invariants, and update
marker test runners to panic on encountered bugs.

This revealed a panic on older Go versions, where we try to create a
range for a missing package name span. Lift the check into the caller
for this case, and leave a big comment explaining that
checkForOrphanedFile probably shouldn't be so tolerant of invalid calls.

Change-Id: Ie16a07afba0f8a5682cca50ad8f04450bfa2da65
Reviewed-on: https://go-review.googlesource.com/c/tools/+/407885
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-31 14:14:38 +00:00
Koichi Shiraishi 0e859afa53 go/analysis/analysistest: use listed mode instead of deprecated const
Change-Id: I8b743e1679f0c0019358b4ce4d715487631bf7dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/408514
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
2022-05-25 23:42:30 +00:00
Hana (Hyang-Ah) Kim f38573358c internal/gocommand: skip ill-formed env vars in cmdDebugStr
Fixes golang/vscode-go#2260

Change-Id: I4dbdb1d582e3b434bce9f0e923899d8af6a43f3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/408376
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-25 15:29:25 +00:00
Robert Findley ccb10502d1 internal/lsp/cache: invalidate metadata when parsing issues resolve
Package loading (at least via go list) fails when the import header
doesn't parse, so we need to invalidate metadata upon a state change
from non parsing->parsing. Refactor metadata invalidation to implement
this feature, add additional documentation, and avoid unnecessary work.

This change revealed a latent bug (via TestDeleteDirectory): when
statting a deleted directory failed, we could fail to invalidate any
package IDs, even those we already knew about. This bug was masked by
the somewhat complicated semantics of pkgNameChanged. The semantics of
pkgNameChanged are simplified to encapsulate any change to a
package->file association.

Also refactor the parsing API somewhat, and add a bug report if we don't
get a ParseGoFile while inspecting for metadata changes.

Update most regtests to panic upon receiving bug reports.

Fixes golang/go#52981

Change-Id: I1838963ecc9c01e316f887aa9d8f1260662281ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/407501
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-23 18:14:40 +00:00
Alan Donovan 904e24e9fc go/ssa: tweak Function.Name() for generic instantiations
Was "f[[int]]", now "f[int]".

Change-Id: I361d2386cffbabd0a4eca180b49c6da2b42cb28a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/407094
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-05-18 21:36:11 +00:00
Jonathan Amsterdam 4dd2c74a9b internal/govulncheck: copy from x/vuln repo
Currently, gopls maintains an edited copy of the govulncheck command
logic in the internal/vulncheck directory, along with the necessary
glue to make it work with gopls.

This CL is the first in a sequence that will make it easier for gopls
to use that logic.

It creates a new package, internal/govulncheck, adds a script to copy
the corresponding package from the x/vuln repo, and removes the cache
in internal/vulncheck in favor of the copied one.

Although it might appear simpler to copy the .go files directly into
internal/vulncheck, that would require editing the package directives
in the files, and has the risk of overwriting files.

Change-Id: I00f726f7b142048da2407f212873420df54844b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405997
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-18 18:10:12 +00:00
Robert Findley b62b00ff9a internal/lsp: add an option to get notified of bug reports
Our mechanism for reporting internal bugs doesn't work unless we
actually notice them. Add an undocumented option to receive showMessage
dialogs on the first bug occurring server-side.

Change-Id: I259a4c13161271c350fae06dc6ab0e1621725c92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399624
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-18 01:40:46 +00:00
Tim King 960b4ce5ae internal/typeparams: adds core type implementation
Adds a function for computing the core type of a type for use within x/tools.

Updates golang/go#52940

Change-Id: I91645c0b27031506be51a5f9d53b3e125e6fd1c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/406838
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 21:56:59 +00:00
Robert Findley b55ed5ed4d internal/lsp/regtest: only print RPC logs if asked
Sometimes one wants to run the regtests with verbose output without
seeing the wall of RPC logs. Add a new flag to control the printing of
logs, rather than overloading testing.Verbose().

Change-Id: Iea5727e3079005d229319cbf86f67067f7c1f85d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405894
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 21:46:20 +00:00
Robert Findley 44db4ebc77 gopls/internal/regtests: add a test for bad go.work files
Add a test that would have reproduced the panic from
golang/vscode-go#2121.

For golang/vscode-go#2121

Change-Id: Idb07dc0789b51e3056e0b3d0910916ec35931ac4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/397355
Run-TryBot: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 21:15:15 +00:00
komem3 f97a804487 go/analysis/passes/nilness: fixed slice not being considered as non-nil
The initialized slice will always be non-nil.
But, nilness could not detect it, so I fixed it.

Fixes golang/go#45177

Change-Id: I3bad2b8dee16331c4a24d2e93fb4baacd98f30ec
GitHub-Last-Rev: f3a532e568e43ae57080bdf8046ac46d93b4cc3f
GitHub-Pull-Request: golang/tools#291
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303890
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
2022-05-17 19:40:15 +00:00
Marwan Sulaiman 13bcb69cfa internal/lsp/analysis/stubmethods: recognize *ast.CallExpr
This change makes it so that the stub methods analysis can recognize
errors happening to method and function call expressions that are being
passed a concrete type to an interface parameter. This way, a method stub CodeAction will appear at the call site.

Updates golang/go#37537

Change-Id: I886d53f06a85b9e5160d882aa742bb2b7fcea139
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404655
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2022-05-17 17:04:34 +00:00
Robert Findley facb0d30e9 internal/span: eliminate Converter and FileConverter
The only real implementation of position conversion was via a
*token.File, so refactor the converter logic to eliminate the Converter
interface, and just use a single converter implementation that uses a
*token.File to convert between offsets and positions.

This change is meant to be a zero-impact refactoring for non-test code.
As such, I abstained from panicking in several places where it would
make sense. In later CLs, once the bug reporting API lands, we can
insert bug reports in these places.

Change-Id: Id2e503acd80d089bc5d73e983215784015471f04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405546
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-17 16:08:12 +00:00
Ian Lance Taylor 814e0d74b5 go/gcexportdata: don't assume that fmt names never change
For golang/go#47579

Change-Id: I25a873fb6da216d885c8faefda98c7fe027b6a4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/406357
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Rob Pike <r@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-05-17 03:21:52 +00:00
Tim King 1e55371df5 go/ssa: fix *SelectorExpr within *IndexExpr handling
When a *IndexExpr or *IndexListExpr expr is over a *SelectorExpr and
expr denotes an instantiation, build expr as the *SelectorExpr.

Fixes golang/go#52834

Change-Id: I9a69ac28a6e8fb0ee9eb45db8675872b75d69a0f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405555
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tim King <taking@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-05-16 16:39:03 +00:00
Zvonimir Pavlinovic 29d48d6d9d go/callgraph/rta: adds tests for (instantiated) generics
Updates golang/go#48525

Change-Id: I7e25ab136dd69ebd50b12894bc893986fc59999b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/402994
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-05-16 16:26:54 +00:00
Robert Findley ed968f66bd internal/lsp/bug: add a package for bug reporting
The existing debug.Bug mechanism for reporting internal bugs is
insufficient for several reasons:
 - It requires a context, which is not always available.
 - By being defined in the debug package, it is subject to import
   cycles.
 - It is too complicated. Listening for bugs requires understanding the
   event package.

Replace this with a simpler 'bug' package with no dependencies, that
allows reporting, listing, and listening on internal bugs. Hopefully
this will fulfill the goal of debug.Bug, to help us track down rare
bugs.

Change-Id: I30cab58429b29bd2d944d62e94f5657e40a760fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399623
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-16 14:45:30 +00:00
Robert Findley 090b14e850 internal/lsp/regtest: make TestResolveImportCycle robust to error order
In JSON output, the Go command was only setting the Error field for one
package involved in an import cycle. As a result, TestResolveImportCycle
was dependent on the chosen package, causing flakes when the chosen
package is not deterministic.

Arguably this behavior should be fixed, both in the go command and in
gopls, but for now make the test resilient to choice by asserting on any
of the possible errors.

Add a new AnyOf expectation to support this type of assertion and tweak the
test output formatting. Also update the test to eagerly fail once the
didOpen notification has been fully processed, so that we don't have to
wait for the assertion timeout.

Updates golang/go#52904

Change-Id: Ic209d8fdcb7308c041b287a8f122c47e96d29a96
Reviewed-on: https://go-review.googlesource.com/c/tools/+/406274
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-13 22:16:40 +00:00
Dominik Honnef 820e09350d go/types/objectpath: implement fast path for concrete methods
Don't search for a matching method on all types in the package scope
when we can trivially determine the type's name. This avoids both a
linear search over the scope, as well as the currently rather costly
call to scope.Names itself.

Updates golang/go#51017

Change-Id: I614f4b1b149d6b42728d3f22f5e47e8ff87a5392
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404514
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-13 20:45:12 +00:00
Tim King cfd99059fd go/ssa: inline *ssa.selection methods
Inlines and removes *ssa.selection methods.

Change-Id: If3b30bc193a60b4aa4241431ce8cbe9c08a70587
Reviewed-on: https://go-review.googlesource.com/c/tools/+/406114
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-13 18:18:45 +00:00
Tim King 304195cc44 go/ssa: create *ssa.selection.
Simplifies handling *types.Selections by always using a *ssa.selection
internally. Updates the selection during monomorphization.

Updates golang/go#48525

Change-Id: If9cf7a623d3fed060dda41a5b65c46fcfe3d431c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405557
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Tim King <taking@google.com>
2022-05-13 00:39:00 +00:00
Hana f918e87c18 gopls/internal/vulncheck: copy logic of govulncheck -html
reference commit: b2400d8
The latest relevant change in the code copied is CL 403075.

Change-Id: If50cb4e0096e4f33876236cf8620430e1bcfcd86
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405795
Reviewed-by: Jamal Carvalho <jamal@golang.org>
2022-05-12 21:17:31 +00:00
Hana a518b798ae gopls/internal/vulncheck: synchronize cache access
Corresponds to
https://go.dev/cl/396594
 adds basic support for cache thread safety
https://go.dev/cl/398115
 change references to GCS bucket to vuln.go.dev

Change-Id: I16587a703431e1e28bc6d5f84ab54b4c88fcbdce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405794
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2022-05-12 21:16:40 +00:00
Hana ad497c6c68 internal/lsp/cmd: add -config option to gopls vulncheck
If -config=true, gopls vulncheck reads the package load
configuration JSON (build flags, env, tests, and later
maybe overlay info) from stdin.

And, add some logging to gopls/internal/vulncheck/command.go
that helps measuring the package loading overhead.

Update golang/go#50577

Change-Id: I5c1ce145b07f2bed03911613f42c09a3d6be6c28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404575
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-12 21:16:26 +00:00
Alan Donovan 62d837c1f3 go/analysis/passes/httpresponse: minor clarification
See discussion in https://go-review.googlesource.com/c/tools/+/405314.

Change-Id: Ic5f5182a1cc55b4a2c40f43ebb2250c508388c75
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405537
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Nooras Saba‎ <saba@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-12 13:23:44 +00:00
Nooras Saba 6eb3de266b internal/lsp/analysis: fix a doc comment typo
Fixes the grammar

Updates #50262

Change-Id: I8bc524b26d6cbeda3e626d0e83601529cbf7ff6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405540
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-11 23:42:05 +00:00
Robert Findley 728485ffcb gopls/internal/regtest: add a test for using staticcheck with generics
For golang/go#52159

Change-Id: I08120331b7f5c9eb06feac0d0eeb76a9a7b629df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399914
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Le <dungtuanle@google.com>
2022-05-11 20:19:40 +00:00
Than McIntosh 1a5eed31fb cmd/compilebench: use -p, handle packages with asm files
Update compiler invocations to pass "-p <importpath>", since that
is the normal way to invoke the compiler these days.  In addition,
add some logic to generate a 'symabis' file for packages that
include assembly source files.

Change-Id: I64c490c55603609cf2cdbfae20ed787a581be4d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405734
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-11 17:47:50 +00:00
Alan Donovan 93852cb65b internal/lsp: fix source.CompareDiagnostic asymmetry
In passing I noticed that this three-way comparison
is not (anti)symmetric. Such comparisons should consist
of a list of pairs of tests of this form:

  if x.key1 < y.key1 { return -1 }
  if x.key1 > y.key1 { return +1 }
  ...key2, etc...
  return 0

Also in passing:
- simplify panic-proof debug string function.
- augment doc comment of (*Server).beginFileRequest

Change-Id: Idcd0844ea4e96fc2dee5bbc270f5a200b5c27aa0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405480
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-11 17:43:03 +00:00
Tim King 8ec40b5329 x/tools/go/ssa: instantiate sel.Recv() on MethodVal.
When a MethodVal selection receiver is a TypeParam while monomorphizing, use the method value from the substituted type.

Fixes golang/go#52835

Change-Id: Iaf174a02b62b0c3ed4aafefdfd2aca195781e9f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405594
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-11 16:27:29 +00:00
Nooras Saba 28c754d415 internal/lsp/analysis: analyzer for //go:embed directive
This CL adds a new analyzer for //go:embed directive, which
checks for the "embed" import.

Along with it, it improves doc for analysistest.Run for
comments of the the form  "//...// want..." or
 "//...// want..."

 Updates #50262

Change-Id: I60ef0ab740feadd4fff3a4d758123b27ceda0bc6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/400854
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Nooras Saba‎ <saba@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-11 14:31:28 +00:00
Hana (Hyang-Ah) Kim 033cbfc76d internal/typeparams: run go generate with go1.18.2
And fix a minor issue in copytermlist.go --

copytermlist.go replaces type names from go/types with
qualified type names. Use of token.NoPos (filled with
ast.NewIdent) however confuses the go/format printer.
As a result, while transforming

  func (x *term) includes(t Type) bool

to

  func (x *term) includes(t types.Type) bool

go/format printer failed to compute the end position of
the parameter list, concluded RPAREN should be in a
different line from the parameter list, added a comma,
and printed

  func (x *term) includes(t types.Type,) bool

Reuse the replaced node's position instead. (not 100%
correct, but better than NoPos)

Change-Id: Ia34e11562cc80c68dcf4b921ffffd926971c2215
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405536
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-11 13:38:50 +00:00
Robert Findley bc0e26ea12 internal/typeparams: remove examples in favor of x/exp/typeparams
The internal/typeparams directory contains an initial draft of the
documentation later published under the golang.org/x/exp/typeparams
module. Remove this draft to avoid confusion.

Change-Id: I1f40468f99c0d2885e8fc380c75669f654ba971e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405260
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-10 12:58:44 +00:00
Zvonimir Pavlinovic b87ceec0dd go/analysis/passes/httpresponse: inspect enclosing context of resp, err
The resp, err results of, say, http.Get can immediatelly be passed to a
helper function that checks err and returns resp. In that case, it is ok
for defer to occur immediately after.

The checker currently assumes that a call to, say, http.Get is the only
call made when a resp is returned. The fix is to check if the original
call is made as a part of another (helper) call and, if so, punt.

For golang/go#52661

Change-Id: If9dc4815013476de381fe69548d1fb9c04aa9fd9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404656
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-09 19:02:05 +00:00
Daniel Martí 313af968cc go/ast/astutil: make Apply follow TypeParams fields
It completely ignored the TypeParams fields in FuncType and TypeSpec.
I was confused why one of my tools, which looks at *ast.Ident nodes,
saw the identifiers where type parameters were being used,
but not the identifiers where they were being declared.

We use the ForFuncType and ForTypeSpec helpers, just like in the rest of
the package, for consistency and backwards compatibility with Go 1.17.

Add a regression test as well.

Change-Id: I00b2dfe5e04d92d63e6d5e91c6466598c865ed0b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/405194
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-09 18:45:38 +00:00
Robert Findley d303668635 internal/lsp/cache: use cached parsed files for symbols, if available
Optimize building the symbol index for a file, in two ways:
 - use the cached full parse tree, if it already exists
 - if it doesn't exist, optimize parsing by skipping both comments and
   object resolution, which aren't necessary for symbols

This results in around 3x faster initial indexing of symbols. In my
manual testing, indexing of Kubernetes went from 16s->5s, and indexing
of x/tools went from 2.4s->700ms.

Also fix a typo in gopls/internal/regtest/bench/bench_test.go.

Fixes #52602

Change-Id: I0893e95410be96e94e5e9dee7a3aab30b59c19c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403679
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-05-09 17:04:06 +00:00
Robert Findley 0fb1abf25a internal/lsp: factor out go/token wrapper into a safetoken package
This avoids an import cycle that prevented these wrappers from being
used in the lsppos package.

Change-Id: I9eedd256db983dfcf962edba39e3d4f3a1aabdeb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403680
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2022-05-09 17:03:37 +00:00
Robert Findley cde25b3a5f internal/lsp/lsppos: add helpers for mapping token positions
For use-cases that work only with token.Pos and protocol.Position, the
span package is unnecessarily indirect, and inefficient. It also loses
information about newline termination, and handles positions within CRLF
line endings incorrectly.

The lsppos package was written to bypass this complexity, but had
limited use and lacked tests.

Add tests, and an wrapper API that operates on token.Pos. Also fix
source.TestTokenOffset to not panic, and add a temporary exemption of
the new token.Offset usage.

This change also fixes position calculation in the case of empty file
content. The mapper now finds position (0, 0) at offset 0 of an empty
file.

Change-Id: I639bd3fac78a127b1c8eddad60b890449901c68c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403678
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-09 17:02:03 +00:00
Hana 22b709631a internal/lsp/cmd: change vulncheck to directly call the hook
Instead of invoking the command through the LSP custom command,
call the vulncheck command hook directly. That reduces the extra
overhead of bringing up the full gopls server & package loading.
The vulncheck hook loads packages again any way, so the benefit
of running the check inside gopls's custom command framework
is not huge any more.

Still `gopls vulncheck` is useful - editors don't need to install
another binary for vulncheck feature, and it will output the
result in the format easier to handle than what `govulncheck`
currently offers.

Updates golang/go#50577

Change-Id: Ia21e6d7e0c37c4a1b02dc8bbca860143524c3d1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404574
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-05-06 16:33:28 +00:00
Hana 72a884b2d6 gopls: update golang.org/x/vuln dependency
v0.0.0-20220503210553-a5481fb0c8be

Ran GOWORK=off go mod tidy -compat=1.16

Change-Id: I06914ae341648b7ef6035ec45f955ec7bfa49566
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399040
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 16:33:10 +00:00
Robert Findley d7e01c038e internal/lsp/source/completion: use typeutil.Map for short-circuiting
While working on golang/go#52715, I discovered an infinite recursion in
gopls' completion logic: eachField assumes a finiteness of type pointers.

It is almost certainly a go/types bug that type-checked types expand
infinitely, but nevertheless we should use the more accurate
typeutil.Map for short-circuiting our search.

Change-Id: Ib1c7125e624f42882869acd4e0476e317d4da056
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404335
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2022-05-06 16:24:14 +00:00
Tim King d299b94661 passes/copylock: suppress reports on Offsetof and Alignof
Suppress false positives on calls to builtins unsafe.{Offsetof,Alignof}.
Similar to the already suppressed Sizeof, these do not execute their
arguments and thus do not copy.

Fixes golang/go#52700

Change-Id: I2ad461df4c270b97cbd1271403935501f8ae25c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404234
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tim King <taking@google.com>
2022-05-05 17:30:08 +00:00
Suzy Mueller 30fbd19e84 internal/lsp: fix fillstruct for structs with unsafe.Pointer
Provide a default value for unsafe.Pointer in fillstruct.

Fixes golang/go#52640

Change-Id: I10a1878fbf53b082f83f44e0ba2788ead14439d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403535
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 17:08:12 +00:00
Alan Donovan 0ebacc111e internal: remove pre-go1.12 conditionally compiled files
Change-Id: I496ad24654990341eae9508587e950abde05b540
Reviewed-on: https://go-review.googlesource.com/c/tools/+/404334
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
2022-05-05 16:48:28 +00:00
Alan Donovan 45c8a71312 internal/tool: implement structured help command
'gopls help cmd...' is redirected to 'gopls cmd... -h'.
The tool.Run operation for each subcommand already has
logic to show the usage message when it parses a -h flag.

Examples:
   $ gopls help
   $ gopls help remote
   $ gopls help remote sessions

Fixes golang/go#52598

Change-Id: I5135c6e7b130d839f880d0613534ac08de199bcf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403677
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: 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-05-04 22:58:41 +00:00
Bryan C. Mills d27d783e99 cmd/godoc: expand skips in TestWeb
After CL 403534, another TestWeb failure was observed in
https://build.golang.org/log/24cca44e99d848317a6bb73b6d15528b500e5643.
This change expands the skips to try to cover more of the cases
where cmd/godoc might hang.

For golang/go#50014.

Change-Id: If3f08da69a68dc00c399b89ffb2c4f049114aeb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403849
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-04 21:37:12 +00:00
Alan Donovan 4911e4af7d internal/testenv: remove darwin/arm case from NeedsGoBuild
This function was derived from internal/testenv.HasGoBuild
in the standard library, which has since been updated
(in https://go-review.googlesource.com/c/go/+/260719)
to permit darwin/arm64 builds.

Change-Id: Ifc793b52b65ee3eedb2f41fbcbfbe36a20cfdbcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403795
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 20:40:54 +00:00
Pontus Leitzler 54c7ba520b go/analysis/passes/asmdecl: add build tag for loong64
The arch "loong64" doesn't exist before go 1.19 causing a "unknown
architecture" message printed to stderr when asmdecl is imported.

A build tag now prevents "loong64" from being checked in earlier
versions of go.

Fixes golang/go#52646

Change-Id: Ibc83ce02d92cfb709a773ca758b21a80516a399c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403874
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 16:24:46 +00:00
Alan Donovan b4c45006d2 README: restructure and update
Update the README file to remove stale information
and describe the most important packages and tools
in the repo, to help users find their bearings amid
the plethora of obscure or obsolete things.

Also, consolidate the Contributing information at the end.

Change-Id: I499c7c62bff142529063df0fc65d9b3da3978379
Reviewed-on: https://go-review.googlesource.com/c/tools/+/403676
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-04 14:51:12 +00:00
Robert Findley 556c550a38 internal/lsp/cache: invalidate packages that have added files
When a file is new or its package name has changed, we should invalidate
all packages for files in the current directory, not just packages
previously containing the file.

Fixes golang/go#52500

Change-Id: I9fc9857a7abcd4e730068871c899d274e1736967
Reviewed-on: https://go-review.googlesource.com/c/tools/+/401795
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-05-02 22:20:22 +00:00