1
0
mirror of https://github.com/golang/go synced 2024-10-01 10:38:33 -06:00
Commit Graph

4909 Commits

Author SHA1 Message Date
Rob Findley
20370b0cb4 internal/lsp: honor GOPRIVATE in documentLinks and go.mod hovers
Several fixes related to GOPRIVATE handling and links:
 + In Go source, fix links matching GOPRIVATE for external modules.
   Previously, in these cases we'd try to match <mod>@v1.2.3/<suffix>,
   which wasn't the correct input into the GOPRIVATE matching algorithm.
 + Similarly check GOPRIVATE for go.mod require statement hovers.
 + Likewise, for documentLink requests (both mod and source).
 + Move the existing hover regtest to link_test.go, and expand to cover
   all these cases.

Along the way, I encountered a couple apparent bugs, which I fixed:
 + Correctly handle the case where there is only one require in a go.mod
   file. This was exercised by the regtest, so took some debugging.
 + Only format links [like](this) if the requested format is actually
   markdown.

Fixes golang/go#36998

Change-Id: I92011821f646f2a7449dcca619483f83bdeb54b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238029
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-18 13:42:42 +00:00
Rob Findley
9b4b92067d internal/jsonrpc2/servertest: replace closerList with connList
closerList was already unnecessarily abstract, and tracking connections
will allow us to also wait for all connections to finish.

Share functionality by embedding this type in PipeServer, TCPServer.

Change-Id: Ib2cb2157c1477f904bc278aa91902f5c633afe13
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238547
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-18 12:08:28 +00:00
Rob Findley
5fddd300b6 internal/lsp/cmd/test/cmdtest: shutdown connections on test completion
To prevent misleading errors from outstanding go command invocations at
test completion, properly shutdown the LSP connection before cleaning up
exported files.

Change-Id: I9ad175060fefc5b914e544c5f58b9b6658405edc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238546
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-18 11:25:59 +00:00
Rebecca Stambler
d15173dcc7 internal/lsp/cache: separate modTidyHandle out of modHandle
While working in this code, I was confused by the fact that modHandle
and modData were used for both ModHandle and ModTidyHandle. Separate out
the two so it's a little more clear. This is mostly a copy-paste, with a
few fields renamed to simplify them.

Change-Id: I20ea11c32a624fd250eabf901d09ebb05fbad062
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238337
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-18 03:14:02 +00:00
Rebecca Stambler
47c907e258 internal/lsp: use a new temporary go.mod for every go list call
Refactor internal/lsp/cache to use a new temporary go.mod file for each
go command invocation. This cleans up the abstraction in the source
package, as we no longer are aware of temporary go.mod files.

This will also fix the raciness of reusing the same temporary go.mod
file for each invocation.

Updates golang/go#37318.
Fixes golang/go#39504.

Change-Id: I90bc17a678b5df222ab598c8f7dbf6c6fdd393f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237517
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-18 02:37:23 +00:00
Heschi Kreinick
87be026d38 internal/lsp/regtest: move and re-enable TestRegenerateCgo
Revert https://golang.org/cl/234480, which was unnecessary, and move it
to a more appropriate file.

Change-Id: I3f5a3eccaf0ffe324fee8e27945a2e5ece2ff12c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238597
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-17 21:29:13 +00:00
Heschi Kreinick
6222995d07 internal/lsp: handle deletion of workspace packages
When a workspace package is deleted, we need to stop trying to load it.
Check that every workspace package still has at least one .go file when
we copy them between snapshots.

I think this is correct, but even if it's not, orphaned file loading
should patch it up.

Fixes golang/go#38977.

Change-Id: I0b11010a40aac09f619f54b5ba02e2467b15a36c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238028
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-17 16:12:49 +00:00
Rebecca Stambler
7f3f4b10a8 go/packages: correct package IDs for overlaid x tests
Bad go/packages results were being cached, causing unexpected behavior
when new x tests are created. This fix also allows us to enable a
regression test that had been previously disabled.

