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

76 Commits

Author SHA1 Message Date
Rebecca Stambler
cf97b7f4a4 internal/lsp: support go1.12
We still don't have a good way to make sure that we don't break 1.12
support, but this is an easy enough fix to start with.

Updates golang/go#39146

Change-Id: I14fe997fa1f3d60320d77e664208e25d97ae6f4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/243578
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-07-20 15:02:56 +00:00
Thomas
dcbf2a9ed1 internal/jsonrpc2: omit empty error data
The spec states error data may be omitted. It is currently always encoded
as null, despite having no usage.

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

Fixes golang/go#39736

Change-Id: Icdb39409010f3a42f84d2372c2061e4bc7cc198e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239059
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-24 06:08:01 +00:00
Ian Cottrell
fcc5b64fe1 internal/jsonrpc2: don't set result in response if there is an error
Marshalling an empty raw message produces a null rather than omitting the field
Instead we do not set the field unless there is no error.
Includes a test that reproduced the issue before the fix.

Fixes golang/go#39719

Change-Id: I683b8ea55d3425613fc956993280ff51202f49fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239097
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-22 15:00:58 +00:00
Rob Findley
9b4b92067d internal/jsonrpc2/servertest: replace closerList with connList
closerList was already unnecessarily abstract, and tracking connections
will allow us to also wait for all connections to finish.

Share functionality by embedding this type in PipeServer, TCPServer.

Change-Id: Ib2cb2157c1477f904bc278aa91902f5c633afe13
Reviewed-on: https://go-review.googlesource.com/c/tools/+/238547
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-06-18 12:08:28 +00:00
Rob Findley
e258ba4578 internal/jsonrpc2/servertest: minor improvements for closing
Return an actual error when closing the test server, and close at the
jsonrpc2.Conn level, rather than at lower levels.

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

Updates golang/go#39130

Change-Id: I6ebe61100501f69c7490b418f53871b4e9704a00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237582
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2020-06-11 19:17:06 +00:00
Ian Cottrell
ef124de36d internal/jsonrpc2: change StreamServer to operate on Conn instead of Stream
Really the name is wrong now, but this is just a stepping stone towards removing
it entirely in favour of a new listener/dialer/server/client pattern, so I am
minimizing the churn by leaving the names alone for now.

Change-Id: I771d117490763ebe05ed2a8c52d490deeb4d5333
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232878
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-03 17:07:01 +00:00
Ian Cottrell
d3396bb197 internal/jsonrpc2: change jsonrpc2.Conn to be an interface
This will allow varying implementations and wrappers, and more
closely matches the concepts used in the net library.

Change-Id: I4be4c6efb3def0eda2693f482cbb0c6f776e5642
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232877
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-03 17:06:45 +00:00
Ian Cottrell
8a3674bff3 internal/lsp: change exit handling
Exit now closes the connection rather than exiting the process.
This allows things to shutdown gracefully, and removes special
cases. It also allows the tests to call CloseEditor instead of
just Shutdown, which prevents goroutine leaks.

Change-Id: I26121ba5d393ef74ce0e912611c8b3817e3691ea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231798
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-03 13:14:19 +00:00
Ian Cottrell
cc40288be8 internal/lsp: change logging stream to be a framer
Change-Id: Id9e17e98ca00f31424068e875851b5f9008c6fe8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231797
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-03 13:12:46 +00:00
Ian Cottrell
9089ff1aee internal/jsonrpc2: switch to building streams on top of net.Conn
This allows us to rely on higher level functionality like timeouts and
close cancelling pending reads cleanly.

Change-Id: I3a43d21ed35d3da1eb818ea22f8d02201488a1d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/230464
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-06-03 13:12:18 +00:00
Ian Cottrell
e84ca95fee internal/jsonrpc2: add the ability to close connections
Also the ability to wait for them to correctly close.

