1
0
mirror of https://github.com/golang/go synced 2024-09-30 20:28:32 -06:00
Commit Graph

4977 Commits

Author SHA1 Message Date
Rebecca Stambler
7a9acb0a45 internal/lsp/source: fix panic in test code lens
Change-Id: I727b2772c63752cb5d3bb4b9165f984b64adc842
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239752
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-24 22:30:20 +00:00
Rebecca Stambler
25775e59ac internal/memoize: add an error return to (*handle).Get
Fixes golang/go#36004

Change-Id: I8da7c21eaa9cf6ffac12aabdd6803d06781cef32
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239564
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-24 16:33:19 +00:00
Thomas
dcbf2a9ed1 internal/jsonrpc2: omit empty error data
The spec states error data may be omitted. It is currently always encoded
as null, despite having no usage.

Omit the field if empty, and add a test to prove the behaviour.

Fixes golang/go#39736

Change-Id: Icdb39409010f3a42f84d2372c2061e4bc7cc198e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239059
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-24 06:08:01 +00:00
Rebecca Stambler
f8e0ea3a3a internal/lsp/analysis/fillstruct: add indentation for struct fields
Getting the right indentation for the text in the AST proves to be a
little complicated. The most reasonable approach seems to be writing
out the AST, getting the lines with the struct definition on it,
and trimming whitespace to get the current indent. Then, we add this
indent to the struct fields in the new text.

Change-Id: I1cc3421d95edae61cfb662254ff3fb759b5c487f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239199
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-23 20:47:33 +00:00
Josh Baum
456ad74e14 internal: fill struct with initialized values instead of nil values
The previous implementation filled map, slice, channel, signature, and
pointer types with nil values rather than initializing these types.

Change-Id: I558446af31fdd8877db5eb3cd92b4004f5d5ab22
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239039
Run-TryBot: Josh Baum <joshbaum@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-23 18:51:56 +00:00
Rebecca Stambler
1745ac5bc6 internal/lsp: refactor various module-specific handles in cache
This change separates out different functions of mod handles.
Previously, we had ModHandle and ModTidyHandle. ModHandle was used to
parse go.mod files and get the results of `go mod why` and possible
dependency upgrades.

Now, we factor this out into 4 handles: ParseModHandle, ModWhyHandle,
ModUpgradeHandle, and ModTidyHandle. This allows each handle to be
specific to its own functionality. It also simplifies the code a bit,
as the handles can be written in terms of ParseModHandles instead of
FileHandles.

I may have some follow-up CLs to refactor the `go mod tidy` logic out of
the cache package, though I'm no longer certain that that's a good
choice.

Change-Id: I8e12299dfdda7bb61b05903d9aa474461d7f4836
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239117
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-23 18:31:46 +00:00
Carlos Iriarte
ff88973b1e gopls/integration: fix typo aloso => also
Change-Id: Id66e75957bda73f5e4aec98a887b61b834e620ef
GitHub-Last-Rev: 6f8b75c0388de580a0a8bdde6191431c6e1c873a
GitHub-Pull-Request: golang/tools#235
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238497
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-23 04:56:35 +00:00
Rebecca Stambler
20e05c1c8f internal/lsp: don't use -modfile for go mod commands
These are commands whose changes should be reflected in the existing
go.mod file, as they do not provide edits. Add a third way of running
the go command, explicitly without -modfile. Update the regression test
accordingly.

Change-Id: I866b5db83b504fae190e58c306c01a7a4296672d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239200
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-22 20:30:43 +00:00
Heschi Kreinick
4fd1c64487 internal/lsp/cache: fix ignored file check
The return of IgnoreFile. We continue using go list's ignore rules,
but only apply them to the part of the path underneath the source root.

This should be fixed to include replace targets once we have them.

Change-Id: I054fee8c12fc860a279b0d0c1fd670f44d78a63f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239288
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-22 19:29:24 +00:00
Ian Cottrell
fcc5b64fe1 internal/jsonrpc2: don't set result in response if there is an error
Marshalling an empty raw message produces a null rather than omitting the field
Instead we do not set the field unless there is no error.
Includes a test that reproduced the issue before the fix.

Fixes golang/go#39719

Change-Id: I683b8ea55d3425613fc956993280ff51202f49fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239097
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-22 15:00:58 +00:00
Josh Baum
0f592d2728 internal/lsp/analysis/fillstruct: use AST nodes to fill struct
The current implementation writes strings to the diagnostic instead
of creating new AST nodes.

Change-Id: Ibb37a93a3c43fb74ec5dc687091601e055c6e1b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238198
Run-TryBot: Josh Baum <joshbaum@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-19 21:01:11 +00:00
Rebecca Stambler
6c6fd98e38 internal/lsp: fix panic in computing diagnostics for module
We were returning empty diagnostics for an empty file.

Fixes golang/go#39696.

Change-Id: Idfd50980f4bf771f76ad7b7fb6180a5f712a92bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239040
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-19 20:49:21 +00:00
Rebecca Stambler
7c47624df9 internal/gocommand: use semaphores to ensure correct serialization
Piped go commands cannot run concurrently, as a user may be looking at
the stdout/stderr, and we don't want to show any load concurrency
errors. We use a semaphore with a maximum number of in-flight go
commands to make sure that all running go commands have completed before
starting a piped command.

Change-Id: Ie027d9ff704fb7dd9640da06569345e89ed7a012
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238059
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-19 18:00:55 +00:00
Heschi Kreinick
8b7669898d internal/lsp/debug: save per-package stats in memory debug files
The per-package stats have proven pretty useful, and I don't want to
have to teach users how to save them. Create zip files and add them in.

Since some users may be sensitive about revealing any information about
the code, generate two variants: one with package names, and one
without.

Change-Id: Icc5631b4cebbbabfdd2fcea4a4cdf4f205dbcab9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239037
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-19 18:00:37 +00:00
Rebecca Stambler
6023b8da91 internal/lsp: use -modfile for import organization
Also add a regression test.

Fixes golang/go#39681.

Change-Id: I685fbe4255b9e8e067dacd84a6d464d0a2bbe1f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238737
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-06-19 17:44:56 +00:00
Pontus Leitzler
aaae6734f9 internal/lsp/cmd: add example to cli help for -ocagent flag
I've forgotten to specify scheme a few times, and gopls is quiet
about invalid ocagent addresses.

Add an example to the CLI help output aid the users with the format
implicitly.

Change-Id: I89ba8a16c18dabff2b4b87b2235755c22ae71117
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239057
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-19 16:26:05 +00:00
Pontus Leitzler
037be6a065 internal/lsp/source: support highlight of switch statements
Placing the cursor on a switch statement or corresponding break and call
document.Highlight will now highlight them.

Fixes golang/go#39275

Change-Id: Ib7e3ba0c6e78141ed3dd37cfd3b72b567b857247
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238478
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-06-19 02:36:21 +00:00
Rebecca Stambler
c7475b9d7f internal/lsp/source: refactor highlighting code
The current implementation has a number of helper functions that have to
thread through context, errors, converters, etc. Simplify the code by
factoring out the conversion to a protocol range into a final step.
There are probably further improvements that can be made too.

As part of debugging, I noticed that the cmdtest server does not get
shutdown once tests finish, which leads to excessive logging. Is closing
the test server connection enough to trigger shutdowns? It doesn't seem
to be.

Change-Id: Ia67666f6b8debccd120795bb24bd089620c0a87b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238377
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-18 15:59:44 +00:00
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