Change-Id: I93c05df2f4d32c6c8a43e9f5aaeeb30bc4a32f3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238058
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-17 04:29:24 +00:00
Heschi Kreinick
b7b89dcb81 internal/lsp/cache: support minimal module compatibility in GOPATH
In GOPATH mode, you can import example.com/foo even if it has a go.mod
that says its path is example.com/foo/v2. Adjust our import path
resolution to support that case.

Fixes golang/go#39560.

Change-Id: I758a2220c579c4374084365c3a78a3a2bbd14b01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238260
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-16 21:57:26 +00:00
Pontus Leitzler
dc31b401ab internal/lsp/source: avoid panic in rename check
In a case where the type info for an ast.CompositeLit isn't found in
forEachLexicalRef(...) gopls will panic.

e.g. trying to rename "foo" where it is declared in this case:
func fn() {
	var foo bool
	make(map[string]bool
	if foo {
	}
}

Note the missing ')' after make.

This change will skip ast.CompositeLits if the type can't be found, and
that fixes the panic. But it also do rename the identifier as long as it
is possible, and I'm not convinced that we should allow rename at all if
the source can't be compiled.

Updates golang/go#39614

Change-Id: Ibb50b15ce4b31056f2f1da52a4dcab7b8b91a320
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238042
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2020-06-16 19:50:46 +00:00
Rebecca Stambler
e3971a17a8 internal/gocommand: revert accidental changes from CL 237685
Not sure how these got submitted, I thought I fixed them.

Change-Id: I2ffd4b838d37a110d3b2d9b44c31ef7aa3056a91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238030
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-16 16:48:58 +00:00
Rob Findley
e258ba4578 internal/jsonrpc2/servertest: minor improvements for closing
Return an actual error when closing the test server, and close at the
jsonrpc2.Conn level, rather than at lower levels.

Change-Id: I0bc153f40ced5dfee9ac26d3ffd666e446b812e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238197
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-16 16:45:34 +00:00
Rob Findley
b1f3cdd652 internal/lsp/regtest: add a regtest for hover handling of GOPRIVATE
Add a regtest to verify that GOPRIVATE identifiers are not given a link
to pkg.go.dev. For efficiency, as well as to exercise dynamic
configuration, do all this in a single regtest.

Updates golang/go#36998

Change-Id: I9102a11312db5c334fdbd30cce9ca2d2e19e9ac2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237938
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-16 15:44:21 +00:00
Rob Findley
2b5917cebf internal/lsp/lsprpc: forward the go environment in initialize requests
The gopls workspace environment defaults to the process environment in
which gopls was started. This means that when switching environments,
gopls can potentially get a different environment when connecting as an
editor sidecar from when forwarding requests to the daemon.

To (hopefully mostly) mitigate this pain point, inject the Go
environment when forwarding the 'initialize' request, which contains
InitializationOptions containing the 'env' configuration. We could go
further and send the entire os.Environ(), but that seems problematic
both in its unbounded nature, and because in many cases the user may not
actually want to send their process env over the wire. Gopls behavior
should *mostly* be parameterized by gopls binary and Go env, and after
this change these should match for forwarder and daemon.

For go1.15, Explicitly set the GOMODCACHE environment variable in the
regtest sandbox. Without this, regtests were failing in the forwarded
environment because they implicitly shared a module cache.

Fixes golang/go#37830

Change-Id: Ic1b335506f8b481505eac9f74c0df6293dc07158
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234109
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-16 15:43:56 +00:00
smasher164
c1934b75d0 go/analysis: improve error message for string(int) warning
To an experienced Go user, the previous error message doesn't describe
the error--it merely states a fact. The new error message asks if the
user meant fmt.Sprint(x). If they used the conversion correctly, the
suggested fix to replace string(int) with string(rune(int)) is
understandable and valid. On the other hand, if they used it to print
a digit representation, asking that in the error message further
emphasizes the mistake.

Updates golang/go#39151.

Change-Id: Iab9cdcaf53e9ca134285246fad0546d6f24c3983
Reviewed-on: https://go-review.googlesource.com/c/tools/+/235797
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-16 13:34:36 +00:00
Rebecca Stambler
6aa8f57aac internal/lsp: un-export (*snapshot).Config to limit it to cache
Limiting the Config to the view seems reasonable, considering that it is
only used to run the `go` command. I prefer just having the cache run
go commands, so that source doesn't have to deal with the environment.

This also enables CL 237517.

Change-Id: I639c082592de30e9682dc25cdd12c7751ddb4f97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237600
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-15 22:28:25 +00:00
Rebecca Stambler
9fe02d1961 internal/gocommand: refactor API to always use *gocommand.Runner
We should always go through the runner to avoid load serialization
errors. This change also updates the comments and uses pointers to
Invocations consistently. This causes a few updates throughout x/tools.

This change also results in a few modifications to the go:generate code
lenses, as they operate on directories rather than file URIs.

Change-Id: I6306e761e68dfdd23f1b410e44aab0ffa85d234c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237685
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-15 22:00:55 +00:00
Rebecca Stambler
e31b568ad1 internal/lsp: plumb fillstruct through analysis
Now that fillstruct is an analyzer, we can simplify the code that calls
it in code_action.go. We introduce a new class of analyzer --
convenience analyzers, which are closer to commands. These represent
suggestions that won't necessarily improve the quality or correctness of
your code, but they offer small helper functions for the user.

This CL also combines the refactor rewrite tests with the suggested fix
tests, since they are effectively the same.

For now, we only support convenience analyzers when a code action was
requested on the same line as the fix. I'm not sure how to otherwise
handle this without bothering the user with unnecessary diagnostics.

Change-Id: I7f0aa198b5ee9964a907d709bae6380093d4ef21
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237687
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-15 21:22:08 +00:00
Heschi Kreinick
a2fa627c4b internal/lsp/cache: don't skip x_tests
We were marking normal tests as workspace packages, but pruning x_tests.
Don't do that.

Fixes golang/go#39578.

Change-Id: Ia8eceea38e63ac17e40f50d6837de9c7a668469b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237943
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: zikaeroh <zikaeroh@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-15 19:08:35 +00:00
Heschi Kreinick
1725ffee6d internal/lsp/cache: hide diagnostics for ignored dirs
The go command ignores go files in specially-named directories like
testdata. We probably still want to try to offer services like
autocomplete and jump-to-definition there, but diagnostics are less
likely to be helpful. As a compromise, just squash diagnostics.

Note that the rules we use are slightly wrong; see the comment on
ignoreFiles for details.

Fixes golang/go#39563.

Change-Id: I0bc00639e68bd71ea55d867af36e07ef4ec780a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237638
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-15 17:27:23 +00:00
Heschi Kreinick
54c614fe05 internal/imports: continue past parse errors
A user that's editing packages in their workspace may introduce parse
errors (missing package statement), but we still want to be able to add
imports for them. Continue past parse errors.

Fixes golang/go#39315.

Change-Id: I3bbf428e7b9ef32a87258af2dafbe0d7b86b7348
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237686
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-12 22:08:49 +00:00
Josh Baum
a1e2396bbd internal/lsp: port fill struct into analysis framework
The current implementation of the fill struct tool is not a part of
the analysis framework. This commit moves the functionality from the
source directory to the analysis directory.

Change-Id: Ibe37b57f3e6680c8729932dbbe010a4642600e4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237258
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-12 20:33:59 +00:00
Heschi Kreinick
4651fa3054 internal/lsp/debug: show per-package memory usage
Calculate and display very crude memory usage statistics. This is
complicated by various levels of sharing and indirection, so the numbers
should be taken with *large* grains of salt and interpreted mostly by
experts.

Still, the results are interesting and helpful.

Change-Id: Ia9aff974c7d5fddd63df0cfd5cecc08ead33cf84
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236163
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-12 20:10:52 +00:00
Hana (Hyang-Ah) Kim
e8084ff2bf gopls/doc: fix composites analyzer name
Not composite, but compositeS.

Change-Id: I5549653748bef90338263aea0380f662eba723d3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237682
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-12 18:47:36 +00:00
Rebecca Stambler
3c1b287bbd internal/lsp: await the initial workspace load in ModHandle
ModHandle races with the initial workspace load if the go.mod file does
not yet exist. We should await for the initial workspace load to
complete before proceeding with update codelenses, etc.

Part of trying to figure out the flakes in golang/go#39504.
Also a few staticcheck fixes, and fix the Windows line endings in
fill_struct.go, because `git gofmt` complains.

Change-Id: Ide21a47137390792d1afb924740cff0bb6f0b764
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237419
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-12 18:21:55 +00:00
Rebecca Stambler
9001f16f58 internal/lsp: cancel the initial workspace load when view shuts down
The error messages from view cancellation clutter up the logs when
testing, especially if you're running a single subtest.

A few quick staticcheck fixes in the CL also.

Change-Id: Ia1ed5360ac754023c589ed526ec0ed3e94a79b2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237637
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-12 18:06:40 +00:00
Sam Cross
74a3dbbe14 gopls/doc: update vscode-go GitHub link
The GitHub repository for vscode-go has been moved to https://github.com/golang/vscode-go. This change reflects that.

Change-Id: I3915ee0db39f8c069c83572893bae2f3d48a4aa9
GitHub-Last-Rev: 8eda352810368352320b7a25846ccbf4d2591c0c
GitHub-Pull-Request: golang/tools#234
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237657
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-06-12 15:25:27 +00:00
Ian Cottrell
742c5eb664 internal/lsp: fix the cache debug page
The cache does not know the sessions associated with it, so the
debug template cannot display them.

Change-Id: I9b043592351ddce097f4e74f3e9aa7a6ad24e613
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237618
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-12 02:23:31 +00:00
Heschi Kreinick
f520afa52e internal/lsp: remove Ignore feature
Ignore ignored the builtin package and files that start with _. The
latter should already be ignored by "go list". The former seems
like too much effort to me. People shouldn't edit random parts of the
stdlib, and ignoring changes to (e.g.) the Error interface seems like
the least of the trouble they can get themselves into.

Remove it for now. If we get complains I'll re-add it, probably by
rejecting the write entirely somewhere.

We incidentally relied on this in the identifier functions; change those
to treat the builtin package slightly more specially.

Change-Id: I005b02a66b1a987c50a3074d53a2d28ff07d3324
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237597
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 22:55:14 +00:00
Heschi Kreinick
02f7de68dc internal/lsp/cache: vendored packages are not workspace packages
Most people aren't going to edit vendored packages; we don't need to
fully analyze them.

Fixes golang/go#38080.

Change-Id: I9c9a286b5340ecffe976b0ea652f1d3b4de4bd41
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237598
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 22:31:50 +00:00
Heschi Kreinick
ca43edf915 internal/lsp/cache: intermediate test variants aren't workspace packages
When you write a test in (say) the fmt package, you get a test variant
augmented with the test files. In many cases you also get test variants
of the things the fmt package depends on. The primary test variant,
(fmt [fmt.test]) is interesting to us, because it contains the tests.
But the intermediate variants (testing [fmt.test]) aren't -- the user
can only get to them indirectly. We certainly don't need to fully parse
them.

Treat intermediate test variants as non-workspace packages. This doesn't
accomplish much yet but paves the way for later optimizations.

Updates golang/go#36943.

Change-Id: I1a20abcd2d67767f07132a75a20f098be6f19a76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236397
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 22:26:57 +00:00
Heschi Kreinick
ecd3fc4348 internal/lsp: read files eagerly
We use file identities pervasively throughout gopls. Prior to this
change, the identity is the modification date of an unopened file, or
the hash of an opened file. That means that opening a file changes its
identity, which causes unnecessary churn in the cache.

Unfortunately, there isn't an easy way to fix this. Changing the
cache key to something else, such as the modification time, means that
we won't unify cache entries if a change is made and then undone. The
approach here is to read files eagerly in GetFile, so that we know their
hashes immediately. That resolves the churn, but means that we do a ton
of file IO at startup.

Incidental changes:

Remove the FileSystem interface; there was only one implementation and
it added a fair amount of cruft. We have many other places that assume
os.Stat and such work.

Add direct accessors to FileHandle for URI, Kind, and Version. Most uses
of (FileHandle).Identity were for stuff that we derive solely from the
URI, and this helped me disentangle them. It is a *ton* of churn,
though. I can revert it if you want.

Change-Id: Ia2133bc527f71daf81c9d674951726a232ca5bc9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237037
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 22:11:59 +00:00
Rob Findley
782c6b3cc7 internal/lsp/regtest: fix context for shared server
The shared server was executing on ctx.Background(), which meant it
didn't have a debug.Instance. This resulted in logs being printed to
stderr, due to the fallback behavior of the global exporter.

Fixes golang/go#39130

Change-Id: Ibb968f78d69752452bec71a7abeff808b1cccb04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237583
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-11 19:17:43 +00:00
Rob Findley
7ffd523398 internal/jsonrpc2: try to suppress unnecessary errors on shutdown
Even on successful shutdown, test logs contain a lot of "failed reading
header line: EOF". This can be distracting, or worse, misleading. Do our
best to suppress these error logs.

Updates golang/go#39130

Change-Id: I6ebe61100501f69c7490b418f53871b4e9704a00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237582
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-11 19:17:06 +00:00
Rob Findley
c1702b46e6 internal/lsp/regtest: print RPC logs when verbose output is enabled
Use the -v flag to control whether RPC logs are always printed, rather
than a regtest specific flag.

Updates golang/go#39130

Change-Id: Ie6293815adee4b59defd80cfc015838cfbf2b3e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/235920
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-06-11 19:16:16 +00:00
pjw
99be2d6e79 internal/lsp: bring lsp protocol stubs up to date
The only substantial change is data types for CallHeirarchy.

util.ts has changed the hash, and adapted to a new source layout, plus
the usual pointless whitespace changes. code.ts has learned a little more
about typescript ASTs.

Change-Id: I9cb3a9a9034d46f4a479123779da3bb3474e4a42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237377
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 18:15:06 +00:00
Josh Baum
40866c6c36 internal/lsp/analysis/fillreturns: implement matching in fillreturns
The existing implementation looks for matching types in the declaration
and the leftmost value in the return statement. Instead, the analyzer
now searches across all the values in the return statement to find one
that matches the type in the declaration. Additionally, if a value in
the return statement does not match any type in the declaration, it is
not overriden.

Change-Id: I4d4aed0ef67e59bfd886b44055d523a8c478255c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236962
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 16:18:57 +00:00
Ian Cottrell
54cf04ef09 internal/lsp: decouple client and server debug
This uses log messages to convey information to the debug system, which
has the benefit of logging even if the debug pages are not active and
also not requiring systems to reach into the debug system or require
extra lifetime tracking Not all things are decoupled yet as there are a
couple of places (notably the handshaker) that read information out of
the debug system.

Change-Id: Iec1f81c34ab3b11b3e3d6e6eb39b98ee5ed0d849
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236337
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-11 13:49:48 +00:00
Heschi Kreinick
1fdcbd1300 internal/lsp/source: format fill_struct.go
Change-Id: Iaf238dfba6f51aed0a15f6ef2b231e1a1816f683
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237421
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-11 03:21:20 +00:00
Matthew Dempsky
2ee2e4c56a go/packages: move TypecheckCgo to packagesinternal
Updates golang/go#16623.
Updates golang/go#39072.

Change-Id: I6612cdac14faa5ad724ceb805e1d6c823b4046ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237423
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-10 22:20:39 +00:00
Matthew Dempsky
51e3d70dba go/packages: use go115UsesCgo instead of UsesCgo
x/tools half of golang.org/cl/237417.

Updates #16623.
Updates #39072.

Change-Id: Ic31c2cf64dc1b71b70912b9641cf468f60d116f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237418
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-10 21:22:23 +00:00
Michael Matloob
3e83d1e96d go/packages: add a mechanism for drivers to decline requests
driverResponse now has a NotHandled field, which, when it's set,
indicates to go/packages that the driver can't handle a request.
go/packages will then fall back to the go list driver. In the
future we might allow multiple drivers to be listed in
GOPACKAGESDRIVER that can be called in a chain.

Fixes golang/go#39202

Change-Id: I21d0d2226070f8e25e4cd918b4b9b3be3f3d28b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236758
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-10 16:09:56 +00:00
Michael Matloob
03e6e36be9 internal/testenv: add a NeedsGoBuild function
This function will skip tests in test environments where
the go command can't be used to build and run binaries.

This will be used by the test in golang.org/cl/236758

Change-Id: Ie61e8890084179b0e999dd377148693395043191
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236920
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-10 16:09:22 +00:00
Heschi Kreinick
7567580308 Revert "cmd/goimports: return exit code 1 when -l finds files to change"
This reverts CL 234484/commit e641245118.

Reason for revert: Incompatible behavior change.

Change-Id: I82216a2a352e6da62d1a09e47b3774d52527effc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237378
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Khosrow Moossavi <khos2ow@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-10 16:09:17 +00:00
Pontus Leitzler
8d7dbee4c8 internal/lsp/source: support labeled statements when highlighting loops
When document.Highlight is called with the cursor on a loop statement or
branch statement, gopls doesn't look for labels. Placing the cursor at
the break statement below highlights the inner for loop:

Outer:
for {
    for {
        break Outer
    }
}

By making highlight label aware, and ensure that unlabeled "break" in
"switch"/"select" doesn't highlight the outer loop, this change fixes
loop highlighting.

Adding support for highlight of "switch" and "select" will be handled in
a separate CL.

Updates golang/go#39275

Change-Id: I7014aa7b0dfb1da871863ced611623be995f3944
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236524
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-10 05:20:24 +00:00
Dominik Honnef
eb789aa7ce go/analysis/internal/checker: don't filter facts of parameters
Change-Id: Iec34ff62159b77eda6732e16b710a5809cf7329b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236526
Run-TryBot: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-06-09 16:44:05 +00:00
Ian Cottrell
5359b67ffb internal/lsp: minor protocol cleanup
This moves as much code outside the protocol generator
as possible making it easier to maintain both the code
and the generator.

Change-Id: I7fe932a58facece5bb0bd5a9c158e5cc7d5a277b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236838
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-09 12:41:32 +00:00
pjw
308beac283 internal/lsp: add a way for regtests to look at the diagnostics
regtests can use Await to wait for diagnostic expectations. But sometimes
it is useful (or more robust) to then look at the specific diagnostics.
This change introduces env.DiagnosticsFor, which returns the current
diagnostics for a file.

Change-Id: Iea35d28f6679289795bc853f156aae351279b205
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236837
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-09 09:53:42 +00:00
Agniva De Sarker
6eec81c746 cmd/godoc: support automatic vendoring
Fixes golang/go#35429

Change-Id: I060ccfbed4c3975d1ddc94fda4fadea527b29841
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232958
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-06-09 06:04:08 +00:00
Pei Xian Chee
1b747fd945 internal/lsp: remove debug line
Remove debug line from CL 227437

Change-Id: Ib33dc6eb05039e78b4a0c883f7ad525fe24d3de7
GitHub-Last-Rev: dbd47a0713d3c39cc0d95b1660f9189ae9927755
GitHub-Pull-Request: golang/tools#233
Reviewed-on: https://go-review.googlesource.com/c/tools/+/236919
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-08 17:46:01 +00:00