1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00
Commit graph

26 commits

Author SHA1 Message Date
Sam Herrmann
8012d49686
Add ability to omit params member from request (#62)
The JSON-RPC 2.0 specification allows the params member of a request to
be omitted [1]. Before this commit, this library did not allow the
params member to be omitted when sending a request. When the params
argument of the Conn.Call/Conn.DispatchCall or Conn.Notify method was
set to nil, then Request.Params was set to the JSON encoding of nil
which is null.

This commit adds a CallOption named OmitNilParams. If OmitNilParams is
used when sending a request with params set to nil, then the params
member in the JSON encoding of Request is omitted. If the OmitNilParams
option is not used then the previous behavior is maintained. In other
words, the changes in this commit are backwards compatible.

References
[1]: https://www.jsonrpc.org/specification#request_object
2023-01-24 08:47:36 +02:00
Semesse
e1f9fdf1bb
fix no corresponding request if req.ID is modified by onSend (#60) 2023-01-13 20:33:58 +02:00
lhchavez
5f298fe6a1
Homogenize treatment of params and meta in UnmarshalJSON (#52)
This change makes the treatment of params and meta the same, by
assigning a well-known pointer at first to detect if the unmarshaling
process overwrites it with an explicit nil, or it stays the same in
which it means that it was unset from the beginning.
2021-08-04 18:55:02 +02:00
lhchavez
d6ac66e24f
Add a way to specify more non-standard-compliant fields to Request (#50)
This change introduces `ExtraField`, a `CallOption` that can add
arbitrary fields to the top-level JSON-RPC Request message.
2021-08-04 14:45:59 +02:00
Sam Herrmann
08fd77d0de
Add StringID call option (#44)
Fixes #43
2021-04-26 09:12:26 +02:00
Cornelius Weig
366fbb5207
Break the Call method into a dispatcher and waiter (#41)
Before, the Call method dispatched the JSON-RPC request and waited
until completion of the request before returning. This made it difficult
to release any locks that need to be released upon dispatch.

Now, the Call method is broken into a DispatchCall and Wait pair.
DispatchCall returns a proxy to the internal call object as soon as the
request is dispatched. When appropriate, the caller can invoke the Wait
method on this proxy to block until the result is ready.

The original Call method is not changed, but now implemented by
these primitives.
2021-02-01 10:28:50 +02:00
s3rj1k
3bf62ad25c fix Using a reference for the variable on range scope (#32)
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-04 13:57:41 -08:00
s3rj1k
6053545ad1 use custom logger for internal logging
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-03 22:30:34 +02:00
Quinn Slack
375ca94e9c add go module, simplify some cleanups 2019-11-02 21:39:58 -07:00
s3rj1k
456318691a fix some golangci-lint, revive linter warnings
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
2019-11-02 22:31:31 +02:00
Ggicci
3e2e814648 fix: don't apply nil CallOption and ConnOpt 2019-01-07 01:47:28 +08:00
Keegan Carruthers-Smith
a3d86c792f allow multiple OnRecv and OnSend 2018-05-01 19:02:17 +01:00
Ondřej Kupka
c6c7b9aa99 Response: Add omitempty tag for Result (#14)
The 'result' key MUST be unset according when the error key is set.
This is not what is happening right now. When the error is set,
"result":null is returned in the response payload. This patch is fixing
the issue by adding omitempty for the result field.
2017-08-02 20:50:46 +02:00
Keegan Carruthers-Smith
3a7c446248 Handle is blocking (#12)
NOTE: This is a breaking change to the expected contract of Handler. Please update your implementation to use AsyncHandler if needs be.

We have strict ordering requirements of how we handle FileSystem requests in
LSP. As such relying on the ordering the goroutine scheduler runs requests in
leads to potential out of order mutations to the FS. As such we update the
jsonrpc2 implementation to by default block until Handle returns (note it can
still respond to the request at a later stage). For more simple use cases we
provide the AsyncHandler which will work like the previous implementation.

* Ensure handle is blocking
2017-02-21 14:25:50 +02:00
Keegan Carruthers-Smith
955f217b74 Add Meta field to Response (#10) 2017-02-20 14:21:08 +02:00
Keegan Carruthers-Smith
4fb7cd9079 Add CallOpt SetID
SetID allows a caller to control the ID of the request. Previously it was
impossible to set the ID of a call.
2017-01-31 11:08:53 +02:00
Quinn Slack
cffa092597 better null handling in (Request).params and (Response).result (#7)
This makes the MarshalJSON/UnmarshalJSON methods centralize the logic, instead of requiring callers to occasionally munge responses to make them valid to later JSON-marshal.
2017-01-26 02:18:31 -08:00
Quinn Slack
64d0b93a7a propagate JSON "null" result instead of treating it as Go nil (and field-not-present in JSON) 2017-01-22 16:05:00 -08:00
Quinn Slack
a61d8f7bd7 warn when marshaling invalid Response 2017-01-22 15:45:18 -08:00
Quinn Slack
d58e8cc226 support responses with null result ({"result":null})
Previously, we incorrectly interpreted these as neither a request nor a response, and we printed an error for them. This is incorrect behavior per JSON-RPC 2.0 spec; responses can have a null result.
2017-01-22 15:34:05 -08:00
Quinn Slack
6e06d561ec Add pluggable transport interface + WebSocket support
simplify API by using interface{}, rename from transport -> stream

add WebSocket transport in websocket subpackage

do not buffer in ReadObject, rename GetObjectReader/ReadObject -> NextObjectReader

use xtest (jsonrpc2_test) package to allow us to test subpackages that depend on us (in a future change)

factor out vscode-specific transport code and allow pluggable transports

remove Server (unused) and Serve (unnecessary):
  The Serve func had nothing specific to JSON-RPC; it was just a loop
  around (net.Listener).Accept. It added no value.
2016-12-17 18:35:34 -08:00
Richard Musiol
9fdd802ab4
make call.done channel buffered so it can discard its value if the call got cancelled 2016-11-22 13:21:59 +01:00
Quinn Slack
6416f80f8f support string request IDs (in addition to numeric request IDs) 2016-11-06 07:12:05 -08:00
Quinn Slack
0328ebe20e remove incomplete JSON-RPC 2.0 batch support 2016-11-06 06:51:04 -08:00
Beyang Liu
3b45ab3a66 add JSONRPC2 interface 2016-10-28 16:33:31 -07:00
Quinn Slack
c04eec1600 initial commit 2016-10-11 15:56:18 +02:00