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

1801 Commits

Author SHA1 Message Date
Rob Findley
b8469989bc internal/lsp/fake: fix some messiness around client hooks
While writing the fake editor, I added some state tracking without using
it (log messages, events etc). We have since duplicated this logic in
the regtest package using client hooks.

Fix two messy aspects of this:
 - remove the state tracking in the editor
 - pass in the client hooks when connecting, so that they may be used
   without locking, and so that we do not miss any hooks that may fire
   during session initialization.

Change-Id: I24c17a28e9cfa4fca32b7ddd17c7bf01cbb12e0f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232744
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-08 18:47:54 +00:00
Rob Findley
88bf40a80d internal/lsp/source: use the setString method when setting options
A couple string options were not using the asString helper. Update them,
and also add a setString helper to be consistent with setBool.

Change-Id: I38caef5b1595a3535b759e5bf1c8d350a8bf061e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232741
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-08 18:47:48 +00:00
Rob Findley
cb8d9cd245 internal/lsp: support configurable codeLens
Some code lenses may be undesirable for certain users or editors -- for
example a code lens that runs tests, when VSCode already supports this
functionality outside of the LSP. To handle such situations, support
configuring code lenses via a new 'codelens' gopls option.

Add support for code lens in regtests, and use this to test the new
configuration. To achieve this, thread through a new 'EditorConfig' type
that configures the fake editor's LSP session. It made sense to move the
test Env overlay onto this config object as well.

While looking at them, document some types in source.Options.

Change-Id: I961077422a273829c5cbd83c3b87fae29f77eeda
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232680
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-08 18:47:35 +00:00
Rebecca Stambler
480da3ebd7 internal/lsp: return early in completion where possible
This a pure cut-and-paste.

Fixes golang/go#38868

Change-Id: I2ff07134a8b9f6186bab737caceab8a34a8e2f44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232677
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-05-07 20:50:54 +00:00
Rebecca Stambler
6441d34c3f internal/lsp: fix caching issue with duplicate handles
In (*snapshot).addPackage, we return early if the package handle is
already cached, but we continue building the dependency graph with a
handle passed into addPackage.

This seems fine since both handles should have the same cache key,
but if we clone the snapshot, we will end up dropping the handle that
had the type information on it. It will then have to be recomputed,
causing the skew in the types.Package.

Fixes golang/go#38403

Change-Id: I0e360447a428123fcac444fbea3c2a3232ef941a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-05-07 19:23:25 +00:00
Rob Findley
08cbf656ce internal/lsp/cache: add an UnsavedFiles method to Session
It is useful to know whether the session has any unsaved files, for
example to warn/error when executing a command that interacts only with
files on disk.

Add a new UnsavedFiles method to the Session.

Change-Id: Iea4bf472e3ed6897979306b670eb974a2ee0d3bb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232747
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-07 17:51:45 +00:00
Richard Miller
ff647943c7 internal/testenv: make ExitIfSmallMachine apply to plan9-arm builders
Some x/tools tests use too much memory (virtual or real) or other
resources to run on "small" builders. Originally only linux-arm
was classified as small. This change addes plan9-arm to the list,
since it normally runs on Raspberry Pi boards with 1GB of RAM.

Partial workaround for golang/go#38772

Change-Id: I93307af10cccf7b1e26d57b9af914c85cf676d43
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232478
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-05-07 17:29:48 +00:00
Hana (Hyang-Ah) Kim
625332f3c5 internal/lsp/protocol: send responses for cancelled requests
LSP https://microsoft.github.io/language-server-protocol/specifications/specification-current/#cancelRequest
expects the server to send back the response even when the request is cancelled.

Gopls LSP protocol implements the cancellation using the context cancellation.
That is, upon a cancellation request from the client, the server calls the
corresponding canceller that cancels the context passed to the handler.
Reusing this cancelled context for the replyer is not safe because code in any layer
can decide to shortcircuit and skip sending the data back to the client.
E.g. https://cs.opensource.google/go/tools/+/master:internal/jsonrpc2/stream.go;l=63

This CL make sure to pass the detached context to the replier.

Alternative, or a better approach to avoid any unexpected side-effect of
using a detached context is to send out the response at the point of cancellation
with a separate context. But that requires more significant code change.

Testing is currently hard, but maybe doable once the current refactoring is
done. Test is left as a TODO.

Change-Id: I4611af00ad913e96b62c6b7180c6673b0465daf9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232300
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-05-07 15:26:07 +00:00
smasher164
a1532b81a2 internal/lsp/cache: avoid string(int) conversion
LoadMode and ParseMode are currently hashed with a string(int)
conversion, but this conversion is now discouraged (see the vet check
'stringintconv' for more information). Since the hash uses the code
point, this change replaces these instances with string(rune(int)).

Updates golang/go#32479.

Change-Id: I0d8e91d073fc34ac9faafe75a0d86cf71a5327d4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232679
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-07 05:02:07 +00:00
Rob Findley
be0c89d0d3 internal/lsp/fake: check for file changes after running the Go command
Our fake.Workdir generates synthetic file events for "watched" files
when using its file API, but we have no such hooks for file changes
originating from an external process, in this case the go command.

Previously, we detected a file event by checking go command logs to see
if a go.mod file was created. This is bound to be fragile, so we replace
this with a helper function that walks the working directory looking for
changes.

Change-Id: I2c2176099b97f3a3b25f4aed2b18de13ae05544a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232637
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-07 03:33:52 +00:00
Rebecca Stambler
88e38c1d8d internal/lsp: make sure diagnostics only refer to existing files
We were previously sending diagnostics for nonexistent files, and then
adding them to the snapshot in the process. Remove this behavior, and
add a regression test. Case insensitive filesystems were too confusing
to write a test for, but fortunately, Filippo reported another instance
of this bug, so I used that for the regression test.

Fixes golang/go#38602

Change-Id: I4ef6b51944f3338e838875a5aafffd066e8392f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230315
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-05-07 02:01:22 +00:00
Rebecca Stambler
002d754683 internal/lsp/regtest: add test for a GOPATH that's missing an element
Test the case described in
https://github.com/fatih/vim-go/issues/2673#issuecomment-622307211.

Change-Id: I55ff3b8719fc255ec0901cf3778e68b48630323d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232360
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-05-07 01:58:00 +00:00
Rob Findley
c20a87c16a internal/lsp/fake: split up and rename the Workspace type
The Workspace type has accumulated too much additional functionality of
late: managing the Env, GOPATH, and GOPROXY in addition to the working
directory. Additionally, the name 'Workspace' can easily be confused
with 'workspaceFolder' in the LSP spec, and they're not quite
equivalent.

Split off a Proxy type to be responsible for the fake module proxy, and
a Workdir type to be responsible for working with the temporary
directory. Rename what remains of 'Workspace' to a more appropriate name
for such a collection of resources: Sandbox.

This is mostly just moving things around, with one significant change in
functionality: previously our three temporary directories (workdir,
gopath, and goproxy) were in separate toplevel directories below
$TMPDIR. Now they are all below a new sandbox temp directory, so that
they are correlated in the filesystem and can be cleaned up with one
call to os.RemoveAll.

Change-Id: I1e160a31ae22f0132355117df941fe65822900eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230758
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-06 18:17:57 +00:00
Rob Findley
9f0e5ee6c7 internal/lsp/fake: skip TestWorkspace_CheckForFileChanges
This test is failing on darwin-amd64-10_12: skip it while I investigate.

Change-Id: I506f54355924e86cf4235b04fd8890f59b48ac33
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232198
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-04 21:58:16 +00:00
Rob Findley
9bfbc38543 internal/lsp: fix incorrect format strings when calling event.Error
I noticed that in a couple places, event.Error was called with a
message containing formatting verb. This was my likely done out of
habit, but is an incorrect use of the API: err is not formatted in the
message but is rather applied as an event label.

Remove the unused formatting verbs.

Change-Id: I52f914da81e338013c7449066e5d9ffa40a0a4c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232137
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-04 19:35:31 +00:00
Rob Findley
1d9c21a7db internal/lsp/regtest: add support for testing generate commands
Our editor interaction for running `go generate` was untested. Add
support for triggering generate from the fake editor, and a simple test.

To enable this, some helpers were added to list Workspace files and
check for file state changes, to avoid having to synthetically create
file events. This workaround is not ideal as it results in a leaky
abstraction: in other cases the regtest may assume that FileEvents are
triggered by workspace interactions (e.g. ws.WriteFile), but in this
case it cannot. Unfortunately the only real solution for this would be
to make file watching more realistic, by polling file state on an
interval or using an actual file watching library. Neither of those
options seemed worthwhile just to keep the fake.Editor API pristine.

A new debugging option is added, SkipCleanup, to allow inspecting
regtest working directories after a test with minimal code change.

Change-Id: I64dceeb21a4eb9eff2b6936e44f80f4bd24b82da
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230313
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-04 19:25:30 +00:00
Ian Cottrell
33427f1b03 internal/jsonrpc2: rename NewStream to NewRawStream
NewStream implies the default stream type, which it is not.
NewHeaderStream is actually the default choice.

Change-Id: I1744d7e902d27c13393f3b367fe2d29e5d7dc283
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231618
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-05-04 15:25:39 +00:00
Ian Cottrell
535e1470ec internal/lsp: use %w in error wrappers
This fixes a bunch of fmt.Errorf calls to use %w rather than %v when wrapping
an error with additional context.

Change-Id: I03088376fbf89aa537555e825e5d02544d813ed2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231477
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-04 14:52:14 +00:00
Clint J Edwards
6b6965ac5d internal/lsp: add comment completions for remaining exported symbols
This should provide simple name completions for comments
above exported vars, constants, functions, and types.

Can be activated with `ctrl+space` within a comment.

Also fixes a panic introduced in the previous commit when completing comments that occur at the end of a file.

Fixes #34010
Fixes #38793

Demo: https://i.imgur.com/qN82CVA.mp4

Change-Id: If9aaec7ce03a3e085361144bce5c7a66535127d1
GitHub-Last-Rev: b9ac874c7ff3c9a164ba698d0d561141a59e2435
GitHub-Pull-Request: golang/tools#224
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230215
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-04 02:29:51 +00:00
pjw
ed308ab3e7 internal/lsp: avoid showing no-GOPATH-nor-module message so much
If the user's workspace is neither in GOPATH nor a module, and there
are errors in their code, send a message (with ShowMessage) only on
the first load, or when the configuration changes. The previous
behavior sent the message more frequently.

There is a regtest, and two new Expectations for when the fake
editor sees (or does not see) a ShowMessage notification.

Fixes golang/go#37279