Change-Id: I198c9e24a21c04d5c05bae7a4a0f503429ab0346
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231699
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-06-03 13:11:45 +00:00
Ian Cottrell
688b3c5d9f internal/jsonrpc2: Add Close method to Stream.
Also switched the internals of the stream implementations to using
net.Conn to enable asynchronous closing, not yet exposed int the API.

Change-Id: I57f1c36e7a46729d24f4339ba2fecc3f868e823f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/231698
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
2020-05-27 15:00:44 +00:00
Ian Cottrell
dd5f9d1033 internal/stack: add the leak test
This adds a package for dealing with stacks in tests.
The only function at this time is NoLeak which verifies that a test
does not leak any goroutines, and prints a stack summary if it does.

Change-Id: I284b846f422334b745bef0e96d84138295120a62
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232681
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-05-27 14:25:42 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
66de428735 internal/jsonrpc2,internal/lsp/regtest: clean up some leaked tempfiles
Not all regtests resulted in LSP shutdown, which caused temp modfiles to
be leaked. After this fix I have confirmed that /tmp is clean after a
successful run of the regtests.

Also proactively clean up the unix socket file when serving jsonrpc2
over UDS.

Change-Id: I745fbd3d2adeeb165cadf7c54fd815d8df81d4e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/220061
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 18:32:50 +00:00
Rob Findley
5fb17a1e7b internal/jsonrpc2: support serving over unix domain sockets
For tests (and perhaps later, for daemon discovery), unix domain sockets
offer advantages over TCP: we can know the exact socket address that will be
used when starting a server subprocess. They also offer performance and
security advantages over TCP, and were specifically requested on
golang.org/issues/34111.

This CL adds support for listening on UDS, and uses this to implement an
additional regtest environment mode that starts up an external process.
This mode is disabled by default, but may be enabled by the
-enable_gopls_subprocess_tests.

The regtest TestMain may be hijacked to instead run as gopls, if a
special environment variable is set. This allows the the test runner to
start a separate process by using os.Argv[0]. The -gopls_test_binary
flag may be used to point tests at a separate gopls binary.

Updates golang/go#36879
Updates golang/go#34111

Change-Id: I1cfdf55040e81ffa69a6726878a96529e5522e82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218839
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-19 16:14:01 +00:00
Rob Findley
b320d3a0f5 internal/jsonrpc2/servertest: support both TCP and pipe connection
Update the servertest package to support connecting to a jsonrpc2 server
using either TCP or io.Pipes. The latter is provided so that regtests
can more accurately mimic the current gopls execution mode, where gopls
is run as a sidecar and communicated with via a pipe.

Updates golang/go#36879

Change-Id: I0e14ed0e628333ba2cc7b088009f1887fcaa82a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/218777
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-16 19:22:41 +00:00
Rob Findley
88be01311a internal/jsonrpc2: fix races in cancellation
We had a deadlock in cases where a request was cancelled (1) after being
written to the stream, but (2) before a response was received. This
resulted in the request ID being removed from the pending map while the
server has the request, after which point the server response would hang
in Conn.Run trying to send to a nil channel.

After fixing this nil send there was still a race: it was possible that
Conn.Run could get the pending request, and Conn.Call would select
ctx.Done before Conn.Run could send to the response channel, again
resulting in a blocking send. Fix this by adding a buffer to the
response channel.

The response channel management is also made less forgiving, because we
should be able to reason precisely about how many sends and receives
will occur:
 + Don't close the response channel after sending a response: there
   should only be one recipient.
 + Don't delete the ID from pending map twice: it should only be cleaned
   up by Conn.Call.

Cancellation tests in the lsprpc package are updated to exercise the
race conditions.

Fixes golang/go#37159

Change-Id: Ie3207442ea910f79247b18d8647fd52f39fb15db
Reviewed-on: https://go-review.googlesource.com/c/tools/+/219126
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-02-14 14:43:24 +00:00