Change-Id: I076bd95105359b9310dcf97019e3559159271356
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230897
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-02 20:28:11 +00:00
Robert Findley
542909fd99 internal/lsp/cmd: partially revert "add a flag to disable telemetry"
This reverts commit 17a19b5fe7. The revert
is partial because that change also added the -short flag when running
govim tests, which we preserve as without this the tests often time-out
(and I don't want to increase our test timeout right now).

Reason for revert: telemetry races have been fixed in https://golang.org/cl/226317

Change-Id: I5fcf034c1fe6e2db48994e2f06b73a593c779e54
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231637
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-01 20:57:27 +00:00
pjw
2658dc0cad internal/lsp: add a regtest for formatting one-line files
Issue https://github.com/golang/go/issues/36824 complained about
legal go code (e.g., 'package a; func f() {}') that was mishandled
(by being rewritten just as 'package a'). This bug seems to have been
partially fixed, as certified by the new regtests. The comment on
OneLineImports36824 says that the bug would be fixed if gopls
formatted the file before fixing the imports, but it doesn't.

Change-Id: If27fa738e54d9434d5b2f17ed4e52d555cb7c499
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229303
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-01 15:50:19 +00:00
Rebecca Stambler
ab2804fb9c internal/lsp: don't offer suggested fixes for generated files
As suggested on Slack, a better fix for golang/go#38467 would be to hide
suggested fixes on generated files. This way, the diagnostics are still
visible but files are not unintentionally modified.

Also, deleted the SuggestedFixes field on source.Diagnostic, since it's
entirely unused.

Change-Id: I10756471e0f913465b1cccd7f222eea0f4de77fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230999
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-05-01 06:56:59 +00:00
Ian Cottrell
d351ea090f internal/event: fix the agent start time
The current use of start time in the cache key prevents re-use of agents under
some circumstances, so we update it later in the exporter instead.

Change-Id: I2f6927d65a0841f77a0ee1b848b5a3b243936083
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231257
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-01 00:59:04 +00:00
Muir Manders
f26c0dd982 internal/lsp/source: improve unimported package member ranking
Untyped members from unimported packages are scored the same as typed
members from unimported packages. We depended on the unimported
package relevance to rank the probably-more-relevant typed members
higher. However, there are some unrelated score penalties that can
only be applied to typed candidates, so the untyped candidates ended
up being ranked higher. Fix by increasing the relevance coefficient so
the relevance score overpowers other less important scoring
adjustments.

Fixes golang/go#38104.

Change-Id: Ie43f769a41511f9cc3747ce6936130be7a29cd31
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231238
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-30 22:11:53 +00:00
Rebecca Stambler
2840dafb9e Revert "internal/lsp: hide analysis diagnostics from generated files"
This reverts commit e4881b2459.

Reason for revert: <CL 230999 has a different approach to this>

Change-Id: I9ec47d858e7db2a66ec8a93063ab950b8553e45b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231042
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-30 19:28:56 +00:00
Ian Cottrell
4b814e0613 internal/event: re-use ocagent exporters
This attempts to detect a Connect call with the same configuration and return
the same exporter.
This mostly affects tests where we end up starting a new ticking go-routine per
test, even though they all have the same configuration. It was noticable that
a goroutine dump of a test would have a very large number of go routines that
were just ticking exporters, making it very hard to see the real work.

Change-Id: Ie8b64b69fce736d2bf3dbadffc1681f7caee6dd8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230463
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-30 04:03:29 +00:00
Ian Cottrell
28a3422bd6 internal/jsonrpc2: move the lock into logCommon
This means the lock is no longer held when writing to the underlying
stream.

Change-Id: I4f066ff593e35d771aa989c762712e4dd83a3f81
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231040
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-30 04:03:07 +00:00
Rob Findley
127c98bd79 internal/lsp/regtest: rearrange runner.go for readability
This is purely moving code: the getRemoteSocket, getTestServer, and
AddCloser funcs were above the more important RunOptions and runner.Run.
Move them closer to their usage.

Change-Id: I6d5b5577ca8ba5cbd5226b195541696967433dec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230998
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-29 21:33:35 +00:00
Heschi Kreinick
290e0af1a2 internal/lsp/regtest: cosmetic fixes
Add issue comments to tests for issues, move a couple constants closer
to their use.

Change-Id: I34fa2643195ae81e463a070952a1a1a4af2c6132
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230997
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-29 21:16:28 +00:00
Rebecca Stambler
b8428586f4 internal/lsp: handle hover documentation for package declarations
We had previously not been generating documentation on hover for
package declarations or import specs. We do this by adding a few special
cases, since package declarations don't appear in type information.

Throughout, we make the assumption that only one file in a package will
have the documentation for the package. go/doc just appends
documentation as it sees it. We may be able to do better by checking for
a "Package ..." but that still is not guaranteed. Not sure what the
right approach is, so this assumption may be the best option.

Fixes golang/go#38526

Change-Id: Ibc515f8729e1aba0d11090be62371be6b18d0cfa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230417
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-29 20:57:41 +00:00
Rebecca Stambler
e4881b2459 internal/lsp: hide analysis diagnostics from generated files
Don't show non-vet analyses when they appear in generated files. Vet
analyzers will give useful reports even in generated files.

Fixes golang/go#38467

Change-Id: I0e628760b386553932de4cf1f5ba39784a205b53
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-29 20:34:34 +00:00
Rob Findley
0c9eba77bc internal/lsp/regtest: add a OnceMet combinator for Expectations
A common problem when writing regtests is that if you have an error in
your expectations, you must wait until the regtest times out to see what
went wrong.

With the integration of additional progress reporting in the LSP server,
we know when diagnostic work should have been completed, and we should
be able to fail tests early once we know that our diagnostic
expectations will never be met.

This CL adds a new OnceMet Expectation, which combines two expecations:
the first is a precondition that must be met before checking the second.
The second is an arbitrary expectation, but is translated as follows:
once the precondition is met, the second condition is checked and any
Unmet verdicts are translated into Unmeetable.

Change-Id: Ie8c677229a347c624e2659a3ef9104304b175243
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229977
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 21:14:28 +00:00
Rob Findley
dbf5ce1eac internal/lsp/regtest: add expository package documentation
Update the regtest docstring to further explain how the package works,
and give a sense for why it exists.

Fixes golang/go#36879

Change-Id: I4df4a286dc835ae56386b6d92128f7ea6c77ffb0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229782
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 21:10:48 +00:00
Rob Findley
12a1c85843 internal/lsp/regtest: rename and document some symbols
Minor cleanup for the regtest package:
 - EnvMode is renamed to Mode, because it's really a server mode and not
   directly related to the Env type.
 - Modes are better documented.

Change-Id: Ia3aedfc70b665ea75a66731a72e4e87ae79db298
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229781
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 21:10:38 +00:00
Rob Findley
317da45f2f internal/lsp/regtest: extract Runner to a new file
The file length of env.go is getting hard to manage, so factor out the
test Runner to a new file.

Also move Runner.Close to the bottom of the file to have a more logical
progression.

Change-Id: Ifebea3277d826e9456aa02507a8349746386eb03
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229780
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 20:47:08 +00:00
Rob Findley
46dc332f25 internal/lsp: instrument work done reporting to use in regtests
In order for regtests to wait until file diagnostics are complete,
instrument diagnostics with verbose WorkDone reporting. In order for
this to be granular enough for use, the modification source needed to be
threaded through to the didModifyFiles function (which is where the
diagnostic goroutine is spun off).

A new expectation is added: CompletedWork, to allow specifying that a
specific work item has been completed. The problem with using
NoOutstandingWork was that it required a continuous chain of work to
prevent the regtest from succeeding when the bug was present, meaning
that by the time we have sent the didChange notification successfully
the server must have started work on its behalf. This was inherently
racy, and too tricky to get right.

Additionally, a couple bugs are fixed:
 - EmptyDiagnostics is corrected to account for the case where we have
   received zero diagnostics for a given file.
 - A deadlock is fixed in Await when expectations are immediately met.

Updates golang/go#36879
Fixes golang/go#32149

Change-Id: I49ee011860351eed96a3b4f6795804b57a10dc60
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229777
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 20:46:32 +00:00
Rob Findley
9938a07982 internal/lsp: factor out progress reporting to a new WorkDone handle
Our current usage of WorkDone progress reporting (new in v3.15 of the
LSP spec) is in reporting progress on `go generate` commands. In
preparation for using this API more widely, factor out the reporting API
from the current io.WriteCloser wrapper (workDoneWriter).

Change-Id: Ib528093d81d4fc065528df90e100859e850b10df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229459
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 20:46:18 +00:00
Heschi Kreinick
e9a00ec821 internal/lsp/cache: correctly split env vars
We were using strings.Split on env vars, which did bad stuff when the
var contained an =, e.g. GOFLAGS=-tags=foo. Only split on the first =.

Irritatingly, this breaks only `go mod` commands, so almost nothing in
gopls failed, just organize imports and the `go.mod` code lens stuff.

Fixes golang/go#38669

Change-Id: I8d28c806b77a8df92100af1fa4fbcca5edf97cff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230560
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 18:55:08 +00:00
Ian Cottrell
006b16f6cf internal/lsp: share common command line test functionality
This moves the common code from the cmd and gopls tests to the shared cmdtest package, they were starting to drift apart.
This change was extracted from another larger cl where I was trying to work out why it broke in one but not the other.

Change-Id: I554ce364f4152e6b61f989da8162d968426d4ae5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230301
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 14:04:16 +00:00
Rob Findley
7ae4988eb4 internal/lsp/fake: clean up Workspace.proxydir on close
This change was unfortunately lost while rebasing, resulting in a lot of
unremoved directories.

Change-Id: Icc1b667e31ac85e617b1c3a8d7c58f78e999d151
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230314
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-28 02:10:58 +00:00
Rebecca Stambler
352a5409fa internal/lsp: handle different package names in signature help
There were a few cases where we were not properly qualifying package
names, particularly if the original package had a named import. Now,
we map between these names correctly - handling the case of multiple
packages that need to be qualified. This requires applying edits to
*ast.SelectorExprs, as well as *ast.Idents.

We still do not fully qualify unimported packages, and likely won't,
unless that's an issue for many users.

Updates golang/go#38591

Change-Id: I966a4d1f936f37ede89362d03da3ff98d8952a06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229979
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-27 20:59:12 +00:00
Rebecca Stambler
e56429333a internal/lsp/cmd: fix the command line query for definition
The definition command-line interface doesn't match the rest of the
commands, because I think we originally wanted to make them all
subcommands of "gopls query". Remove this, since it's no longer in use.

Change-Id: Iee923db6328774f787d539931001e438d1a2ae6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-27 20:15:23 +00:00
Rebecca Stambler
e0d5eebdf8 internal/lsp: fix docs on hover for ungrouped package variables
Fixes golang/go#38525

Change-Id: I8833c925663b67b2c82ad4cbf580d1c6f3c7a81d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230305
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-27 18:59:06 +00:00
Ian Cottrell
9ea0146da6 internal/jsonrpc2: remove jsonrpc2.ErrDisconnected
It was not very useful, it basically renamed io.EOF under some limited
circumstances, and was only there for the befit of tests.
Instead, the test now checks io.EOF directly, but also checks for
io.ErrClosedPipe which was also happening.
We also make sure we wrap errors rather than replacing them.
This prevents some weird random test failures due to races in the way they were
closed.

Change-Id: I236b03ac5ba16bf763299b95d882cf58b1f74776
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230303
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-27 16:39:59 +00:00
Ian Cottrell
a90b7300be internal/event: remove the event.eventType type
Instead of tagging events with their type, instead we infer the type from
the label pattern.
The standard event creators all have a matching test that returns true
if the the labels pattern matches the ones that would be built by the
creator.
Spans and logs already have a unique label pattern, other event types
required a special label marker.
This makes the system much more extensible, and also cleans up some
the API.

Change-Id: I1fbc9ec07aa84ead6c12bbd5ca65b13b605bfa4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229242
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-27 15:30:19 +00:00
Ian Cottrell
bed5418863 internal/event: don't print invalid labels
Change-Id: I781dfbd37aefe352c74d0df0af9da52bbf09fdcc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229989
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-27 14:36:10 +00:00
Rob Findley
479cc23432 internal/jsonrpc2: fix goroutine leak when listener is closed
When jsonrpc2.Serve times out or is cancelled, we leak the goroutine
that is accepting connections, because it is stuck trying to write its
error back to the doneListening channel.

Fix this by adding a context cancellation for the serve func, and
selecting on this context when writing the error.

Change-Id: I3383535f58b44616983816e8b257a975e3c337a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229978
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-04-27 12:55:06 +00:00
pjw
f3a5411a4c internal/lsp: fix panic when trying to log an event
Formatting keys in labels can panic when a label is constructed with a nil
error. Avoid that by not passing the defective label to event.Log.

Change-Id: I3099a7ac48c5830af1072141f2b619d0e0fbcf5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229985
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-04-26 10:28:38 +00:00
Muir Manders
8463f397d0 internal/lsp/source: fix false positive "..." in completions
In cases like:

    var v interface{}
    fmt.Println(<>)

Completing to "v" would insert "v..." instead of "v". This was due to
a mixup where we were checking if the variadic type "[]interface{}"
was assignable to the candidate type "interface{}" instead of the
other way around.

Fixes golang/go#38652.

Change-Id: I27c0b50bbf4b895924c8ed2c0c9dd6785e98cbe1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229921
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-25 04:34:58 +00:00
Rob Findley
3585060312 internal/lsp/source: add option for verbose work progress reporting
In order to experiment with adding more progress reporting to gopls, add
a new experimental configuration for verbose work done reporting.

Also, pass configuration in InitializationOptions when initializing the
editor.

Change-Id: Id2336790719d9c0b6d663997e1aef672aec43d28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229458
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-24 19:57:22 +00:00
Rebecca Stambler
59e73619c7 internal/lsp: correctly handle type aliases when formatting
This change improves our approach to handling type aliases. Previously,
we were not fully qualifying the names in the AST, making the code
inserted in completions incorrect at times. Now, we clone the relevant
AST expr and qualify it. We also add handling for the return values of a
function, instead of just the parameters.

Fixes golang/go#38230
Fixes golang/go#37283

Change-Id: Ib79f4636891c9b610ae848e9fa4dbae7c63db509
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229319
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-23 20:53:58 +00:00
Rob Findley
38a97e00a8 internal/lsp/regtest: track outstanding work using the progress API
In preparation for later changes, add support for tracking outstanding
work in the lsp regtests. This simply threads through progress
notifications and tracks their state in regtest.Env.state. A new
Expectation is added to assert that there is no outstanding work, but
this is as-yet unused.

A unit test is added for Env to check that we're handling work progress
reports correctly after Marshaling/Unmarshaling, since we're not yet
exercising this code path in actual regtests.

Change-Id: I104caf25cfd49340f13d086314f5aef2b8f3bd3b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229320
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-23 20:44:50 +00:00
Ian Cottrell
a466788a31 internal/event: change event.At to be a private field
This was the last piece of Event that was public, and it was only public to
allow mutation in tests.
Adding CloneEvent allows tests to create an updated copy rather than
update the event in place.

Change-Id: I2215d1eb0317063948ef0fac955fa768a209564d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229241
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-23 18:13:49 +00:00
Ian Cottrell
a82abb5396 internal/event: extract keys to their own package
Now key types can be implemented outside the package that holds labels or events, they should be.
This prevents the large list of types from poluting the public interface of the core packages.

Change-Id: I927f31cb5e4e1d0c29619681015962f890623e5c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229240
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-23 18:13:43 +00:00
Ian Cottrell
c81623a0cb internal/event: move event/core.Tag to event/label.Label
Also moves core.Key to label.Key, but leaves the implementations
behind for now.
After using for a while, the word Tag conveys slightly the wrong
concept, tagging implies the entire set of information, label maps
better to a single named piece of information.
A label is just a named key/value pair, it is not really tied to the
event package, separating it makes it much easier to understand the
public symbols of the event and core packages, and allows us to also
move the key implementations somewhere else, which otherwise dominate
the API.

Change-Id: I46275d531cec91e28af6ab1e74a2713505d52533
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229239
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-23 18:13:33 +00:00
Ian Cottrell
7b212d60a1 internal/event: renaming the main event API functions
event.Log removed
event.Print -> event.Log
event.Record -> event.Metric
event.StartSpan -> event.Start

In order to support this core now exposes the MakeEvent and Export functions.

Change-Id: Ic7550d88dbf400e32c419adbb61d1546c471841e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229238
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-23 17:21:36 +00:00
Ian Cottrell
cf0cb92717 internal/telemetry: renaming to internal/event
internal/telemetry/event was renamed to internal/event/core
Some things were partly moved from internal/telemetry/event straight to
internal/event to minimize churn in the following restructuring.

Change-Id: I8511241c68d2d05f64c52dbe04748086dd325158
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229237
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-23 17:20:48 +00:00
Rebecca Stambler
72e4a01eba internal/lsp: refactor code for formatting signatures
The code for formatting function signatures is fairly confusing.
Factoring out an unexported signature type simplifies things a bit.
Hopefully we'll be able to pull out more formatting logic from the other
features. Ideally, I'd like to return to the separation between
internal/lsp/source and internal/lsp so that a formatting package can be
pulled out and used in internal/lsp.

Change-Id: I7428db5004eab371e46402188e0dc6bb30f0c425
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229318
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-22 20:52:58 +00:00
Rob Findley
3d37a67796 internal/gocommand: clean up docstring typos and staticcheck errors
Fix a couple typos in the RunRaw docstring, as well as some superficial
staticcheck errors.

Change-Id: I557d7ee63366b2b3a82d590d69ee2907d4e3ac59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229417
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-22 17:07:37 +00:00
Rebecca Stambler
3d57cf2e72 internal/lsp: add regtest for golang/go#37984
This change also required the addition of a new run configuration -
WithEnv, which adds extra environment variables to the configuration.
Please let me know if this is the wrong approach.

Fixes golang/go#37984

Change-Id: Ied2a53a443dc74c7ed723b91765eeddc1a7c1c00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229128
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-22 02:23:33 +00:00
Rebecca Stambler
4e4aced336 internal/lsp/regtest: add regtest for golang/go#38207
Fixes golang/go#38207

Change-Id: I78396814a2e6a3ccecc860953ac6892ffa1b68e8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226960
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-22 01:51:11 +00:00
Rebecca Stambler
504fe87a53 internal/lsp: add regtest for golang/go#38211
A few more updates to the regtest framework - add support for all
codeActions, not just organize imports. Also, return diagnostics from
env.Await to pass into code actions. Not sure if that's the correct way
to do it, so please let me know if there's a better way.

The test is for 1.14 only, since -modfile is only supported after 1.14.

Fixes golang/go#38211

Change-Id: I5cdd35e2ec06e2b2487d1f3491197030008be9c9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226958
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-22 01:32:14 +00:00
Rebecca Stambler
66008de356 internal/lsp/regtest: add regtest for golang/go#36951
Not sure when this got fixed, but confirmed manually and via a
regression test.

Fixes golang/go#36951

Change-Id: I7833a5d1119c34fd3fb45ea658e954eadbee750c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229129
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-21 18:57:00 +00:00
Ian Cottrell
7504fd2219 internal/lsp: fix broken lsp logs
ID's are now by value not pointer, which caused it to not use the Format
method, resulting in broken id strings
The id maps need to be crossover (set and get go to different maps for a given direction of message)

Change-Id: Ide2b63ec1b009ae3587ee10e8bce018732ea342c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229244
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-04-21 17:00:05 +00:00
Rob Findley
26dd2a56eb internal/telemetry/export: guard against NPE when merging tag maps
In a separate CL, I was getting a nil pointer exception looking up a tag
value in a tag map chain where one map was nil. To avoid this, check
that maps are non-nil when merging them into a chain.

Change-Id: Ie2ec4865e1ed62f91b9b146d2f2b56f48c156043
Reviewed-on: https://go-review.googlesource.com/c/tools/+/229130
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-21 14:47:19 +00:00
Ian Cottrell
4b6a508a9c internal/lsp: merge the in and out protocol logging functions
The special cases were all removed by the previous changes to jsonrpc2 messages.
The only difference now is the "Recieved" vs "Sending" text prefix, so we just paramaterize the common function with that instead.

Change-Id: If6f8de39dca38041cf68a6b5506ff0482af3cb8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228890
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-21 13:43:21 +00:00
Ian Cottrell
2dc4334630 internal/jsonrpc2: rewrite streams in terms of messages
messages are the atomic unit of communication, changing streams
to read and write whole messages makes the code clearer.
It also avoids the confusion about what should be an atomic
operation or when a stream should flush.

Change-Id: I4b731c9518ad7c2be92fc92211c33f32d809f38b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228722
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-21 13:42:58 +00:00
Paul Jolly
cfa8b22178 go/packages/packagestest: do not walk packages and their test variants
Currently, where a package has a test variant, we end up walking the
non-_test.go files twice: once when walking the package itself, the
second time when walking the test variant. In the gopls tests, this
means we end up double-counting the number of symbols (via the @symbol
annotation) in a package.

Extend the existing expect_test.go to demonstrate the problem is fixed
(a test which fails when the fix is not in place)

Change-Id: Ifd68b3d86e24f19d3f8efc3af71494b7d28b0acb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228761
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-21 04:27:24 +00:00
Paul Jolly
b4d5569d26 internal/lsp/tests: provide SymbolInformation.Name in @symbol annotations
In preparation for a later change where we alter the implementation of
the workspace Symbol method, we now specify the Name that should be used
when constructing a SymbolInformation value from a @symbol annocation.
There is no change in the test expectations.

Change-Id: I4ee5f714d6060aab2ee33ef18339504f443cecdc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228757
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-21 04:22:56 +00:00
Ian Cottrell
9f075f7bfe internal/lsp: switch the protocol logger to use the new jsonrpc2 message types
This saves it from having to know the wire format and understand the decoding
tricks.

Change-Id: I1f3ef3345ffee736a9d104f8ebfb436404d737c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228721
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-20 21:06:19 +00:00
Ian Cottrell
434f7a8fef internal/jsonrpc2: add concrete types for Call, Notify and Response
The previous implementation was exposing the details of the wire format
and resulted in non idomatic go, detecting the presence of absence of
values in fields to deterimine the message type.
Now the messages are distinct types and we use type switches instead.
Request still exists as an interface to expose the shared behaviour of
Call and Notification, as this is the type accepted by handlers.
The set of messages is deliberately closed by using a private methods on the
interfaces.

Change-Id: I2cf15ee3923ef4688670c62896f81f760c77fe04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228719
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-20 21:05:32 +00:00
Ian Cottrell
98173f2f69 internal/jsonrpc2: clean up the tests
This runs the tests as sub tests, and makes sure they clean up
correctly.
It also installs the telemetry debug handlers.

Change-Id: I75b4f7a19be378603d97875fc31091be316949e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228718
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-20 21:05:12 +00:00
Ian Cottrell
f0ebba1556 internal/telemetry: add support for using telemetry in tests
For now this just logs to the testing.TB, it should be possible to also use it
to log metrics and timings in the future.
Also adds event.Debugf as a temporary debugging print to the telemetry
system, which is very helpful when debugging tests.

Change-Id: Ib2e919998919491e227885e2ee6eeea9e2fdc996
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228717
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-20 21:04:52 +00:00
smasher164
978e26b7c3 internal/imports: update stdlib index for 1.14
$ go run mkstdlib.go

Fixes golang/go#38464.

Change-Id: I97cbd0abf6b9d874739d236429aba8ef271c48ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228884
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-20 00:18:25 +00:00
Rebecca Stambler
c07e33ef32 internal/lsp/source: enable type error analyzers
I had intended to enable these after gopls/v0.4.0 was released so that
people who test at master can try these out. Also, mark "fillreturns" as
high confidence so users can get it applied on save, much like
goreturns.

Change-Id: I71aa0b723b2e9b69474ceed7cb1d7da7c929d65d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228724
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-17 14:00:56 +00:00
Rebecca Stambler
e33929705b internal/lsp/regtest: enable test for golang/go#37195
I believe that other changes in gopls/v0.4.0 also fixed the issue that
this regression test was written for. Re-enable it, and change it to
assert that diagnostics are cleared.

Fixes golang/go#37195

Change-Id: I4538186ad288d9c6f70cc450f948b62f3868941f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228723
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-17 14:00:42 +00:00
Hana (Hyang-Ah) Kim
fc959738d6 internal/lsp: fill in ServerInfo in the initialize response
Fixes golang/go#38459

Change-Id: I98476ddc35c4ab2c43145083149454875cb4b041
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228398
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-16 21:44:02 +00:00
Rob Findley
f038785680 internal/lsp/regtest: generalize expectations beyond diagnostic messages
Due to the asynchronous and non-transactional nature of the LSP, writing
regtests requires waiting for certain conditions to be met in the client
editor. To this point, the only type of condition for which we supported
waiting was the presence of diagnostic messages, but we can in principle
wait for anything that is triggered by a server notification.

This change generalizes the notion of expectations to also encompass log
messages. Doing this required expanding the value returned from checking
expectations to include a new "Unmeetable" verdict, to account for cases
where we know that a condition will never be met (for example if it is a
negative assertion). This may be useful for diagnostics as well.

A test is added to demonstrate these new expectations, where the initial
workspace load fails due to unfetchable dependencies.

Additionally, some helper flags are added to help debug regtests without
a code change, by allowing changing the test timeout, printing logs, and
printing goroutine profiles.

Updates golang/go#36879

Change-Id: I4cc194e10a4f181ad36a1a7abbb08ff41954b642
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228399
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-16 21:39:01 +00:00
Rob Findley
92fa1ff4b1 internal/lsp/regtest: add support for custom test proxy data
Certain regtests require referencing external data. To support this, add
the ability to use a file-based proxy populated with testdata.

To expose this configuration, augment the regtest runner with variadic
options. Also use this to replace the Runner.RunInMode function.

Add a simple regtest that uses this functionality.

Updates golang/go#36879

Change-Id: I7e6314430abcd127dbb7bca12574ef9935bf1f83
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228235
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-16 19:38:27 +00:00
Rob Findley
405595e0b5 internal/lsp/fake: be more careful when closing the workspace
Closing the workspace has frequently been failing on Windows, due to
file locks held by the go command.

This change makes several tests more careful to check errors when
closing resources, and defers closing the regtest workspaces until the
entire test suite completes, at which point it is much more likely that
closing the workspace will succeed.

If this change results in test flakes on Windows, we should temporarily
demote errors in regtest.Runner.Close to a t.Log.

Updates golang/go#38490

Change-Id: Ibd2f7dd0e0e2faecfa0ca8c60237fc72e64f6719
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228231
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-16 19:25:41 +00:00
Rebecca Stambler
5744cfde56 internal/lsp: fix imports issue with duplicate package decl
We shouldn't apply formatting fixes when we are
organizing imports.

Fixes golang/go#38412

Change-Id: I082f4d9a7d1d1dd571304733c287b0d5e90ea448
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228264
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-16 06:17:24 +00:00
Ian Cottrell
9c19d0db36 internal/telemetry: delete the unit package
It is not currently used at all, and is probably not the right approach.
Now we can easily add type safe keys we can add ones for types that know
their unit rather than storing it separately.

Change-Id: If393ad1df76033cff571c46f98cde8decb722b9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228265
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-16 04:05:50 +00:00
Ian Cottrell
18395615f2 internal/telemetry: pack strings efficiently into tags
TagOfString() deconstructs a string into length and data pointer using the
unsafe package, and then stores the length into Tag.packed and the pointer into
Tag.untyped, which it can do without allocations.
Tag.UnpackString can reconstruct a string on access also using the unsafe
package to rebuild the string header.

This makes tag significantly smaller, which in turn makes things a faster

name                old time/op    new time/op    delta
/Baseline-8            160ns ± 6%     158ns ± 8%     ~
/StdLog-8             7.50µs ± 8%    7.47µs ±20%     ~
/LogNoExporter-8      1.13µs ± 7%    1.04µs ± 2%   -8.08%
/TraceNoExporter-8    3.61µs ±15%    2.96µs ± 5%  -18.08%
/StatsNoExporter-8    1.65µs ± 7%    1.39µs ± 7%  -16.14%
/LogNoop-8            4.43µs ±14%    4.05µs ± 7%     ~
/TraceNoop-8          10.9µs ± 5%    10.1µs ± 8%     ~
/StatsNoop-8          8.08µs ± 3%    7.42µs ±13%     ~
/Log-8                16.2µs ±14%    13.4µs ± 3%  -17.10%
/Trace-8              61.7µs ±22%    53.6µs ± 7%     ~
/Stats-8              11.3µs ±10%     9.5µs ± 4%  -15.56%

name                old alloc/op   new alloc/op   delta
/Baseline-8            0.00B          0.00B          ~
/StdLog-8               552B ± 0%      552B ± 0%     ~
/LogNoExporter-8       0.00B          0.00B          ~
/TraceNoExporter-8    3.58kB ± 0%    2.82kB ± 0%  -21.43%
/StatsNoExporter-8     0.00B          0.00B          ~
/LogNoop-8            3.58kB ± 0%    2.82kB ± 0%  -21.43%
/TraceNoop-8          11.5kB ± 0%     9.2kB ± 0%  -20.00%
/StatsNoop-8          7.17kB ± 0%    5.63kB ± 0%  -21.43%
/Log-8                3.58kB ± 0%    2.82kB ± 0%  -21.43%
/Trace-8              27.9kB ± 0%    23.6kB ± 0%  -15.60%
/Stats-8              7.17kB ± 0%    5.63kB ± 0%  -21.43%

name                old allocs/op  new allocs/op  delta
/Baseline-8             0.00           0.00          ~
/StdLog-8               30.0 ± 0%      30.0 ± 0%     ~
/LogNoExporter-8        0.00           0.00          ~
/TraceNoExporter-8      16.0 ± 0%      16.0 ± 0%     ~
/StatsNoExporter-8      0.00           0.00          ~
/LogNoop-8              16.0 ± 0%      16.0 ± 0%     ~
/TraceNoop-8            64.0 ± 0%      64.0 ± 0%     ~
/StatsNoop-8            32.0 ± 0%      32.0 ± 0%     ~
/Log-8                  16.0 ± 0%      16.0 ± 0%     ~
/Trace-8                 384 ± 0%       384 ± 0%     ~
/Stats-8                32.0 ± 0%      32.0 ± 0%     ~

Change-Id: If5c369f138b60435f1aa74120aa3c1b68baae402
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228234
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-16 04:05:44 +00:00
Ian Cottrell
be55493b88 internal/telemetry: add tag value formatting to the Key
This means that format functions don't need an exhaustive list of the
key types to work correctly.

Change-Id: Iee17b225a0ecf82eb3f50d6341baf677655efc0d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228233
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-16 04:05:32 +00:00
Ian Cottrell
bd061c738e internal/telemetry: expose the TagOf* and Unpack* methods
These allow tags to be constructed and used from outside
the event package.
This makes it easy for users of these APIs to write their own
implementations of Key.

Change-Id: Ic3320a80f297bbe1d4cd6d9beafbe13ebbace398
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228232
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-16 04:05:21 +00:00
Rebecca Stambler
5d8e1897c7 internal/lsp: fix erroneous documentation for struct fields
The fix is just a missing return.
Also clean up a staticcheck thing, regenerate the golden files.

Fixes golang/go#38417

Change-Id: I290b63df9d97211c59d6399fda7a273bc700fbdb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228297
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-15 03:45:06 +00:00
Ian Cottrell
33e937220d internal/jsonrpc2: simplify request even futher
It does not need to expose wire level fields, especially not by embedding.
It also no longer needs to know what Conn it came from.

Change-Id: I1aede2baaa2daa40da4e7a1278b2eaada25b2310
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227919
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-04-14 21:18:25 +00:00
Ian Cottrell
ce2627f346 internal/jsonrpc2: remove the OnReply callbacks
The same behavior can now be achieved by wrapping the Replier as we traverse the
handler stack instead.
Request is no longer mutated during handler invocation.

Change-Id: I2213de500f39e048f3f80161e234f3ae30464d70
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227918
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-14 21:18:03 +00:00
Rob Findley
6a72e3782c internal/lsp/fake: don't lock while calling formatting
While trying to be pragmatic, I simply locked the fake.Editor while
calling textDocument/formatting. This did indeed manifest later on as a
deadlock, so instead we release the lock but fail if the buffer version
changes while awaiting the formatting call.

Change-Id: I0ca24a502f3118e76de306a016449bbe665e70e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228230
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-14 20:55:25 +00:00
Rob Findley
3bb7580c69 internal/lsp/fake: correctly configure the fake editor
Configuration was not being set correctly, because the configuration
response was not honoring the configuration section order.

Change-Id: I8418535b45e6a24fd8f0605d58cb370e22664f17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228257
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-14 20:27:33 +00:00
Rob Findley
912958979a internal/lsp/regtest: put testing.T back in the test func signature
In https://golang.org/cl/225157, I removed the redundant T and Context
parameters from the regtest func signature in an effort to reduce
confusion. In hindsight, removing the testing.T did not reduce
confusion, because there is a T in the test signature anyway (and now
it's the wrong T!).

Change-Id: I2e84009e9cb33cd51055012cfef9fe4987e1b9bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228229
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-14 18:42:46 +00:00
Yasuhiro Matsumoto
0037cb7812 all: Fix spelling of Marshaling.
The single "l" form is used throughout the adjacent tools package
and the Go standard library.

Change-Id: I88c3530ef9d3b1354895d342e39403fa20ccd4d1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228237
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-04-14 13:15:30 +00:00
Rob Findley
a4a177c7d7 internal/lsp/diff/difftest: ignore for GOOS=illumos
illumos has a different copy of the `diff` executable, causing this test
to fail. Ignore it for this GOOS.

Updates golang/go#38414

Change-Id: I45ec5fcd9fd332977349bb6ba33d9ed09417a023
Reviewed-on: https://go-review.googlesource.com/c/tools/+/228199
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-14 02:36:50 +00:00
Rob Findley
07bb9fb2f9 internal/proxydir: add an internal package for file-based proxies
Both packagestest and the gopls regtests need to write module data to
the filesystem in proxy structure. Since this seems like a common and
self-contained concerned, factor this out into a shared package.

Change-Id: I5275dbc0cd7b13290061e8bb559d6dd287fbb275
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227841
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-13 22:35:07 +00:00
Ian Cottrell
1f08ef6002 internal/jsonrpc2: split reply from request
reply is now passed to handlers separately from request, which allows it to be
substituted by handlers.
This also makes the handler signature much closer to http (which has
ResponseWriter)

Change-Id: I12be2e8e8b9bd508982ba43c9092709429284eaf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227839
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-13 01:58:12 +00:00
Ian Cottrell
b854406a88 internal/jsonrpc2: make the wire structures private
The wire structures do not need to be public, and making them so might make it
harder to keep the package correct without breaking changes if the protocol
changes in the future.

Change-Id: I03a5618c63c9f7691183d4285f88a177ccdd3b35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227838
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-13 01:57:29 +00:00
Ian Cottrell
2595e72532 internal/jsonrpc2: replace NewErrorf with fmt.Errorf
We utilize error wrapping to recover the error codes when needed.
The code constants are also replaced by fully declared errors with
human readable messages.

Change-Id: I8edeb05f5028e99966e4ca28151f644f008d4e7d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227837
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-13 01:57:14 +00:00
Rebecca Stambler
79a7a3126e internal/lsp: add an extra bounds check to avoid nil pointers
A nil pointer was reported to the golang-tools group (see
https://groups.google.com/g/golang-tools/c/JrNTz8I6ifo/m/tcJRpek-AAAJ).
I think this bounds check should address it.

Updates golang/go#34433

Change-Id: I87352c269c65c844c86ebe9ee3fd2d041cc49ee9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227770
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-10 19:49:07 +00:00
Ian Cottrell
ae9902aceb internal/lsp: remove the CallCanceller
This required changing the jsonrpc.Conn.Call signature to also return the
request ID so it can be cancelled.
The protocol package now declares the Call function which wrapps up
Conn.Call and then sends a cancel message if the context was
cancelled during the call.
There is a small chance that a context can be cancelled on a
request that has already completed, but it is safe to do so.

Change-Id: Ic8040c193e1dd4ef376ad21194b1d0ea82145976
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227558
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-10 13:26:12 +00:00
Ian Cottrell
c92aeb7438 internal/lsp: improve ID formatting
Replace the String method with a Format method so we can use it for extra
formats.
Add some tests to make sure it is all correct

Change-Id: I39f361ffba036fad99c93f8c0944164f7cf199ec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227486
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-10 13:25:36 +00:00
Rebecca Stambler
3bd20875a2 internal/lsp/cache: hide type errors if we fix up the AST
I was curious about why were logging errors during type-checking in
tests, and the answer turned out to be a bit more sinister than I
expected. We were getting type error messages without filepaths, so I
tried to reproduce it in the playground and wasn't able to. I realized
that these errors were coming from were coming from the "fixed" version
of the AST that we pass to the type checker.

Adding fake positions to our fake Cond statements trivially fixes the
logging issue, but it does nothing to handle the fact that the error
makes no sense to the user - because it applies to something that's not
in the source code. I figured we have two options: (1) skip type errors
for all packages with "fixed" ASTs, or (2) add something to the error
messages to indicate that the source code may not match. Starting with
(1) here, and if it becomes a problem, we can move to 2. All ASTs that
we fix have *ast.BadExpr in them, meaning that, by definition they have
parse errors which we will preferentially show those errors to users in
diagnostics (so I'm not sure how to test this).

Change-Id: I17733968aa15f989cdd3e4e7261c4f4fe9b97495
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227557
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-10 04:07:51 +00:00
Rebecca Stambler
c08edad6b3 internal/lsp: linkify IP addresses in textDocument/documentLink
Found golang/go#18824, which helped me understand what to do to fix this
issue. Also, changed some of the structure of the code to propagate
errors up to the top-level functions. I think this will help us deal
with actual errors vs. ignorable errors.

Didn't add tests because of golang/go#35880. Just prioritized that issue
for gopls/v0.5.0 - it's been biting us a lot lately.

Fixes golang/go#38285

Change-Id: I6962462818becb1bcedde4a5be3a2060e71c9389
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227559
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-10 03:56:59 +00:00
pjw
700752c244 internal/lsp/regtest: add test for issue 32149 (wrong package)
Gopls gets confused about the package if the package name is edited.
(See golang.org/issues/32149) This skipped test will succeed as long
as the bug is present.

Change-Id: Ic99ceda133f92f306baf94e2f8ad0381ed565814
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227760
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-09 21:04:53 +00:00
Rob Findley
bc09a2cac9 internal/lsp/regtest: output gopls logs on test failure
Wrap the regtest test servers to capture jsonrpc2 logs, so that they can
be printed on test failure.

There was a little bit of complication to implement this in the 'Shared'
execution mode, and since we're not really using this mode I just
deleted it.

Updates golang/go#36897
Updates golang/go#37318

Change-Id: Ic0107c3f317850ae3beb760fc94ae474e647cb78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226957
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-04-09 19:58:30 +00:00
Rob Findley
97c4fbe514 internal/lsp/protocol: make loggingStream log writes concurrency-safe
Per the documentation for jsonrpc2.Stream Write must be safe for
concurrent use, but this isn't the case for the loggingStream.

Guard it with a mutex.

Change-Id: I384892b90cef950d518089421d05cf8040c6b233
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227487
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-04-09 19:31:31 +00:00
Ian Cottrell
9ee5ef7a2c internal/jsonrpc2: remove Direction
It is no longer used after the changes to the logging system.

Change-Id: I7b96fb8297eb66f2ebad67c74c82fa7ed96c3139
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227485
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-08 13:21:56 +00:00
Ian Cottrell
888a00fb34 internal/telemetry: a faster logging exporter
Moved printing directly inside the exporter,
which yields a massive reduction in allocations.

name                old time/op    new time/op    delta
/Log-8                41.7µs ± 1%    13.6µs ± 2%  -67.48%

name                old alloc/op   new alloc/op   delta
/Log-8                20.9kB ± 0%     3.6kB ± 0%  -82.86%

name                old allocs/op  new allocs/op  delta
/Log-8                   286 ± 0%        16 ± 0%  -94.41%

Change-Id: Ieafd644683d98d24978c8be061e6632dd8ef113e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227302
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-08 13:21:36 +00:00
Ian Cottrell
6a75126720 internal/lsp: make tag iteration allocation-free
Change the tag iteration api to something less flexible
that allows for event iteration without allocation.

Change-Id: I212d45ebceea0183d1a61e6b611e0558649be60a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227301
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-08 13:20:38 +00:00
Rohan Challa
46bd65c853 internal/lsp/cache: add concurrency error check for go cmds
This change attempts to fix a concurrency error that would cause
textDocument/CodeLens, textDocument/Formatting, textDocument/DocumentLink,
and textDocument/Hover from failing on go.mod files.

The issue was that the go command would return a potential concurrency
error since the ModHandle and the ModTidyHandle are both using the
temporary go.mod file.

Updates golang/go#37824

Change-Id: I6cd63c1f75817c7308e033aec473966536a2a3bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224917
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-08 03:22:09 +00:00
Rebecca Stambler
4d14fc9c00 internal/lsp: add type error fixes to existing diagnostics
This change is the first step in handling golang/go#38136. Instead of
creating multiple diagnostic reports for type error analyzers, we add
suggested fixes to the existing reports. To match the analyzers for
FindAnalysisError, we add an ErrorMatch function to source.Analyzer.

This is not an ideal solution, but it was the best one I could come up
with without modifying the go/analysis API. analysisinternal could be
used for this purpose, but it seemed to complicated to be worth it, and
this is fairly simple. I think that go/analysis itself might need to be
extended for type error analyzers, but these temporary measures will
help us understand the kinds of features we need for type error
analyzers.

A follow-up CL might be to not add reports for type error analyzers
until the end of source.Diagnostic, which would remove the need for the
look-up.

Fixes golang/go#38136

Change-Id: I25bc6396b09d49facecd918bf5591d2d5bdf1b3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-08 01:45:16 +00:00
Rebecca Stambler
a3568bac92 internal/lsp: disable unimported completions for snippet tests
Turns out that these were already disabled in the
golang.org/x/tools/internal/lsp tests, which is why we only ever save
the failures in golang.org/x/tools/internal/lsp/source tests. Discussing
the reasons that this is necessary on the issue, but I think completion
scoring in general needs to be centralized and documented, so hopefully
we can handle this case as part of that larger fix.

Fixes golang/go#38269

Change-Id: Ie1b615315e417ab8211a3580cf8f27cbdc3b74e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227417
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-07 14:37:52 +00:00
Hana (Hyang-Ah) Kim
066fd1390e internal/telemetry/event: fix error/value key type tag formatting
%v behaves better with nil values.

Change-Id: I4041f5460173c8f420553996d64d9463ef5a0370
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227355
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 21:38:09 +00:00
Rebecca Stambler
1fd976651f internal/lsp: make sure that gofmt -s analyses don't modify AST
The code for `gofmt -s` directly modifies the AST, since the ASTs are
not long-lived. Some of this code made it into our analysis
implementations, causing very strange bugs to manifest. Added a
regression test for this specific case.

Fixes golang/go#38267

Change-Id: I235620adcbf2bbc7027c6d83ff2c7fe74729062e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-06 21:01:14 +00:00
Ian Cottrell
903869a827 internal/lsp: make event directly implement TagMap
Makes Event implement TagMap directly, instead of
having to build an entirely new object.

Change-Id: I0c1e8638de3dc3347f60fd93af3df6b7f8387751
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227300
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-06 17:24:01 +00:00
Ian Cottrell
ff0df58207 internal/telemetry: add an example of using the logging behaviour
And also fix that the output was not actually correct!

Change-Id: If81e22e586b1c2a71c69843b49d5dd8d5d2dfde6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227298
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-06 17:23:38 +00:00
Rebecca Stambler
ee2abff5cf internal/lsp: use one context throughout completion
I originally made this change to see if it would help with the timeouts.
Based on the TryBot results, it doesn't -- but I still think it's more
correct to have the contexts this way. It was my mistake to put the
context on the completer in the first place, I think.

Change-Id: Ib77c8f0ac0b0d0922b82db4120820fb96cb664f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227303
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-06 16:51:37 +00:00
Ian Cottrell
7db14c95bf internal/lsp: rewrite the rpc debug page
Now it only uses the telemetry messages directly rather than the metric system.
This is much faster and more direct, and removes a blocker on improving the
metrics support.
Also fixes the fact that recieced and sent were the wrong way round before,
probably as an artifact of the old protocol logging code, and also removes
the bytes histogram which was a lie (it was a histogram of write sizes that
was presented as a histogram of message sizes)

fixes golang/go#38168

Change-Id: Ib1c3459c0ff1cf0c6087a828981e80c1ce1c5c1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227139
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 14:44:18 +00:00
Ian Cottrell
ccaaa5c26f internal/jsonrpc2: dont add any handlers by default
This pushes the handler construction out to the user, allowing flexability of
use, and is the final stage of the switch to the new handler API.

Change-Id: Id2e61813a817df0d6e4d20dd47ce8c92b0ae87db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227024
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 14:44:07 +00:00
Ian Cottrell
17cc17e0bb internal/jsonrpc2: remove the legacy interface
We can do cancelling at the top level handler now, it can drop the cancel
messages themselves before they enter the queue stage, and also track
all the events as they flow through it.
The ugly part is the OnCancelled interface, which is a bit clunky.

Change-Id: I3fa972198625fb3517fdecc740d1a3fdb19a188a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226959
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 14:43:58 +00:00
Ian Cottrell
3eebf4bf9d internal/jsonrpc2: break Run up into composable handlers
Change-Id: I9aff86f7ab06e61849495b9c73553147e29343f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226840
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 14:43:41 +00:00
Ian Cottrell
5c4bdbc02c internal/jsonrpc2: remove request state
This removes the state machine from the request.
It adds a done handler and uses that to manage the unlock channel instead
This also allows us to remove the nextRequest channel from request.
This is the last major piece that allows us to split up the run method into
composable handlers.

Change-Id: I5517ed5a51e30534754522a58453c27b5178ffa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226839
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 14:40:45 +00:00
Ian Cottrell
44c82bac18 internal/jsonrpc2: make it an error to fail to call Reply
It is now a programatic error to have a handler registered to a connection that
does not call reply for all messages, including notifications.
This normalizes the flow making the code easier to understand  and fixes a
couple of long standing hard to find bugs.

Change-Id: If41c39ece70e3bc64420abefac75ec647a8f8b37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226838
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 13:49:19 +00:00
Ian Cottrell
7e0acf58eb internal/jsonrpc2: cleanup reply handling
Instead of having a Parallel method, we only have Reply, which must also be used
for Notify messages (with a nil response).
This has no real functional impact but makes it easier to refactor in the next
cl.

Change-Id: Ifd4316dd71706de7913c69e6be539b966800e9dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226837
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 13:49:09 +00:00
Ian Cottrell
6dc6d5718f internal/jsonrpc2: change handler to a function type
Handler is now a function type that mapps to what used to be the Deliver method.
The only handler that used other methods was Canceller, for now that still
exists as LegacyHooks. Once the handlers are fully cleaned up we should be able
to re-implement canceller as handler middleware.
Each connection is now only allowed one handler, and it is passed to the Run
method, but handlers are composable.

Change-Id: I370e0459df851bb9c9c2a679b99cff073b94489e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226479
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-06 13:48:45 +00:00
Rebecca Stambler
44a64ad78b internal/lsp, go/packages: don't log context cancellation errors
Instead of checking the context, check the error. This may expose some
errors that are not wrapped correctly. Replaced all uses of errors
with golang.org/x/xerrors.

Change-Id: Ia40160f8ea352e02618765f2a9415a4ece0dcd94
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227036
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-04-03 19:08:13 +00:00
Rebecca Stambler
bcf690261a internal/lsp: use context with timeout in all RunProcessEnvFuncs
The modifications in CL 226559 introduced a new call to
RunProcessEnvFunc that was not using the context with a timeout, so deep
completion tests were hitting the timeout early (I think?).

Also, fix a staticcheck warning that's been bugging me today.

Change-Id: Iac894f630ebfa1cbc5588ae3a5490a93fa53aba2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227057
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-02 22:33:21 +00:00
Rob Findley
8cb32c4661 internal/lsp/regtest: clean up module names and include github issues
A couple small improvements for regtests:
 - module names fixed to include a '.'. This was fixed for diagnostic
   tests already.
 - For regtests that were written to exercise specifig github issues,
   include the issue number in the test name.

Change-Id: I67da6d78dc166e854d2543cf63dac382202f9dbc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226844
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-02 21:48:35 +00:00
Rebecca Stambler
226fa68e9d internal/lsp: fix references for transitive dependencies
We need to search all transitive dependencies of a package, not just its
immediate imports.

Fixes golang/go#38100

Change-Id: I15b4dbe226ba851691ca0c95460c3648ede32f04
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227030
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-04-02 20:53:30 +00:00
Rebecca Stambler
72cf467e29 internal/lsp: handle non-file:// URIs gracefully
Rather than panicking, we should fail to initialize the server.
Context: https://github.com/microsoft/vscode-go/issues/3081
Change-Id: Ic4622d435dffb77b72dc1e0214f0a1d181a6f767
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227032
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-04-02 20:53:07 +00:00
Rob Findley
8f5be0d382 internal/lsp/regtest: add functions to make diagnostic assertions easier
One of the tricky things about asserting on conditions in regtests is
the asynchronous nature of LSP. For example, as the LSP client we cannot
be sure when we've received all diagnostics for a given file.

Currently, regtests are implemented by awaiting specific diagnostic
expectations.  This means that if gopls generates diagnostics that do
not match those expectations, we can only time out the test.

Ideally, we would want to know that gopls is done generating all diagnostics
for the current file state. This is not possible without knowing the
status of diagnostics for. Barring this, we would want to know that
diagnostics are done for the current file version. Unfortunately, that
also is not possible, because a new version of file B can affect
diagnostics in file A.

So in lieu of this information, this CL exposes a few tools that can be
used to improve the experience of writing new regtests.

 - A new expectation is added: AnyDiagnosticAtCurrentVersion, that is
   satisfied if any diagnostics have been received for the current
   buffer version.
 - ExpectDiagnostics is added to Env, to help check whether the current
   diagnostics matches expectations.

Updates golang/go#38113

Change-Id: I48d2c3db87c13ac3ab424d01d9444cbc285af9e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226842
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-02 20:10:23 +00:00
Rebecca Stambler
9fc00b0a7f internal/lsp: fix panic in builtin completions
Fixes golang/go#38091

Change-Id: I88ac6d3413de3dd9d235e2f2fca9b4a3f7127e0a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227026
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-02 17:53:26 +00:00
Heschi Kreinick
0a46fa39b0 internal/lsp/source: propose loaded unimported package names first
When proposing unimported package members, we start with packages loaded
in-memory first, for three reasons: we know that they're fast, they're
fully typed, and they're probably pretty relevant. I hadn't bothered
doing that for package names, because the first two reasons aren't very
relevant. But the third still is -- loaded packages are a pretty good
approximation for in module scope, etc.

With this change we do package names the same as members, so relevance
should be about as good. Not perfect, but nobody's complained much yet.

Fair bit of copy-and-paste, but I don't want to extend the
getAllCandidates abstraction outside of the imports package yet.

Updates #38104.

Change-Id: Ia479181607dff898baee3cd6aa84d1ab61715d19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226559
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-02 17:48:25 +00:00
Rebecca Stambler
3304cfb00f internal/lsp: temporarily disable type error analyzers by default
If we release gopls/v0.4.0 soon, we should keep these new analyzers off
by default. They were just merged, so they haven't been used enough to
be enabled, I think. We'll turn them on by default for gopls/v0.5.0.

Also, ended up creating a helper function to check if analysis has been
abled (which fixed a small bug in FindAnalysisError), and another helper
function to enable all analyses for testing purposes.

Updates golang/go#38212

Change-Id: I5ee94b3582dfc0863978650fc6ce51bfa0606c13
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226962
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-04-02 16:54:32 +00:00
Rebecca Stambler
2d9ba733ec internal/lsp: add a mutex around the view's options
The options can be modified without the view being recreated, so we need
a mutex there.

Change-Id: I87e881835622a941fce98e4a1062aa41acd84fcb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/227022
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2020-04-02 16:41:49 +00:00
Rebecca Stambler
69646383af internal/lsp/source: add a replacement for experimentalDisabledAnalyses
Change-Id: I5bff1db1d937ffdcb8bb4e36f05073238fbdeb5f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226961
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-04-02 14:48:50 +00:00
Rohan Challa
099440627f internal/lsp: add goreturns like functionality as quickfix
This change ports the functionality of https://github.com/sqs/goreturns
to be used as code actions on diagnostics that have missing
return values. It improves on the original goreturns functionality by:

- filling out empty return statements
- trying to match existing return values to the required return
  values and then filling in missing parameters

Fixes golang/go#37091

Change-Id: Ifaf9bf571c3bc3c61e672b0a2f725d8d734d432d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224960
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-04-01 19:27:44 +00:00
Rebecca Stambler
9d5940d493 internal/lsp: refactor and propagate errors from code actions
This change makes sure that all errors in code actions are returned,
instead of ignored. There is also a refactoring of the suggested fixes
for go.mod files so that we don't compute them unless there is already a
matching diagnostic.

Change-Id: I34afda0116f3cc7e47809d980a0171487787e55e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221221
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-31 20:20:46 +00:00
Rebecca Stambler
e18c1c42de internal/lsp: add a reg test to test "go mod init"
This change adds a RunGoCommand function to the workspace, which will
allow us to test how gopls responds when a certain go command is
executed. Add a test that checks behavior after "go mod init" runs.

Change-Id: I679249c1654b136d44187397b4196b8a10b5615e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226478
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-31 02:48:52 +00:00
Rebecca Stambler
a7c0594f4e internal/lsp: avoid logging context cancellation
This change adds a helper function that checks if the context is
canceled, and if so, doesn't log the error. Tried to use it everywhere
in internal/lsp where it fits, which resulted in changing a few pieces
of error handling throughout.

Updates golang/go#37875

Change-Id: I59cbc6f893e3b70cf84524d9944ff7f4b4febd78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226371
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-03-31 01:46:33 +00:00
Ian Cottrell
a42d6a358d internal/telemetry: give Event a custom implementation of TagMap
This cuts the allocation cost of preparing an event for export from 4 down to 1.

name                old time/op    new time/op    delta
/LogIgnore-8          5.97µs ± 6%    4.18µs ± 4%  -29.87%  (p=0.000 n=20+19)
/TraceIgnore-8        13.6µs ± 4%    10.8µs ± 6%  -20.92%  (p=0.000 n=18+19)
/StatsIgnore-8        11.3µs ± 6%     7.9µs ± 6%  -30.29%  (p=0.000 n=20+20)
/Log-8                47.8µs ± 6%    43.9µs ± 6%   -8.15%  (p=0.000 n=20+19)
/Trace-8              60.5µs ±12%    54.7µs ± 4%   -9.58%  (p=0.000 n=20+19)
/Stats-8              13.8µs ± 3%    10.6µs ± 5%  -23.57%  (p=0.000 n=20+19)

name                old alloc/op   new alloc/op   delta
/LogIgnore-8          5.12kB ± 0%    3.58kB ± 0%  -30.00%  (p=0.000 n=20+20)
/TraceIgnore-8        14.6kB ± 0%    11.5kB ± 0%  -21.05%  (p=0.000 n=20+20)
/StatsIgnore-8        10.2kB ± 0%     7.2kB ± 0%  -30.00%  (p=0.000 n=20+20)
/Log-8                24.0kB ± 0%    20.9kB ± 0%  -12.81%  (p=0.000 n=18+20)
/Trace-8              31.0kB ± 0%    27.9kB ± 0%   -9.92%  (p=0.000 n=20+20)
/Stats-8              10.2kB ± 0%     7.2kB ± 0%  -30.00%  (p=0.000 n=20+20)

name                old allocs/op  new allocs/op  delta
/LogIgnore-8            64.0 ± 0%      16.0 ± 0%  -75.00%  (p=0.000 n=20+20)
/TraceIgnore-8           160 ± 0%        64 ± 0%  -60.00%  (p=0.000 n=20+20)
/StatsIgnore-8           128 ± 0%        32 ± 0%  -75.00%  (p=0.000 n=20+20)
/Log-8                   382 ± 0%       286 ± 0%  -25.13%  (p=0.000 n=20+20)
/Trace-8                 480 ± 0%       384 ± 0%  -20.00%  (p=0.000 n=20+20)
/Stats-8                 128 ± 0%        32 ± 0%  -75.00%  (p=0.000 n=20+20)

Change-Id: I76ff4ac9658b766daf3929e7cfc0d2cfcab036ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226359
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-31 00:51:03 +00:00
Ian Cottrell
3b4a2bfdc9 internal/telemetry: removing the IsEmpty method of TagMap
It is not being used, and implementing it efficiently is infeasible without
reducing the efficiency of cases that matter more.

Change-Id: Ie53250f0e63ad08a418724c60a74a52edbdfdb29
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226358
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-31 00:50:56 +00:00
Ian Cottrell
4edcf52965 internal/telemetry: add a noop exporter benchmark
This has the exporter registered but doing nothing, to measure the basic cost of
having any exporter without any specific exporter costs.
Specifically at the moment this measures the cost of filling in the time on the
event and building the TagMap that is passed down.

Change-Id: Iaae5659e3de9b871dc281c509fa2ee9c3e1d049a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226357
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-31 00:50:42 +00:00
Ian Cottrell
80f63e2b9b internal/lsp: rewrite the stats using the newer telemetry features
This allows us to reduce the handler interface and delete the telemetry handler.
It is also safer and faster, and can be easily disabled along with the rest of
the telemetry system.

Change-Id: Ia4961d7f2e374f7dc22360d6a4020a065bfeae6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225957
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-31 00:50:33 +00:00
Ian Cottrell
657a652153 internal/telemetry: add a synchronization to telemetry
Some things that used to be safe due to the global
lock now need ther own synchronization primitives.

Fixes golang/go#38102

Change-Id: I03c692682d57620d96fe84b7dc74efae0d3f8f09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226317
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-30 19:15:27 +00:00
Rebecca Stambler
f8bfb4ee30 internal/gocommand: fix environment on Windows
Seems like os.Environ() is necessary after all. My bad for not testing
my earlier change on Windows. I'm not able to reproduce the behavior
in my test, so it's not really testing the crash correctly.

Fixes golang/go#38062

Change-Id: Ied45bbf572023a9dcd5d020db49bf3e95c824602
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226370
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-30 18:31:14 +00:00
Rohan Challa
31583a0dbb internal/lsp/tests: remove ellipses from test names
This change makes working with tests easier by trimming the folder name
up to "testdata". This will remove any ellipses from the test folder name.

Fixes golang/go#38103

Change-Id: I33b931e527de63713b8fc370c50b1c382796b2b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226377
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-30 17:55:17 +00:00
Rebecca Stambler
9c79f685b7 internal/lsp: fix view rebuilding when go mod init runs
https://github.com/microsoft/vscode-go/issues/3076#issuecomment-605062933
inspired me to write a regression test for this case. Turns out we
weren't handling it correctly after all...

This change makes sure that we only rebuild the view once a new go.mod
file is saved, not just created. It also preserves the snapshot ID
number when the view is recreated so that diagnostic caching continues
to work as expected.

Change-Id: I63bd559c3bd33b91828171cd7ddb3d099c31cddb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226017
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-30 17:42:33 +00:00
Ian Cottrell
fd4102a86c internal/telemetry: minor improvement to span events
This changes span events to return a cheaper end function if there is
no exporter and also to deliver the end event to the same exporter
that the start even was delivered to rather than which was active
when the end event is triggered.

Change-Id: I831283da20e8cc991a0cf7490952ae194d125428
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225737
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-29 02:58:19 +00:00
Ian Cottrell
36db529775 internal/telemetry: add fast non variadic event functions
This adds variants of the main event functions that take specific
numbers of tags, rather than a tag slice. This reduces the allocation
cost when using those functions with no exporter to zero.

name                old time/op    new time/op    delta
/Baseline-8            158ns ± 7%     154ns ± 1%      ~
/StdLog-8             6.90µs ± 1%    6.83µs ± 1%      ~
/LogNoExporter-8      1.78µs ± 5%    1.20µs ± 3%   -32.37%
/TraceNoExporter-8    3.11µs ± 3%    2.48µs ± 2%   -20.39%
/StatsNoExporter-8    3.18µs ± 5%    1.87µs ± 3%   -41.16%
/Log-8                46.8µs ± 2%    44.8µs ± 1%    -4.33%
/Trace-8              55.1µs ± 5%    54.3µs ± 3%      ~
/Stats-8              15.8µs ± 3%    13.4µs ± 1%   -15.00%

name                old alloc/op   new alloc/op   delta
/Baseline-8            0.00B          0.00B           ~
/StdLog-8               552B ± 0%      552B ± 0%      ~
/LogNoExporter-8      1.02kB ± 0%    0.00kB       -100.00%
/TraceNoExporter-8    1.54kB ± 0%    0.51kB ± 0%   -66.67%
/StatsNoExporter-8    2.05kB ± 0%    0.00kB       -100.00%
/Log-8                26.0kB ± 0%    24.0kB ± 0%    -7.87%
/Trace-8              28.7kB ± 0%    27.1kB ± 0%      ~
/Stats-8              13.3kB ± 0%    10.2kB ± 0%   -23.08%

name                old allocs/op  new allocs/op  delta
/Baseline-8             0.00           0.00           ~
/StdLog-8               30.0 ± 0%      30.0 ± 0%      ~
/LogNoExporter-8        16.0 ± 0%       0.0       -100.00%
/TraceNoExporter-8      32.0 ± 0%      16.0 ± 0%   -50.00%
/StatsNoExporter-8      32.0 ± 0%       0.0       -100.00%
/Log-8                   430 ± 0%       382 ± 0%   -11.16%
/Trace-8                 496 ± 0%       464 ± 0%    -6.45%
/Stats-8                 192 ± 0%       128 ± 0%   -33.33%

Change-Id: I629c0d506ab07de6f12b0acbecfc7407f59a4285
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225580
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-29 02:57:12 +00:00
Ian Cottrell
f61d083d3b internal/telemetry: use tags instead of special event fields.
Change-Id: I0e6a26c62bd1f6eaa07c38a06152cb7a0f2eedc2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225579
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-29 02:56:35 +00:00
Ian Cottrell
f8bbb56955 internal/telemetry: change tag to use type specific storage
Because packing values into interface{} causes allocations
this gives us a major improvement on allocation count, but
tag is bigger so a significant loss on bytes allocated.
It is a minor performance win overall, especially in the
null exporter case when it really matters the most.

name                old time/op    new time/op    delta
/Baseline-8            147ns ± 3%     146ns ± 3%     ~     (p=0.349 n=5+5)
/StdLog-8             6.83µs ± 1%    6.78µs ± 2%     ~     (p=0.548 n=5+5)
/LogNoExporter-8      1.15µs ± 1%    1.05µs ± 1%   -8.63%  (p=0.008 n=5+5)
/TraceNoExporter-8    1.01µs ± 4%    0.99µs ± 1%     ~     (p=0.087 n=5+5)
/StatsNoExporter-8    1.89µs ± 0%    1.95µs ± 3%   +3.27%  (p=0.016 n=4+5)
/Log-8                23.7µs ± 1%    24.4µs ± 6%   +3.14%  (p=0.032 n=5+5)
/Trace-8              42.2µs ± 1%    42.2µs ± 1%     ~     (p=0.841 n=5+5)
/Stats-8              7.37µs ± 3%    7.10µs ± 1%   -3.74%  (p=0.008 n=5+5)

name                old alloc/op   new alloc/op   delta
/Baseline-8            0.00B          0.00B          ~     (all equal)
/StdLog-8               552B ± 0%      552B ± 0%     ~     (all equal)
/LogNoExporter-8        680B ± 0%     1024B ± 0%  +50.59%  (p=0.008 n=5+5)
/TraceNoExporter-8      512B ± 0%      512B ± 0%     ~     (all equal)
/StatsNoExporter-8    1.26kB ± 0%    2.05kB ± 0%  +62.03%  (p=0.008 n=5+5)
/Log-8                5.20kB ± 0%    6.06kB ± 0%  +16.46%  (p=0.008 n=5+5)
/Trace-8              11.8kB ± 0%    11.8kB ± 0%     ~     (p=0.167 n=5+5)
/Stats-8              2.29kB ± 0%    3.07kB ± 0%  +34.27%  (p=0.008 n=5+5)

name                old allocs/op  new allocs/op  delta
/Baseline-8             0.00           0.00          ~     (all equal)
/StdLog-8               30.0 ± 0%      30.0 ± 0%     ~     (all equal)
/LogNoExporter-8        30.0 ± 0%      16.0 ± 0%  -46.67%  (p=0.008 n=5+5)
/TraceNoExporter-8      16.0 ± 0%      16.0 ± 0%     ~     (all equal)
/StatsNoExporter-8      62.0 ± 0%      32.0 ± 0%  -48.39%  (p=0.008 n=5+5)
/Log-8                   172 ± 0%       158 ± 0%   -8.14%  (p=0.008 n=5+5)
/Trace-8                 336 ± 0%       336 ± 0%     ~     (all equal)
/Stats-8                94.0 ± 0%      64.0 ± 0%  -31.91%  (p=0.008 n=5+5)

Change-Id: I81d2443c9a32d25a5b60fffa60759caa33566da2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225381
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-29 02:53:08 +00:00
Rebecca Stambler
3db5fc6bac internal/gocommand: don't delete command's environment
My fix in CL 225817 introduced another bug :)

Fixes golang/go#38101

Change-Id: I3de1a051d3e86474c6aa0fb0e427a590438e2172
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226257
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-28 03:18:15 +00:00
Heschi Kreinick
82bb89366a internal/lsp/cache: validate workspace path case
On case-insensitive file systems, the editor may send us a path that
works but doesn't match the actual file's case. Then when we run go
list, we'll get mismatching paths and everything will break.

We can't reliably fix this problem: tracking what case the editor
expects is too difficult to be worth it. Instead, check the workspace
path and bail if it's mismatched.

Possibly we should also check files on DidOpen or such, but we can start
with this.

Updates golang/go#36904.

Change-Id: I7635c8136bf9400db4143a0f2fde25c39b5abc44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225239
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-03-27 19:55:53 +00:00
Rebecca Stambler
8faa90c243 internal/gocommand: only set working dir if it's not empty
This was causing crashes by setting the working directory to be empty.

Fixes golang/go#38062
Fixes golang/go#38101

Change-Id: I6d679ee1d5dcab914df3d565d83aa6de0dd74cb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-27 19:39:47 +00:00
Rohan Challa
eabff7e044 internal/lsp/analysis: add quickfix for "no new vars on left side"
This change adds a quick fix for type errors of the type "no new vars on left side of :=". It will replace the ":=" with an "=".

Updates golang/go#34644

Change-Id: I91af8eb82956104229c3b4f3d0fce60fdfdbb5ea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225477
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-27 19:15:53 +00:00
Rohan Challa
f4fcf867e7 internal/lsp/analysis: add quickfix for "no result values expected"
This change adds a quick fix for type errors of the type "no result values expected". It will replace the return statment with an empty return statement.

Updates golang/go#34644

Change-Id: I3885748dfc69a2d19f8e7a2e81f36f6d0a20d25b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223666
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-27 18:57:59 +00:00
Rohan Challa
afab6edfad internal/lsp/source: remove unused parameters from functions
This change uses the new unusedparams analyzer to remove any unused parameters from functions inside of internal/lsp/source :)

Change-Id: I220100e832971b07cd80a701cd8b293fe708af3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225997
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-27 18:57:18 +00:00
Rob Findley
17a19b5fe7 internal/lsp/cmd: add a flag to disable telemetry
govim integration tests (and probably some real user sessions) are
broken because telemetry metrics are not threadsafe, resulting in an
index out of range panic.

Fix this by adding a flag (labeled temporary) to disable telemetry
export.

Also temporarily update govim to master to pick up some fixes, and run
only the -short tests to avoid timeouts.

Updates golang/go#38042

Change-Id: I584e5d200c2f732bd4024002ee6253d09623b29f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226057
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-03-27 18:51:17 +00:00
Rohan Challa
8f81e2e6d4 internal/lsp/analysis: add quickfix for undeclared variable
This change adds a quick fix for diagnostics that have an error message of the form "undeclared name: %s". It provides a quick fix to add a new variable with that name.

Updates golang/go#34644

Change-Id: I6534ee79d1770d1a62bac169c3c7e52e2443f39e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222237
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-27 18:31:06 +00:00
Rohan Challa
42235f6384 internal/lsp: add support for type error analyzers
This change adds support within gopls for analyzers that work with type errors to provide suggested fixes.

Updates golang/go#34644

Change-Id: Ia8929173752fda6bd84a9edaabd310e758f25fe8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222761
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-27 17:27:16 +00:00
Rebecca Stambler
eca45d481d internal/lsp: refactor references/rename/implementations
As part of investigating golang/go#38100, I noticed a few things that I
wanted to clean up. Mostly, for renames, we were calling
qualifiedObjAtProtocolPos twice, so I factored out a shared helper
function. I also added an error return for builtins so that callers
don't have to check.

Change-Id: I28c75c801cbec1611736af931cfa72befd219201
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225777
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-27 17:09:18 +00:00
Rohan Challa
5d86d385bf internal/lsp/analysis: add simplify-slice pass from "gofmt -s"
This is one of the simplifications that "gofmt -s" applies.
https://golang.org/cmd/gofmt/#hdr-The_simplify_command

A slice expression of the form:
	s[a:len(s)]
will be simplified to:
	s[a:]

Updates golang/go#37221

Change-Id: Ibd4dedaadc9b129d5d39524f0c1ccc8a95bf7e0d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223659
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-03-26 21:04:57 +00:00
Rohan Challa
e428a8eca3 internal/lsp/analysis: add simplify-composite-lit pass from "gofmt -s"
This is one of the simplifications that "gofmt -s" applies.
https://golang.org/cmd/gofmt/#hdr-The_simplify_command

An array, slice, or map composite literal of the form:
	[]T{T{}, T{}}
will be simplified to:
	[]T{{}, {}}

Updates golang/go#37221

Change-Id: I2dca46501983c8af3581c9319d973da5cf690388
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223660
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-03-26 20:50:12 +00:00
Rohan Challa
88b9c284fd internal/lsp/analysis: add pass for unused parameters
This change adds a pass that checks for unused parameters inside of a function. It is disabled by default.

Updates golang/go#36602

Change-Id: I9e8de3368f16f27e7816ec4ddb16935e1a05584e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222817
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 20:36:28 +00:00
Rohan Challa
94fe02cb5c internal/lsp/analysis: add simplify-range pass from "gofmt -s"
This is one of the simplifications that "gofmt -s" applies.
https://golang.org/cmd/gofmt/#hdr-The_simplify_command

A range of the form:
	for x, _ = range v {...}
will be simplified to:
	for x = range v {...}

A range of the form:
	for _ = range v {...}
will be simplified to:
	for range v {...}

Updates golang/go#37221

Change-Id: Ic6babbd0b8ab961ebb4d0d6df72df52d9acde6e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223661
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 20:18:45 +00:00
Rohan Challa
e46a7b92c0 internal/lsp: add support for sourceFixAll analyzers
This change adds support for analyzers that have suggested fixes of the kind Source.FixAll. This will allow these fixes to be applied on save if the user desires.

To auto apply these fixes on save, make sure your settings.json looks like:

"[go]": {
	"editor.codeActionsOnSave": {
		...
		"source.fixAll": true,
		...
	},
	...
}

Update golang/go#37221

Change-Id: I534e4f6c8c51ec2848cf2899aab68f587ba68423
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223658
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 20:01:16 +00:00
Daisuke Suzuki
d58d27dcbb tools/gopls: add cmd support for workspace_symbol
This change adds command line support for workspace/symbol.
Symbols are formatted as '{span} {name} {type}'.

$ gopls workspace_symbol -matcher fuzzy 'wsymbols'
$
$ workspacesymbol/a/a.go:5:7-31 WorkspaceSymbolConstantA Constant
$ workspacesymbol/b/b.go:5:6-28 WorkspaceSymbolStructB Struct

Optional arguments are:
-matcher, which specifies the type of matcher: fuzzy, caseSensitive, or caseInsensitive.
The default is caseInsensitive.

Updates golang/go#32875

Change-Id: Ieef443b13710f9c973210e58f66ab7679f258b30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224677
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 19:59:04 +00:00
Rohan Challa
02a6ca6dc3 internal/lsp: change disabledAnalyses setting to be general
This change removes the disabledAnalyses setting and replaces it with a more general feature named "analyses". This will allow users to opt in as well as opt out of analyzers that they do not find useful. This also updates some documentation to show users what analyzers gopls is using and which are enabled by default.

Change-Id: Id3239b4c4c9667e834f262c889270d14fdba0f93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223662
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 19:30:34 +00:00
Rebecca Stambler
52ff224b76 internal/lsp: avoid possible nil pointer in references/rename
Noticed this in https://github.com/fatih/vim-go/issues/2786. I don't
think that this will fix the problem in this issue, but we should avoid
nil pointers as much as possible. Also, remove a bit of extra whitespace
so that the style closer matches that of the rest of the project.

Change-Id: I94b924ea14e4a296382e3e68c52eeb43f6cd86a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225523
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-26 18:28:26 +00:00
Ian Cottrell
c9942794f0 internal/telemetry: render trace tags using typed keys
Type switch on the key and use it to get the value and decide how
to render it.
Use the same render for all debug tag printing.

Change-Id: Ia305fded7dcf05b57c5805f48bb5c22fa7def71f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225380
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:46:26 +00:00
Ian Cottrell
1386b938c6 internal/telemetry: convert attributes using the key type
This uses the strongly typed key to get the value rather than
type switching on the value itself.

Change-Id: I8f72d1d9cac0191b0565c14d8a1108459ee6df36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225379
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:46:10 +00:00
Ian Cottrell
1249273038 internal/telemetry: make metrics take a strongly typed key
Now that keys are solidly typed, we can use them for the metrics.
This prevents accidentally using the wrong type of key, and
allows us to use the typed accesorrs rather than the raw value.

Change-Id: I553bd8e12128d3f00a3e926dbd3bfd420cd3f135
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225378
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:45:58 +00:00
Ian Cottrell
063d392fe0 internal/telemetry: normalize the event reciever names to all use ev
Change-Id: Ie622d8d5c4f1c7c272400e549981cd182fe0ab67
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225377
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:45:47 +00:00
Ian Cottrell
8f75b710dd internal/telemetry: improve the telemetry benchmark
This changes the benchmarks to be less heavy weight.
It allows the baseline to have no allocations and be
very lightweight. This makes it easier to see
realistic numbers for the costs of the various
operations, making it easier to track and optimize.

Change-Id: I07699881d6976c3ab3432373f057b563752509b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225337
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-26 17:45:41 +00:00
Heschi Kreinick
e2e2519b1d lsp/source: create zero value ast.Exprs
In support of https://golang.org/cl/224960, add utility functions that
create zero value expressions for a given types.Type. There are probably
some bugs here but they pass the basic tests in that CL.

Known problems: it skips through type aliases, and can't handle
anonymous structs/interfaces. Hopefully it's pretty unusual to return
those.

Change-Id: I69a388d9ce9bd60bc230e4a3d2b30f581ec25698
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225177
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-26 17:41:01 +00:00
Rebecca Stambler
f53864d0db internal/lsp: remove command-line-arguments as a workspace package
If a package starts out as command-line-arguments, and then becomes
"valid" (i.e., gets a package declaration), we shouldn't continue to try
to diagnose "command-line-arguments". We should remove
"command-line-arguments" from workspace packages any time its metadata
is invalidated (assuming it may get added back if a file= query produces
it again).

Include the relevant regression test.

Fixes golang/go#37978

Change-Id: I7fc51edeb58007b4b4a163336cbeb752a53da322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-25 20:31:30 +00:00
Ian Cottrell
a49f79bcc2 internal/telemetry: hide event.Type
Change-Id: I390102bbffaa242051cc131ef0659a6544aa89c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224938
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-25 01:02:19 +00:00
Ian Cottrell
f207553f3c internal/telemetry: remove the ProcessEvent function
There is no reason for it to be public now, it is no longer possible to build an
event
without using the helpers.
This also allows us to delay setting the time until after the nil exporter
check, for
a significant time saving in the no exporter case.

name                old time/op    new time/op    delta
/Baseline-8            588ns ± 4%     575ns ± 4%   -2.24%  (p=0.000 n=18+18)
/StdLog-8             9.61µs ± 3%    9.58µs ± 3%     ~     (p=0.384 n=18+18)
/LogNoExporter-8      3.94µs ± 2%    2.26µs ± 2%  -42.50%  (p=0.000 n=17+18)
/TraceNoExporter-8    2.77µs ± 4%    1.11µs ± 2%  -59.82%  (p=0.000 n=18+18)
/StatsNoExporter-8    3.83µs ± 5%    2.15µs ± 3%  -43.70%  (p=0.000 n=18+17)
/Log-8                23.3µs ± 6%    23.0µs ± 1%     ~     (p=0.245 n=18+17)
/Trace-8              26.4µs ± 3%    26.5µs ± 4%     ~     (p=0.269 n=18+17)
/Stats-8              5.36µs ± 2%    5.45µs ± 3%   +1.68%  (p=0.000 n=17+18)

Change-Id: Ibde0e20eaf99d03f786cd1436f05eab7b2a17b20
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224657
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-25 01:01:39 +00:00
Ian Cottrell
224c947ce5 internal/telemetry: replace TagSet with TagMap and TagPointer
This separates the concerns of tag collections that have to be iterated
and tag collections that need lookup by key.
Also make it so that events just carry a plain slice of tags.
We pass a TagMap down through the exporters and allow it to be
extended on the way.
We no longer need the event.Query method (or the event type)
We now exclusivley use Key as the identity, and no longer have a
common core implementation but just implement it directly in each
type.
This removes some confusion that was causing the same key through
different paths to end up with a different identity.

Change-Id: I61e47adcb397f4ca83dd90342b021dd8e9571ed3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224278
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-25 01:00:44 +00:00
Ian Cottrell
62abcc1da2 internal/telemetry: change Exporter to be a function type.
Change-Id: Id410da20310baf4da6875de08e4449c7a6fb0250
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224277
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-25 00:42:15 +00:00
Rob Findley
1fc30e1f4c internal/lsp/regtest: remove redundant T and ctx params from regtest funcs
In an effort to be idiomatic, I made the regtest func signature
func(context.Context, testing.T, *Env), despite the fact that Env
already has a Context and a T.

This just ended up causing more confusion, as it's not clear which
Context or T to use. Remove this and just use the fields on Env.

Change-Id: I54da1fdfe6ce17a67601b2af8640d4d2ea676e8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225157
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-24 20:18:24 +00:00
Rob Findley
4c83a7e07a internal/lsp/fake: add regexp search and replace
Expressing regtests in terms of textual coordinates is hard to read: the
reader ends up counting lines and characters to understand the text edit
or assertion.

To address, this, add two new functions for fake.Editor: RegexpSearch
and RegexpReplace, as well as a symmetric RegexpSearch function for
workspace files and wrappers for regtext.Env.

This allows expressing edits as well as buffer locations in terms of
easily scannable regexps.

An alternative solution to this problem is to integrate markers ala
packagestest. I tried this, but it ended up being cumbersome to
implement and less usable than regexps, due to the static nature of
markers: after the buffer has been edited all markers must be
updated.

Updates golang/go#36879

Change-Id: Iad087cf0d529737034197beef7b729816a159c69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224757
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-24 20:17:55 +00:00
Rebecca Stambler
6fc5d0bc36 internal/lsp: print view-specific environment
For debugging purposes, we print the output of `go env` on start. Now,
we print a view-specific `go env`, which will helps us when debugging
multi-project workspaces. Additional information included: the folder of
the view, if the view has a valid build configuration, and the build
flags for the view.

Updates golang/go#37978

Change-Id: Iadffd46f8ac5410971558a304b8bbcb2f9bdbcc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225137
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-24 20:15:47 +00:00
Rebecca Stambler
a5e5fedfe7 internal/lsp: stop showing workspace misconfiguration message
This is helpful for users to diagnose issues, but it annoys people who
have workspaces with both non-Go and Go projects. I'm going to spend
some more time thinking about this, particularly about which error
messages we should retry the initial workspace load for.

Updates golang/go#32394

Change-Id: I7d02b385da232914fe7342837dc3a9c4185399fd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225237
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-24 18:23:14 +00:00
Rebecca Stambler
6fb6f5a9fc internal/lsp: never reload command-line-arguments directly
I'm not sure if this is entirely the correct approach, but at the very
least we should never pass "command-line-arguments" to packages.Load. We
still need to cache packages with the path "command-line-arguments" to
avoid an excessive number of calls to packages.Load.

Updates golang/go#37978

Change-Id: I1b5263a3dab95aacd797f03f742069fd0c53619c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225117
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-24 17:58:52 +00:00
jiacai2050
bbbf714b4a internal/lsp: fix nil pointer in 'go mod why' logic
Fixes golang/go#37977

Change-Id: I125c7900e8ee7975f179ea68333ea347b9bfa9e8
GitHub-Last-Rev: 69b71b7853dedc1dc42e96059aa693a4b8652062
GitHub-Pull-Request: golang/tools#217
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224591
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-24 16:11:17 +00:00
Nathan Dias
5c746ccfa2 internal/telemetry/export/ocagent: add traces to tutorial
This change updates the metrics tutorial to include example code for
exporting traces from go tools.

Change-Id: Ie1d3c373ed4308ef0160f6389b74c642b348bed6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225061
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-24 05:36:59 +00:00
Nathan Dias
dbf25ea225 internal/telemetry/export/ocagent: update metrics tutorial to use the event system
This change updates the metrics tutorial to be compatible with the new event system.

Change-Id: I8b75f6b02d241bc9dede01cfac167a982f1df67c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225058
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-24 03:55:26 +00:00
Muir Manders
ef1313dc6d internal/lsp/source: prefer unexported and non-func candidates
A common annoying mis-completion is as follows:

    type foo struct {
      field int
    }

    func (f foo) Field() int { return f.field }

    func (f foo) logic() {
      if f.f<>
    }

Now at <> we prefer "field" over "Field()". Similarly:

    type foo struct {
    }

    func (f foo) DoSomething() { }

    func (f foo) doSomething() { }

    func (f foo) logic() {
      f.d<>
    }

Now at <> we prefer "doSomething()" over "DoSomething()". All else
being equally, you normally want private objects over public objects
when the private objects are available.

The same logic is applied to deep completions so we prefer "c.foo.bar"
over "c.Foo().bar".

Change-Id: Ic91cba7721ddb1f2a30338037693ddcce8c621f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223877
Run-TryBot: Muir Manders <muir@mnd.rs>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-23 21:07:25 +00:00
Rebecca Stambler
8849913b69 internal/lsp: be more careful about showing workspace misconfig message
We can re-enable this when we have a version of Go that includes the fix
for golang/go#37971. Then we can continue playing whack-a-mole with go
list corner cases :)

Fixes golang/go#37958

Change-Id: I2417731bf5c01fbde867fef2ef03b5025ae779c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224538
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-23 19:22:00 +00:00
Rebecca Stambler
18ea2c8f73 internal/lsp: fix nil pointer in renaming to "error"
Fixes golang/go#37963

Change-Id: I0a46cbcbd250729761b9a8323b942202bb1dbd75
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224477
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-23 16:43:54 +00:00
Ian Cottrell
8dcfad9e01 internal/telemetry: switch metrics to use the event system
Change-Id: If036530ffe47e7df925bcf6592f664d6020a3d65
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223997
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-23 14:44:30 +00:00
Ian Cottrell
326edff2a4 internal/telemetry: switch metrics to use only the public API
This also modifies the test data based on a comment in
https://go-review.googlesource.com/c/tools/+/222849

Change-Id: Ib0db60846566b40408b12f84240b58356065d319
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223928
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-23 14:44:17 +00:00
Ian Cottrell
b378960d5b internal/telemetry: replace event.TagList with event.TagSet
This allows us to hide the implementation details of how tags are stored on a
context from the normal interface, to allow us to explore more efficient
mechanisms.
The current storage is not intended as the most efficient choice, this cl is
about isolating the API so we can experiment with benchmarks in the future.

Change-Id: Ib101416bccd8ecdee269cee636b1564d51e1da8a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222854
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-23 14:43:48 +00:00
Rebecca Stambler
0d839f3cf2 internal/lsp: remove completion commands
The next version of VS Code Go has to be released before this can be
released.

Fixes golang/go#37966

Change-Id: I6b97f2a3ff9c8400ae85b815d8bf83a9b12b1069
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224518
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2020-03-21 22:47:14 +00:00
Nathan Dias
268ba720d3 internal/telemetry/export/ocagent: update metric tutorial to use oragent
This change updates the metric exporting tutorial to use oragent to spin
up OpenCensus, Prometheus, and Zipkin all at once using docker-compose
rather than manually setting each one up. This allows developers to set
up an environment for testing metrics and traces with minimal effort.

While oragent also spins up Zipkin for traces, the tutorial does not yet
have a section outlining how to export traces from Go tools. A section
for traces will added in a later CL.

Change-Id: I07f49977f7ab49995853ff8ee8eb6ccdf6ef1642
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224258
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-21 01:49:04 +00:00
Koichi Shiraishi
2f9d11aa23 internal/jsonrpc2: remove unnecessary Log comment from Handler interface
Change-Id: If488397bbf543ff77ff789e955c04dfe84501c14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/224557
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-20 20:59:04 +00:00
Daisuke Suzuki
521f4a0cd4 internal/lsp/cmd: fix definition test to run independently
definition.Run requires a nil check of opts before applying to avoid
panic, and test must be run with markdown enabled.
When running 'go test' without -run flag, connection.initialize() was
not called and there was no problem because the default value of
Options.PreferredContentFormat was Markdown.
In addition, currently using the same connection despite different
options, therefore make to use a different connection for different
options.

Change-Id: I6ef773c14cbdcae621da9295d4c618c3aff0beee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222497
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-19 21:04:07 +00:00
Rob Findley
9a0fabac01 internal/lsp: fix errors found by staticcheck
While experimenting with different static analysis on x/tools, I noticed
that there are many actionable diagnostics found by staticcheck. Fix the
ones that were not false positives.

Change-Id: I0b68cf1f636b57b557db879fad84fff9b7237a89
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222248
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-19 19:20:54 +00:00
Ian Cottrell
540150da73 internal/telemetry: add type safe tag keys
This changes the way keys work, there is still a single internal key
implementation for performance reasons, but the public interface is a set of key
implementations that have type safe Of and Get methods.
This also hides the implemenation of Tag so that we can modify the storage form
and find a more efficient storage if needed.

Change-Id: I6a39cc75c2824c6a92e52d59f16e82e876f16e9c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223137
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-18 13:29:43 +00:00
Ian Cottrell
d7fc2cf50e internal/telemetry: delete the event.TagOf method
It encourages poor performing log lines, and also reduces the readability of
those lines.
Also delete the Key.With method which was unused, and should never be used
instead of the event.Label function anyway.

Change-Id: I9b55102864ee49a7d03e60af022a2002170c0fb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222851
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-18 13:23:15 +00:00
Ian Cottrell
04208b9e8a internal/lsp: move the telemetry package
Move the lsp specific telemetry package that just declares the labels under the
debug package and call it tag, to make all the usages much more readable.

Change-Id: Ic89b3408dd3b8b3d914cc69d81f41b8919aaf424
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222850
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-18 13:22:49 +00:00
Ian Cottrell
9dec35b5f8 internal/telemetry: change ocagent test to use the standard telemetry methods
Rather than building cusom events and driving the exporter, the test now
registers a custom exporter and then uses the normal higher level methods to
deliver events to it.
This means we are testing the actual information that would arise in a user
program, and also means we no longer have to expose internal features just for
tests.
Metrics are not fully converted yet.

Change-Id: I63248a480fb1b3e6274dce0c2e1d66904d055978
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222849
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-18 13:22:16 +00:00
Ian Cottrell
cb106d260e internal/telemetry: allow ProcessEvent to modify the event
This allows early exporters to adjust the event for later ones.
This is used to lookup key values from the context if needed.
Also add a Query type event which is intended to perform all event
modifications but nothing else, and is used to lookup values from
the context. This cleans up a weirdness where the current lookup
presumes there will be an exporter with a matching mechanism.

Change-Id: I835d1e0b2511553c30f94b7becfe7b7b5462c111
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223657
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-18 13:22:01 +00:00
Ian Cottrell
9fceb114c3 internal/lsp: move the operation key to the telemetry package
Change-Id: If064d9bb396169fe78214b07f72a0536082bf374
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223748
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-18 13:08:08 +00:00
Muir Manders
11a475a590 internal/lsp/source: fix literal completions in variadic args
We now properly offer literal completions when completing the variadic
parameter. For example:

    func foo(...[]int) {}
    foo(<>) // now offers "[]int{}"

Updates golang/go#37656.

Change-Id: I91c47d455ae3f8051078c82a308f2b5ad4b3d4cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222199
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-18 05:47:22 +00:00
Muir Manders
613a0345a2 internal/lsp/source: optimize enumeration of a type's fields
When searching for deep completions, we can end up enumerating struct
types' fields a lot. Optimize fieldSelections to reduce work:

- Wait until we see an embedded field before we create the "seen"
  map.
- Use a callback style to iterate over the struct's fields rather than
  returning a slice of fields.
- Change "seen" checking strategy back to track struct types rather
  than each individual field.

Struct with 5 non-embedded fields:

name       old time/op    new time/op    delta
Fields-16     293ns ± 1%      20ns ± 2%   -93.13%  (p=0.008 n=5+5)

name       old alloc/op   new alloc/op   delta
Fields-16      120B ± 0%        0B       -100.00%  (p=0.008 n=5+5)

name       old allocs/op  new allocs/op  delta
Fields-16      4.00 ± 0%      0.00       -100.00%  (p=0.008 n=5+5)

Same struct but add an embedded struct with 2 fields:

name       old time/op    new time/op    delta
Fields-16     389ns ± 1%     142ns ± 1%  -63.53%  (p=0.008 n=5+5)

name       old alloc/op   new alloc/op   delta
Fields-16      120B ± 0%      144B ± 0%  +20.00%  (p=0.008 n=5+5)

name       old allocs/op  new allocs/op  delta
Fields-16      4.00 ± 0%      2.00 ± 0%  -50.00%  (p=0.008 n=5+5)

I think the alloc/op went up because the "seen" map is no longer
allocated on the stack. There is more room for more optimization, but
it's probably not worth making things more complicated.

Change-Id: I6f9f2124334a8594ef9d6f9b5ac4b3a8aead5f49
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223419
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-18 05:47:12 +00:00
Marwan Sulaiman
cf1dd6fc34 x/tools/gopls: 'go generate' should use $/progress if available
This commit will make the 'go generate' CodeLens command check the client
capabilities to use $/progress to report the progress of the command or otherwise
it will fallback to showing the message box already in place. The $/progress will
give you a play by play update while the message box shows only the beginning and
the end. The gopls logs will have all the details in either case.

Note that the $/progress is an LSP 3.15+ feature and not yet supported in all clients.

Updates golang/go#37680

Change-Id: I5ba37448be8e388f728394795e1bb5f1d50cc30d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223739
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-17 19:18:43 +00:00
Rohan Challa
d05f4d6edb internal/lsp: fix breadcrumbs when inside of a method
This change fixes breadcrumbs when the cursor is inside of a method by making the method a top level symbol and removing it from the struct's hierarchy.

Fixes golang/go#36949

Change-Id: I8da5f453a5c78ade1e7688fc4eeebf79ce96f1e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221819
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-17 19:04:34 +00:00
pjw
827390e901 internal/lsp: fix code.ts to generate progress and *TextEdit
This CL gets code.ts to generate code for $/progress and
window/workDoneProgres/create messages. $/progress uses a
ProgressParams type which contains one of three new data types,
WorkDoneProgressBegin, WorkDonProgressEnd, WorkDoneProgressReport.

In addition, a *TextEdit is now generated for CompletionItem.TextEdit.

The substantive differences in code.ts are around line 451 and line
682. Everything else is whitespace caused by vscode formatting typescript
differently on different OSes.

Change-Id: Ide441e6e0029cbc8401d6476f6a939216cc89634
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223743
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-17 18:47:13 +00:00
Marwan Sulaiman
63da46f303 x/tools/gopls: run go generate through CodeLens
This change adds support for recognizing a //go:generate directive
and offering a CodeLens that will then send a "generate" command to
the server to run "go generate" or "go generate ./...". Because
"go generate" can only be executed per package, there is no need to show
the CodeLens on top of every //go:generate comment. Therefore, only the
top directive will be considered.

The stdout/stderr of the go generate command will be piped to the logger
while stderr will also be sent to the editor as a window/showMessage

The user will only know when the process starts and when it ends so that they wouldn't
get bogged with a large number of message windows popping up. However, they can
check the logs for all the details.

If a user wants to cancel the "go generate" command, they will be able
to do so with a "Cancel" ActionItem that the server will offer to the client

Fixes golang/go#37680

Change-Id: I89a9617521eab20859cb2215db133f34fda856c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222247
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-17 04:34:34 +00:00
Ian Cottrell
fbeba2149c internal/telemetry: split the ocagent tests from the support functions
This moves the actual trace test into its own file so that it can easily
be seen separately from the functions that support all tests.

Change-Id: I1d30cf8a712377ca79a5de77b85412c881177f43
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223397
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-17 03:16:54 +00:00
Marwan Sulaiman
3e76bee198 x/tools/gopls: add support for $/progress functionality
This CL adds support for sending progress notifications through $/progress
calls as well as being able to cancel them through window/workDoneProgress/cancel.
This feature is only supported in clients running LSP 3.15 and therefore the initialize
request will check for client capabilities for its progress support.

Updates golang/go#37680

Change-Id: Iff8c016694746a9dd553e5cc49444df7afcc21f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222981
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-16 21:25:24 +00:00
aca
df010c5017 internal/lsp/cache: fix typo
Change-Id: Ida5ed631652d9d4e35018300ab098ebb24b75856
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223498
Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-16 18:21:19 +00:00
Rob Findley
c312e98713 gopls/doc: update daemon.md and remove 'experimental' caveats
Now that the feature-set is relatively complete for running gopls in
daemon mode, daemon.md is updated to reflect the new features and to
remove some of the experimental warnings. Similarly the `-remote` flag
is made more welcoming.

The feature still needs more usage, but it shouldn't be considered
experimental anymore.

Fixes golang/go#34111

Change-Id: I994fc8f9f84bf856f24e1eadabd73c503267e804
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222717
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-12 19:44:00 +00:00
Rob Findley
c1c69b635f internal/lsp: clean up on Shutdown even if not initialized
Previously it was an error to call shutdown while the server was not yet
initialized. This can result in session leak for very short-lived
sessions.

Instead, allow shutdown to proceed and simply log the error. On the
other hand, for consistency make it an error to call initialized without
first calling initialize.

Updates golang/go#34111

Change-Id: I0330d81323ddda6beec0f6ed9eb065f8b717dea0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222671
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-12 19:43:25 +00:00
Rob Findley
30fd94b347 internal/lsp/lsprpc: expose configuration for auto-started daemon
Three new flags are added to the serve command, and threaded through to
the LSP forwarder:
 -remote.listen.timeout: -listen.timeout for the auto-started daemon
 -remote.debug: -debug for the auto-started daemon
 -remote.logfile: -logfile for the auto-started daemon

As part of this change, no longer enable debugging the daemon by
default.

Notably none of this configuration affects serving, so modifying this
configuration has been chosen not to change the path to the automatic
daemon. In other words, this configuration has effect only for the
forwarder process that starts the daemon: all others will connect to the
daemon and inherit whatever configuration it had at startup. This should
be OK, because in the common case this configuration should be static
across all clients (e.g., many Vim sessions all sharing the same
.vimrc).

Exposing this configuration made the signature of lsprpc.NewForwarder
a bit hard to understand, so I decided to go ahead and switch to a
variadic options pattern for initializing both the Forwarder and
StreamServer, the latter just for consistency with the Forwarder.

Updates golang/go#34111

Change-Id: Iefb71e337befe08b23e451477d19fd57e69f36c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222670
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-12 19:43:16 +00:00
Rob Findley
bd435c612c internal/lsp/cmd: add an inspect verb
Add a new toplevel `inspect` verb to the gopls command, to expose the
internal state of a running gopls server. For now, this verb exposes a
single subcommand `sessions`, which lists some information about current
server sessions on a gopls daemon.

This can be used even if the debug server is not running, which will
become the default in a later CL.

Updates golang/go#34111

Change-Id: Ib7d654a659fa47280584f9a7301b952cbccc565a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222669
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-12 17:21:45 +00:00
Muir Manders
11d5b4c81c internal/lsp/source: offer loop keyword completions in range stmt
Be sure to offer "continue" and "break" keyword completions in
RangeStmt in addition to ForStmt.

Fixes golang/go#34009.

Change-Id: I01ea0c3d8d110e322cb6582fda32aeb060116bb1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223120
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-12 04:57:24 +00:00
Ian Cottrell
eff45d17df internal/telemetry: convert key from string to struct
This makes keys a pointer, which reduces the allocations during logging, and has
a significant improvement in memory and cpu cost when there is no exporter.
Packing a string into an interface requires a 16 byte allocation, packing a pointer
does not.

name                old time/op    new time/op    delta
/LogNoExporter-8      4.39µs ± 2%    3.83µs ± 2%  -12.74%  (p=0.000 n=18+20)
/Log-8                23.5µs ± 2%    22.6µs ± 1%   -4.20%  (p=0.000 n=19+18)

name                old alloc/op   new alloc/op   delta
/LogNoExporter-8      1.70kB ± 0%    1.38kB ± 0%  -18.78%  (p=0.000 n=20+20)
/Log-8                4.91kB ± 0%    4.91kB ± 0%     ~     (p=1.000 n=20+20)

name                old allocs/op  new allocs/op  delta
/LogNoExporter-8        83.0 ± 0%      63.0 ± 0%  -24.10%  (p=0.000 n=20+20)
/Log-8                   163 ± 0%       163 ± 0%     ~     (all equal)

Change-Id: Iec127f1bff8d5c8f4bd0a6d9f6d8fc4b8bc740b2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222599
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 04:17:52 +00:00
Ian Cottrell
a9aaa4e906 internal/telemetry: use keys properly for benchmarks
Change-Id: I571628db26a5b89fd567077d90d325fd76301956
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222598
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 04:17:28 +00:00
Ian Cottrell
68dc0f3515 internal/telemetry: remove all the event aliases
Change-Id: I6d9a25be2b9dbba2385e13810e3c9e79c5f67aa5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222559
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 04:17:16 +00:00
Ian Cottrell
206ec5b82a internal/lsp: migrate telemetry to using the event package
Change-Id: Idc662385ed08bd62593ccd1d54afd3fa8c1a7d29
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222558
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 03:59:16 +00:00
Ian Cottrell
d780ff7bdd internal/telemetry: unify the event handling to an event package
This is now the only package that is exposed to normal use, and should
be the only thing to appear in libraries.

Change-Id: I90ee47c6519f30db16ff5d5d2910be86e91e5df2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222557
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-12 03:58:56 +00:00
Muir Manders
3dc7fec788 internal/lsp/cache: remove parseGo semaphore
The original intention was to limit the number of open file handles,
but the parseLimit semaphore was limiting parser.ParseFile calls that
don't access files, so there was no benefit. The file limiting is
already handled generically by another semaphore in the lsp FileSystem
abstraction.

Change-Id: Idc7f2507af5287e983a7edf3e38a848d26770bbe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/223119
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-12 03:18:52 +00:00
Daisuke Suzuki
0d653b92c5 internal/lsp/tests: fix WorkspaceSymbols tests
The tests will not run because there is no workspacesymbol marker.
Therefore, restore testdata used in WorkspaceSymbols tests, and
initialize data so that the tests run even if the target of the marker
is 0.

Change-Id: I051b842183b7e23bb746cc282fc3921a90ca8df1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221617
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-11 18:46:36 +00:00
Muir Manders
43e3193a9b internal/lsp/source: suppress keyword completions in "case" statement
Now we no longer offer keyword completions inside "case" statements:

    select {
    case fo<>: // don't offer "for"
    }

Updates golang/go#34009.

Change-Id: I908eda32af01fd1912fb587ce59efef1798b6741
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220580
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-11 03:54:31 +00:00
Muir Manders
7bb885034f internal/lsp/source: fix completion in empty switch statements
Now we properly offer "case" and "default" keyword completion in cases
like:

    switch {
      <>
    }

First I had to add an AST fix for empty switch statements to move the
closing brace down. For example, say the user is completing:

    switch {
    ca<>
    }

This gets parsed as:

    switch {
    }

Even if we manually recover the "ca" token, "<>" is not positioned
inside the switch statement anymore, so we don't know to offer "case"
and "default" candidates. To work around this, we move the closing
brace down one line yielding:

    switch {

    }

Second I had to add logic to manually extract the completion prefix
inside empty switch statements, and finally some logic to offer (only)
"case" and "default" candidates in empty switch statements.

Updates golang/go#34009.

Change-Id: I624f17da1c5e73faf91fe5f69e872d86f1cf5482
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220579
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-11 03:54:16 +00:00
Ian Cottrell
f30ed8521d internal/telemetry: change detach to be an event
deliver detach to the exporter as an event rather than hard coding the
span detach behavior.

Change-Id: I87b6e2a3596fea338908c11ba0b219176b6305bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222542
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-11 02:43:08 +00:00
Ian Cottrell
e8dd451b4b internal/telemetry: add a stats benchmark
Change-Id: I9cb1459a8589cec75ae29d0e53f044c6489b1ea2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222537
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-11 02:40:42 +00:00
Muir Manders
0983143fce internal/lsp/source: avoid type checking in AllImportsFixes
Change AllImportsFixes to get the ParseGoHandle directly rather than
using getParsedFile. The latter also type checks the containing
package, which is slow in general and can be really slow in certain
circumstances. This should speed up the organizeImports code action.

Change-Id: Ic505873db41d5d76c398cee42f0323e390d9e034
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222780
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-10 23:10:53 +00:00
Peter Weinbergr
3e041465cc internal/lsp: change the type of CompletionItem.TextEdit back
The recent LPS protocol change made the definition of textEdit into
a union type, so the generated code made TextEdit an interface{},
which broke govim. This CL reverts it to a *TextEdit. The code
generator will be fixed in another CL.

We can revisit this when  gopls wants to start using the new
InsertReplaceEdit type.

Change-Id: I4d7a14b3746b747f34b0907f72ecbc3593706a05
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222765
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-10 21:12:04 +00:00
Rebecca Stambler
b84001dd64 internal/lsp: suggest filing an issue if a warning is incorrect
It seems that people are running into this warning for reasons other
than ad-hoc packages. Suggest filing an issue, since it may be that they
are opening the wrong directory or something.

Change-Id: I88036d2db9477bbea5099910f4cd8e5ba55e0624
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-10 21:11:10 +00:00
Muir Manders
138c814f66 internal/lsp/source: offer completion "if err != nil { return err }"
Now we offer an error-check-and-return completion candidate when
appropriate:

    func myFunc() (int, error) {
      f, err := os.Open("foo")
      <>
    }

offers the candidate:

    if err != nil {
      return 0, <err>
    }

where <> denotes a placeholder so you can easily alter "err".

The completion will only be offered when:
1. The position is in a function that returns an error as final result
   value, and
2. The statement preceding position is an assignment whose final LHS
   value is an error.

The completion will contain zero values for the non-error return values
as necessary.

Using the above example, the completion will be offered after the user
has typed:

    i
    if
    if err

Basically the candidate will be offered after every keystroke as the
user types "if err".

I call this new type of completion a statement completion - perfect
for when you want to make a statement!

Change-Id: I0a330e1c1fa81a2757d3afc84c24e853f46f26b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221613
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-10 21:06:53 +00:00
Peter Weinberger
20ab64c0d9 internal/lsp: bring generated protocol code up to date; stop corrupting logs
1. logging at debug/rpc.go:105 was corrupting logs.
2. DocumentSymbol (a Server method) now returns []interface{}.
3. The latest version of the LSP changed CompletionItem.TextEdit to
possibly be of the new type InsertReplaceEdit, so the generated Go
code now has TextEdit an interface{} rather than a *TextEdit. This
required a change to tests/util.go.
4. The latest version also introduced several other new types,
and new members in some structs.

Tests pass and the I've use the new gopls a little.

Change-Id: Ic44d46f0c923882c9076c2754c1c85e09fbcaa2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222668
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-09 20:21:50 +00:00
Muir Manders
92d517f97b internal/lsp/source: suppress completions in ellipsis
Editors typically trigger completion automatically after ".". This
pops up annoying, useless completions after "..." variadic param, such
as "foo(bar...<>)". We now suppress completions in or directly after
the ellipsis.

Fixes golang/go#37358.

Change-Id: I9fc94fbdf69429bd787bcb2c643f4f730e24154d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222200
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-09 18:42:16 +00:00
Rob Findley
aa4048aca1 internal/lsp/lsprpc: don't connect to sockets owned by different users
When running gopls as a forwarder it attempts to forward the LSP to a
remote daemon. On posix systems, by default this uses a unix domain
socket at a predictable filesystem location.

As an extra precaution, attempt to verify that the remote socket is in
fact owned by the current user.

Also, change the default TCP listen address used on windows to bind to
localhost.

Updates golang/go#34111

Change-Id: Ib24886d290089a773851c5439586c3ddc9eb797d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222246
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-09 18:08:59 +00:00
Danish Prakash
c94e1fe145 internal/lsp/source: return location(s) for imported packages
Fixes golang/go#32993

Change-Id: Iff2f7ab8e34eea1ce7c1ab99fb2e51589dce95c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210321
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-09 16:25:02 +00:00
Muir Manders
11ec41452d internal/lsp/source: support completing "range" keyword
We now offer "range" keyword in the for loop init statement:

for i := r<> // offer "range" completion candidate

Updates golang/go#34009.

Change-Id: I2e4c1db11c37127406c78191681c39b9dd3439f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220504
Run-TryBot: Muir Manders <muir@mnd.rs>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-08 01:35:34 +00:00
Muir Manders
2047c2d578 internal/lsp/source: complete keywords as types
Offer "struct", "interface", "map", "chan", and "func" keywords when
we expect a type. For example "var foo i<>" will offer "interface".

Because "struct" and "interface" are more often used when declaring
named types, they get a higher score in type declarations. Otherwise,
"map", "chan" and "func" get a higher score.

I also got rid of the special keyword scoring. Now keywords just use
stdScore and highScore. This makes the interplay with other types of
candidates more predictable. Keywords are offered in pretty limited
contexts, so I don't think they will be annoying.

Finally, keyword candidate score is now to be scaled properly based on
how well they match the prefix. Previously they weren't penalized for
not matching well, so there were probably some situations where
keywords were ranked too high.

Updates golang/go#34009.

Change-Id: I0b659c00a8503cd72da28853dfe54fcb67f734ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220503
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-08 01:33:38 +00:00
Rohan Challa
51e69f7192 internal/lsp/cache/mod: return errors only within ModHandle and ModTidyHandle
This change makes ModHandle and ModTidyHandle return a ModData structure that only contains an error if something goes wrong when parsing the .mod files.

Change-Id: I89661cfefeff666bdf13cf99f4c56137e120de82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222242
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-06 19:16:17 +00:00
Rohan Challa
e4e22f76d0 internal/lsp: support when hierarchicalDocumentSymbolSupport is false
This change adds support when hierarchicalDocumentSymbolSupport is false, this can happen with editors who have not supported textDocument/DocumentSymbol. As a result, these older lsp clients need to recieve []protocol.SymbolInformation rather than []protocol.DocumentSymbol. This change required some changes to internal/lsp/cmd to handle not knowing which type it is receiving, this required manual parsing inside of cmd/symbols.go.

Fixes golang/go#34893

Change-Id: I944ae24302f155b561047227f65bee34b160def1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221823
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-06 18:17:37 +00:00
Ian Cottrell
ca9608b5cd internal/telemetry: refactor the benchmark framework
Change-Id: I566ed7cd3a4d755cf06504e749ba54d0a309e53f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221921
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-06 18:16:20 +00:00
Rob Findley
8287d625a0 internal/lsp/debug: guard rpc stats with a Mutex
This type was previously guarded implicitly by the global exporter
mutex. With that gone, we've started seeing panics due to races in
(*rpcs).Metric.

Guard it with a mutex.

Change-Id: I2a8c670ecfbaee9422e1f1d282b1fedb86b6a5e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222300
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-03-06 16:15:13 +00:00
Rohan Challa
a0897bacdd internal/lsp/cmd: improve flexibility of suggested fixes
This change adds support for passing a span to cmd/suggested_fix.go, originally it would just take the filename and apply all the fixes for that file. Now, it can also take just a span within that file and only apply the fixes relevant to that span.

The //@suggestedfix marker now contains an extra parameter to specify which type of codeaction is expected.

Change-Id: I4e94b8dad719f990dc2d0ef3c50816f70f59f737
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222137
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-06 14:31:35 +00:00
Rohan Challa
136c3617b6 internal/lsp: support textDocument/formatting for .mod extension
This change implements support for textDocument/formatting when it comes to go.mod files. It also adds formatting on save ability.

To enable formatting on save for go.mod files, you need to include the following settings inside of your VSCode settings.json:

...
"[go.mod]": {
	"editor.codeActionsOnSave": {
		"source.organizeImports": true,
	},
	"editor.formatOnSave": true,
},
...

Updates golang/go#36501

Change-Id: I60ac14d0e99b2b086fe9a8581770771aafc2173c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221223
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-06 13:51:27 +00:00
Rob Findley
de023d59a5 internal/lsp/protocol: unmarshal to pointers when dispatching requests
With #34111, we are forwarding the LSP from one gopls instance to
another. This exposed an asymmetry in our LSP dispatching: for both
ClientDispatcher and ServerDispatcher, we unmarshal to non-nil response
structs. This means that when forwarding the LSP, we translate empty
JSON responses (corresponding to nil values) into the non-nil zero
value.

This causes problems for some editors, as reported in #37570. Fix it by
instead unmarshaling to a pointer.

This is, of course, a somewhat dangerous change. I fixed the one NPE
that occurred in tests, and have done some mild manual testing.  I
wouldn't be surprised if we discover more NPEs later on, but I still
think this is the right change to make.

Updates golang/go#34111
Fixes golang/go#37570

Change-Id: Ie69e92d2821c829cdfc4f4ab303679a725f1f859
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222058
Reviewed-by: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-05 22:45:36 +00:00
Rob Findley
d1d1f200c6 internal/lsp/lsprpc: use Setsid on POSIX GOOSes, to avoid SIGTERMs
When the gopls daemon is automatically managed (-remote=auto), it will
be started by one of the forwarder gopls processes that was in turn
started by the editor. By default, this puts it in the same process
group as the forwarder gopls.

Some editors (at least Vim) send SIGTERM to the process groups of
sidecar processes when exiting. This can cause the gopls daemon to
terminate, thereby losing state.

Rather than ignore SIGTERM (which is bound to be editor dependent
anyway), let's just put the gopls daemon in a separate session.

Updates golang/go#34111

Change-Id: I71386fb54b8c2efe1c565f59763f46693a7d48b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221220
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-03-05 21:44:44 +00:00
Rob Findley
bc073721ad internal/lsp/cache: include session IDs in some cache keys
When caching file data specific to a session (anything with a Version or
tied to a view), we now need to be more careful about the existence of
multiple sessions.

This change fixes a few places where we appear to cache session data
without explicitly referring to the session. In principal this could
cause data corruption in multi-session gopls instances, but I have not
been able to force this to occur in either manual or automated testing.

Also fix a data race to the unsaved overlays:
https://storage.googleapis.com/go-build-log/588ee798/linux-amd64-race_d0762522.log

Updates golang/go#34111

Change-Id: I47117da1aba1afc2e211785544ad3f8b3416d15d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222059
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-05 20:50:14 +00:00
Rob Findley
6a641547f5 internal/lsp/cache: fix NPE in fileWasSaved
Reading the docstring, it looks like the sense of the type assertion was
accidentally inverted in this function. Fix it to what I believe was
intended.

Fixes golang/go#37687

Change-Id: Ief44a996f1a262527c2916d6b78b81dd35b2cf9e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222217
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-05 18:53:22 +00:00
Dan Kortschak
d7d4448666 internal/tool: avoid editorialization
Change-Id: Ic274b13ce7b621e2baf4c2659fb4e7facd6b19b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212581
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-03-05 14:01:59 +00:00
Ian Cottrell
32f14692fc internal/lsp: use standardised events for tagging
This means that tags also become cheap if there is no exporter and cleans up the
mess with how spans, tags and logs were related.
Also fixes the currently broken metrics that relied on the span tags.

Change-Id: I8e56b6218a60fd31a1f6c8d329dbb2cab1b9254d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222065
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-05 14:00:10 +00:00
Heschi Kreinick
95d2e580d8 internal/lsp/source: use logical filenames for workspace symbols
We need to use the filename derived from the symbol information, not the
one from CompiledGoFiles, in case of cgo packages.

No tests because workspace symbols are entangled with document symbols,
and the latter doesn't work in cgo packages.

Fixes golang/go#37659.

Change-Id: Ic32293c542830a49b37c25ebf3b231771c3a4225
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222060
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-04 19:39:43 +00:00
Rohan Challa
d6a4d55695 internal/lsp/cache: attach ModTidyHandle to snapshot instance
This change attaches a modTidyHandle to the snapshot instance and tries to reuse it as often as possible. It also modifies the modTidyKey to include the files that have not yet been saved. This was necessary because `go mod tidy` only runs using contents on disk.

So, if a user decides to add an import that is not in their modcache, we run diagnostics as normal and the ModTidyKey's imports field gets updated with the new import, we run `go mod tidy` but since the file was not saved yet, nothing changes. Then when the user eventually saves their file, we do not rerun `go mod tidy` because the imports hash has not changed from the time the file was in overlay to the time the file was saved on disk. To be able to account for this, we need the invalidate the ModTidyKey when imports change between saves.

Change-Id: I9e210a15cf009d222cecd7824c2a1a927957483b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219477
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-04 14:31:13 +00:00
Ian Cottrell
c4206d458c internal/telemetry: change tracing to be event based
We no longer use the span as the core type of tracing, instead that is an
artifact of the exporter, and start and end tracing is just event based.
This both makes the interface normalized, and also means the null exporter case
is considerably cheaper in memory and cpu.
See below for benchstat changes

name                 old time/op    new time/op    delta
TracingNoExporter-8    4.19µs ±12%    2.71µs ±11%  -35.33%  (p=0.000 n=20+20)
Tracing-8              24.1µs ± 3%     5.1µs ±17%  -78.66%  (p=0.000 n=16+20)

name                 old alloc/op   new alloc/op   delta
TracingNoExporter-8    2.32kB ± 0%    0.40kB ± 0%  -82.76%  (p=0.000 n=20+20)
Tracing-8              6.32kB ± 0%    2.32kB ± 0%  -63.30%  (p=0.000 n=20+20)

name                 old allocs/op  new allocs/op  delta
TracingNoExporter-8      35.0 ± 0%      15.0 ± 0%  -57.14%  (p=0.000 n=20+20)
Tracing-8                 215 ± 0%        35 ± 0%  -83.72%  (p=0.000 n=20+20)

Change-Id: I3cf25871fa49584819504b5c19aa580e5dd03395
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221740
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-04 02:41:40 +00:00
Ian Cottrell
c5a1414753 internal/telemetry: add simple tracing benchmarks
These are just like the logging benchmarks but for tracing instead.
Also makes the log writer write out tracing events as well if it is
not in only errors mode

Change-Id: Ie00d7c80f7e2b9433787603261950f70ab1c1e9d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221739
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-03 22:57:24 +00:00
Ian Cottrell
3e346efd93 internal/telemetry: move the benchmarks to the main package
Change-Id: I9aabed798951ffba775c2255c8baafd56b009636
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221738
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-03 22:57:05 +00:00
Ian Cottrell
046aa1cdaf internal/telemetry: moving towards a unified event based exporter
This adds a type to events and makes the logging calls use it.

Change-Id: Iaa50fe2e332caae611b1e00424c878a3bc479feb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221741
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-03 22:56:52 +00:00
Ian Cottrell
a1c56757aa internal/telemetry: remove the concept of a Tagger
The Tagger interface allowed for specifying a key in a tag list and having the
value be aquired from the context automatically. It was almost never used, and
the alternative (using the key to get the value) is not that much more long
winded, so it was not holding it's own weight from a complexity persective alone
but the performance cost of having to use a list of interface rather than a list
of tags was very large. See the benchstat improvements below for the difference
it makes to both speed and memory usage, especially in the no exporter case.

name                 old time/op    new time/op    delta
Baseline-8              341ns ± 2%     342ns ± 1%     ~     (p=0.139 n=19+18)
LoggingNoExporter-8    2.46µs ± 5%    1.97µs ± 3%  -19.88%  (p=0.000 n=19+20)
Logging-8              13.3µs ± 2%    12.8µs ± 2%   -3.42%  (p=0.000 n=17+20)
LoggingStdlib-8        5.39µs ± 6%    5.34µs ± 3%     ~     (p=0.692 n=20+19)

name                 old alloc/op   new alloc/op   delta
Baseline-8              80.0B ± 0%     80.0B ± 0%     ~     (all equal)
LoggingNoExporter-8      728B ± 0%      440B ± 0%  -39.56%  (p=0.000 n=20+20)
Logging-8              2.75kB ± 0%    2.46kB ± 0%  -10.53%  (p=0.000 n=17+20)
LoggingStdlib-8          568B ± 0%      568B ± 0%     ~     (all equal)

name                 old allocs/op  new allocs/op  delta
Baseline-8               5.00 ± 0%      5.00 ± 0%     ~     (all equal)
LoggingNoExporter-8      32.0 ± 0%      23.0 ± 0%  -28.12%  (p=0.000 n=20+20)
Logging-8                88.0 ± 0%      79.0 ± 0%  -10.23%  (p=0.000 n=20+20)
LoggingStdlib-8          28.0 ± 0%      28.0 ± 0%     ~     (all equal)

Change-Id: Ic203ad0c5de7451348976b999a0d038ac532dc39
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221737
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-03 22:56:24 +00:00
Ian Cottrell
ae19ec7143 internal/telemetry: use atomics to get the exporter
We change the main exporter to be stored and fetched using atomics rather
than aquiring a mutex for a mild (but significant in the disabled case) speedup.
Also has the benefit of not holding a global lock over all telemetry operations.

benchstat of logging benchmatks before and after:

name                 old time/op    new time/op    delta
Baseline-8              329ns ± 2%     327ns ± 2%     ~     (p=0.181 n=19+17)
LoggingNoExporter-8    3.08µs ± 3%    2.42µs ± 2%  -21.42%  (p=0.000 n=20+19)
Logging-8              13.7µs ± 2%    13.2µs ± 1%   -3.49%  (p=0.000 n=19+19)
LoggingStdlib-8        5.39µs ± 3%    5.41µs ± 2%     ~     (p=0.177 n=19+20)

This is a replacement for https://go-review.googlesource.com/c/tools/+/212244
but built on the single exporter principle rather than the exporter list.

Change-Id: Icc99319c4357e0bcb63386c64372a733e8a76796
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221218
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-03-03 22:56:03 +00:00
Ian Cottrell
4183ba16a9 internal/lsp: move the debug.Instance onto the Context
This allows us to register a telemetry exporter that works with mulitple active
debug instances.
It also means we don't have to store the debug information in our other objects.

Change-Id: I9a9d5b0407c3352b6eaff80fb2c434ca33f4e397
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221558
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-03 22:54:53 +00:00
Rebecca Stambler
2b0b585e22 internal/imports: don't set a logger unless the user has provided it
Not sure why I thought it was a good idea to enable extra logging
by default, but this was added in CL 184198.

Fixes golang/go#37636

Change-Id: I1840a9e53625db99c9097f2c23500ae20d6dac1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221918
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-03-03 21:46:25 +00:00
Rohan Challa
55b754b4e0 internal/lsp: fix active param in signature help
This change adjusts where the start and end of the arguments list are when determining which parameter is the active paramter. Rather than use the first and last argument's position, we will use the start and ending parentheses.

Fixes golang/go#37271

Change-Id: I70bc5c8b4bdb5242fc35a20e63b9a8860cb1d6bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221817
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-03 19:47:17 +00:00
Rohan Challa
115860e962 internal/lsp: fix concurrent map read/write for missingmodules
This change fixes an issue with concurrent map reads and writes that occurred when determining if an import is missing the corresponding dependency in the go.mod file.

Change-Id: Ic5cf3a620b4fd84eb4a377d0e4c22edbc8f37540
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221897
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-03 19:46:16 +00:00
Heschi Kreinick
5bcca83a78 internal: rationalize debug logging
In all cases, use a Logf field to configure debug logging. Non-nil means
that logging is enabled through the given function.

Fixes accidental debug spam from goimports, which had a separate Debug
flag that was supposed to guard logging, but wasn't used when creating
the gocommand.Invocation.

Change-Id: I448fa282111db556ac2e49801268d0affc19ae30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221557
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-03 16:59:18 +00:00
Rohan Challa
9b52d559c6 internal/lsp/regtest: add a test for diagnostics on first file
This change adds a test for diagnostics not disappearing when you create the first .go file for a project and add an import, then save.

Updates golang/go#37195

Change-Id: I871e77d9ab129f13be58931fe009e4297c7f2b38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221222
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-02 22:55:59 +00:00
Rohan Challa
c4f5635f10 internal/lsp: add an upgrade all dependencies codelens
This change adds an upgrade all dependencies codelens on the go.mod file if there are available upgrades.

Updates golang/go#36501

Change-Id: I86c1ae7e7a6dc01b7f5cd7eb18e5a11d96a3acc1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221108
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-02 21:30:18 +00:00
Muir Manders
8d77031968 internal/lsp/source: fix completion crash with untyped assignee
We were panicking when a LHS assignee's type was nil, such as:

    // "foo" has not been declared
    foo = 123

A recent refactoring changed (*completer).typeMatches() to no longer
gracefully handle a nil types.Type for its first parameter. That
behavior seems fine, so fix the problematic caller of typeMatches to
check for nil before calling.

Change-Id: Ie11e4a2d374ab1efbf6fd13fbe214e06d359fca0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221020
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-02 21:29:26 +00:00
Muir Manders
ae0473a2ca internal/lsp/source: support inverse "implementations"
Now "implementations" supports finding interfaces implemented by the
specified concrete type. This is the inverse of what "implementations"
normally does. There isn't currently a better place in LSP to put this
functionality. The reverse lookup isn't an important feature for most
languages because types often must explicitly declare what interfaces
they implement.

An argument can be made that this functionality fits better into find-
references, but it is still a stretch. Plus, that would require
find-references to search all packages instead of just transitive
dependents.

Updates golang/go#35550.

Change-Id: I72dc78ef52b5bf501da2f39692e99cd304b5406e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219678
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-03-02 21:28:54 +00:00
Rob Findley
49e4010bbf internal/lsp/regtest: implement formatting and organizeImports
Add two new fake editor commands: Formatting and OrganizeImports, which
delegate to textDocument/formatting and textDocument/codeAction
respectively. Use this in simple regtests, as well as on save.

Implementing this required fixing a broken assumption about text edits
in the editor: previously these edits were incrementally mutating the
buffer, but the correct implementation should simultaneously mutate the
buffer (i.e., all positions in an edit set refer to the starting buffer
state). This never mattered before because we were only operating on one
edit at a time.

Updates golang/go#36879

Change-Id: I6dec343c4e202288fa20c26df2fbafe9340a1bce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221539
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-03-02 19:16:53 +00:00
Rob Findley
9aa23abf06 internal/lsp/regtest: consolidate Env wrappers
Helper functions on the regtest.Env wrapping workspace or editor
functionality are moved to a new wrappers.go file.

Also, rename 'WriteBuffer' to 'SaveBuffer', for less confusion with
'WriteFile'.

Change-Id: Ide9a5cf919dcee6e4a4fbfdb167eddf751a26eeb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221538
Reviewed-by: Rohan Challa <rohan@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-02 19:06:06 +00:00
Pontus Leitzler
7ae42e3a8b internal/lsp/debug: add nil checks in debug page
There are missing nil checks in a few places when using the gopls
debug page. It will result in panics when trying to access a debug
page that no longer exist (for example a closed session).

This change adds nil checks and updates the template to not render
non-existing debug address.

Change-Id: Ic9163f3727fd8c51122cbd4ab4374fc4d55477c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221699
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-03-02 15:51:55 +00:00
Pontus Leitzler
066e0c0245 internal/lsp/lsprpc: use localhost for remote gopls debug interface
When using the experimental feature where gopls runs as deamon, the
remote is spawned with debug enabled. It currently exposes the debug
interface to all network interfaces. This should be configurable in
the future, but until then we should at least keep it on the
localhost interface.

This change starts the debug on the local interface instead of all.

Updates golang/go#34111

Change-Id: I3184268dd434ae11ff5f8c3c57a229d22c158196
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221697
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-01 22:23:51 +00:00
Ian Cottrell
71482053b8 internal/telemetry: remove Flush method from exporter
It is never invoked anyway, and it provices no useful benefit while complicating
the implementation, as it is the only non context aware method.

Change-Id: Id5a99439fedafdf4d71285e36103b4854cf3635a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221540
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-02-28 22:46:39 +00:00
Heschi Kreinick
b3f10971cb internal/fastwalk: fix checkptr failure on Darwin
Darwin's syscall.Dirent is declared as larger than the kernel may
actually return. Don't assume that we can copy the whole thing out of a
buffer.

Fixes golang/go#37269

Change-Id: I7f2b273f3a14071df8b5ff5bd70e59d784f6d187
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221381
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-27 19:33:42 +00:00
Rob Findley
afe1c6fc1b internal/lsp/regtest: remove calls to t.Parallel()
Originally I decided to use t.Parallel() in hopes of uncovering new
bugs. That may have worked... but manifested as rare flakes that are
difficult to diagnose (golang.org/issues/37318).

Since this level of parallelism is extremely unlikely in normal gopls
workloads, I'm going to remove the t.Parallel() calls in hopes of
eliminating this flakiness. I'd rather be able to continue running these
tests.

Also, don't run in the 'Shared' execution mode by default: normal gopls
execution is either as a sidecar (the Singleton execution mode), or as a
daemon (the Forwarded execution mode).

Un-skip the TestGoToStdlibDefinition test, as hopefully it will no
longer flake.

Updates golang/go#37318.

Change-Id: Id73ee3c8702ab4ab1d039baa038fbce879e38df8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221379
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-27 18:46:34 +00:00
Rebecca Stambler
204d844ad4 internal/lsp: mitigate possiibility of a slow code action
Related to https://github.com/microsoft/vscode-go/issues/3063.
A small collection of fixes: (1) Don't reload packages with missing
dependencies unless imports change. (2) Show the error message from the
initial workspace load to the user.

Also, a small fix for deletion suggested fixes - upgrading to the latest
version of the VS Code language client revealed that I had made a
mistake there.

Change-Id: I7ab944ed27dc3da24a79d5d311531a1eb2b73102
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-26 22:45:02 +00:00
Ian Cottrell
2e887e3d13 internal/telemetry: removing the concept of exporter lists
Instead we only have a single exporter, and it must delegate behaviour
to any other exporters it wants to include.
This removes a whole collection of suprises caused by init functions adding
new exporters to a list, as well as generally making things faster, at the small
expense of needing to implement a custom exporter if you want to combine the
features of a few other exporters.

This is essentially the opposite of https://go-review.googlesource.com/c/tools/+/212243
which will now be abandoned in favor of this approach.

Change-Id: Icacb4c1f0f40f99ddd1d82c73d4f25a3486e56ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220857
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-26 21:51:01 +00:00
Rebecca Stambler
eb7c56241b internal/lsp: remove unknown dependency from highlight tests
The highlight tests imported golang.org/x/tools/internal/lsp/protocol
package, which doesn't exist when the testdata is set up in the test
harness. This causes gopls to try to reload the metadata for the
package. I'm not sure why this wasn't an issue before, since we should
re-run go/packages.Load every time we have missing dependencies.

Fixes golang/go#37365

Change-Id: I8ebcbbf78b7e6fcdac9ab83bef3f5a0c9a50a361
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221107
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-26 20:52:01 +00:00
Anthony Fok
26f6a1b680 internal/lsp/source: fix typo: identifer → identifier
Change-Id: I37da513eb4a28df5054066b94ff1d915b9dce239
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221022
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-02-26 18:09:45 +00:00
Rebecca Stambler
020676185e internal/lsp: replace mistaken "break" with "continue"
I had meant to continue instead of break this loop. This caused us to
invalidate all IDs (except for those for one file) every time a snapshot
was cloned.

Picked up a staticcheck fix along the way.

Change-Id: I8fb3b2bdd6b58ac21130e01cb0d32fa6a57e6b73
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221103
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
2020-02-26 17:12:34 +00:00
Rohan Challa
abb57c682a internal/lsp: support textDocument/hover for .mod extension
This change implements support for textDocument/hover when it comes to go.mod files.

Updates golang/go#36501

Change-Id: Ie7da0194bb972955b7ab9cf7b9c9972bd9f4b8a9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220359
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-26 15:59:49 +00:00
Rohan Challa
48cfad2f5e internal/lsp: support textDocument/documentLink for .mod extension
This change implements support for textDocument/documentLink when it comes to go.mod files.

Updates golang/go#36501

Change-Id: Ic0974e3e858dd1c8df54b7d7abee085bbcb6d4ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219938
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-26 15:45:04 +00:00
Rebecca Stambler
807dcd8834 internal/lsp: invalidate package IDs along with metadata
We had previously only added to a list of package IDs, rather than
invalidating package IDs along with metadata. This is because we loaded
packages by file, rather than by package path or workspace. Now that we
load by workspace, we can invalidate package IDs. This will avoid the
issue of lingering "command-line-arguments" IDs.

Fixes golang/go#37213

Change-Id: I21830219efaf0df9531e9d811ccbc3f141c0cbcb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-25 23:00:52 +00:00
Heschi Kreinick
c099ead939 internal/lsp/source: limit WorkspaceSymbols results
Searching with an empty string shouldn't return every symbol in the
workspace -- nobody wants that. Limit to 100 results to avoid breaking
editors. (VS Code locks up for like 30 seconds on my workspace.)

Change-Id: I1e0be476e8eeaef9e69767bfa04a89d40bd3a6e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220939
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 21:59:15 +00:00
Heschi Kreinick
7c03e3340d internal/gocommand: kill gracefully
We want the go command to get a chance to do its cleanups. Send it
Interrupt before Kill.

Fixes golang/go#37368.

Change-Id: Id891d2f4f85aae30d2aaa19b9c854d2346ec6e1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220738
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 21:33:51 +00:00
Heschi Kreinick
c5cec6710e all: consolidate invokeGo implementations
Over time we have accumulated a disturbing number of ways to run the Go
command, each of which supported slightly different features and
workarounds. Combine all of them.

This unavoidably introduces some changes in debug logging behavior; I
think we should try to fix them incrementally and consistently.

Updates golang/go#37368.

Change-Id: I664ca8685bf247a226be3cb807789c2fcddf233d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220737
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 21:33:46 +00:00
Rob Findley
fefc8d1877 internal/lsp/regtest: clean-up and more error handling
Fix various things related to regtest execution:
 + Check the error from OpenFile in fake.Editor.GoToDefinition.
 + Add an error-checked wrapper to env for CloseBuffer.
 + Use env wrappers in TestDiagnosticClearingOnClose.
 + Use os.Executable to get the test binary path.
 + Add a -listen.timeout to the remote gopls process, so that it is
   cleaned up.

Updates golang/go#36879

Change-Id: I056ff50bdb611a78ad78e4f5e2a94a4f155cc9de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220902
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 19:00:36 +00:00
Heschi Kreinick
6bd7a38086 internal/imports: filepath.Clean module Dirs
Various bits of the module code use HasPrefix, which only works if all
paths are clean. Make sure they are.

No test; this is pretty esoteric and it's not easy to test.

Fixes golang/go#36193.

Change-Id: I8c8e87d1882d149a1a129d8b7123bc95c115b2ad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220659
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 18:45:58 +00:00
Rob Findley
45849e8256 internal/lsp/lsprpc: wait for the handshake before running clientConn
By running the client connection before the forwarder-remote handshake
completes, we introduce a race in the TestDebugInfoLifecycle: the editor
may connect and initialize before the handshake, and assertions on the
debug state fail.

Requiring that the handshake complete before running the client
connection fixes this flakiness. It also seems like a good thing to
have the handshake complete before proceeding with any LSP.

Fixes golang/go#37444

Change-Id: I07187797b4759bcaf99f5b0a0b3cd7ac7de34f43
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220903
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-02-25 18:38:23 +00:00
Rebecca Stambler
df82bb964a internal/lsp: add a test for internal imports handling
I'm still not sure if we need to handle any other non-standard package
path apart from "command-line-arguments".

Also, a couple of staticcheck fixes.

Change-Id: I0bb3e60f6ffe104ff9027dbebb628020caaa1af4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220138
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-25 18:38:19 +00:00
Ian Cottrell
a0ec867d51 internal/telemetry: add a benchmark with a null writer for comparison
Make all the benchmarks cleanly pass around the context to remove a non logging
difference.
Rename the non logging calls benchmark to Baseline

Change-Id: I24a33b0a817df403fb43c53b5f097bc1e9418af4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220520
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-02-25 02:20:59 +00:00
Rob Findley
daf22849ce internal/lsp/lsprpc: add a 1m timeout to auto-started gopls
It would be bad behavior if a gopls forwarder process started the gopls
daemon and it stuck around indefinitely. Add an idle timeout by default
for the gopls daemon.

Updates golang/go#34111

Change-Id: I0408a1e6a3b89d862803ae5c439d6aa0d8ed9494
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220521
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 23:36:36 +00:00
Rob Findley
63caf62cea internal/lsp/lsprpc: clean up client session on disconnection
Gopls behavior on disconnection is currently somewhat undefined, because
it hasn't mattered when there was a single gopls session per binary
invocation. With golang/go#34111, this changes.

Checks are added to ensure clients and sessions are cleaned up when an LSP
connection closes. Also, normal client disconnection is differentiated
with the jsonrpc2.ErrDisconnected value.

Updates golang/go#34111

Change-Id: I74d48ad6dcfc30d11f7f751dcffb20c18a4cbaa3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220519
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 23:23:05 +00:00
Rob Findley
9ffc0ab4ef internal/jsonrpc2: add an idle timeout for stream serving
When running gopls against an automatically started remote instance, we
want the lifecycle of the remote to be detached from that of its
clients, so that it doesn't shut down while clients are still connected.
On the other hand, a gopls process can consume significant resources, so
we don't want it to remain when there are no more connected clients.

The jsonrpc2 package is updated to support the concept of idle timeout:
a duration after which the server is shut down when there are no
connected clients. This is exposed in the gopls serve command via the
-listen.timeout flag.

Update golang/go#34111

Change-Id: Id62b3d4a2fa66de2c9306d130ca431717f01d1e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220281
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 23:06:35 +00:00
Rob Findley
a208025ccb internal/lsp/lsprpc: automatically resolve and start the remote gopls
Most users will not want to manage their own gopls instance, but may
still want to benefit from using a shared instance.

This CL adds support for an 'auto' network type that can be encoded in
the -remote flag similarly to UDS (i.e. -remote="auto;uniqueid"). In
this mode, the actual remote address will be resolved automatically
based on the executing environment and unique identifier, and the remote
server will be started if it isn't already running.

Updates golang/go#34111

Change-Id: Ib62159765a108f3645f57709b8ff079b39dd6727
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220137
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 22:51:55 +00:00
Rob Findley
20f46356b3 internal/lsp/lsprpc: add a handshake between forwarder and remote
In the ideal future, users will have one or more gopls instances, each
serving potentially many LSP clients. In order to have any hope of
navigating this web, clients and servers must know about eachother.

To allow for such an exchange of information, this CL adds an additional
handler layer to the serving configured in the lsprpc package. For now,
forwarders just use this layer to execute a handshake with the LSP
server, communicating the location of their logs and debug addresses.

Updates golang/go#34111

Change-Id: Ic7432062c01a8bbd52fb4a058a95bbf5dc26baa3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220081
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 22:51:04 +00:00
Rob Findley
e02f5847d1 internal/lsp/debug: move all debug state onto the Instance
For testability, and to support the exchange of debug information across
Forwarder and server, it is helpful to encapsulate all debug information
on the instance object.

This CL moves all state in the debug package into a new 'State' type,
that is added as a field on the debug.Instance. While doing so, common
functionality for object collections is factored out into the objset
helper type.

Also add two new debug object types: Client and Server. These aren't yet
used, but will be in a later CL (and frankly it was easier to leave them
in this CL than to more carefully rewrite history...).

Updates golang/go#34111

Change-Id: Ib809cd14cb957b41a9bcbd94a991f804531a76ea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220078
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-24 22:50:47 +00:00
Muir Manders
023911ca70 internal/lsp/source: untangle completion type comparison
The code to check if a candidate object matches our candidate
inference had become complicated, messy, and in some cases incorrect.
The main source of the complexity is the "derived" expected and
candidate types. When considering a candidate object "foo", we also
consider "&foo", "foo()", and "*foo", as appropriate. On the expected
side of things, when completing the a variadic function parameter we
expect either the variadic slice type and the scalar element type.

The code had grown organically to handle the expanding concerns, but
that resulted in confused code that didn't handle the interplay
between the various facets of candidate inference.

For example, we were inappropriately invoking func candidates when
completing variadic args:

    func foo(...func())
    func bar() {}
    foo(bar<>) // oops - expanded to "bar()"

and we weren't type matching functions properly as builtin args:

    func myMap() map[string]int { ... }
    delete(myM<>) // we weren't preferring (or invoking) "myMap()"

We also had methods like "typeMatches" which took both a "candidate"
object and a "candType" type, which doesn't make sense because the
candidate contains the type already.

Now instead we explicitly iterate over all the derived candidate and
expected types so they are treated the same. There are still some
warts left but I think this is a step in the right direction.

Change-Id: If84a84b34a8fb771a32231f7ab64ca192f611b3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218877
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-02-24 18:12:40 +00:00