You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+20-10
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,9 @@ lsp4clj reads and writes from io streams, parsing JSON-RPC according to the LSP
13
13
To initialize a server that will read from stdin and write to stdout:
14
14
15
15
```clojure
16
-
(lsp4clj.io-server/stdio-server)
16
+
(lsp4clj.io-server/stdio-server
17
+
{:request-handler receive-request
18
+
:notification-handler receive-notification})
17
19
```
18
20
19
21
The returned server will have a core.async `:log-ch`, from which you can read server logs (vectors beginning with a log level).
@@ -27,20 +29,28 @@ The returned server will have a core.async `:log-ch`, from which you can read se
27
29
28
30
### Receive messages
29
31
30
-
To receive messages from a client, lsp4clj defines a pair of multimethods, `lsp4clj.server/receive-notification` and `lsp4clj.server/receive-request` that dispatch on the method name (as defined by the LSP spec) of an incoming JSON-RPC message.
32
+
To receive messages from a client, lsp4clj defines a pair of handlers: the `:request-handler`
33
+
and the `:notification-handler`, which should be passed to the server constructor.
31
34
32
-
Server implementors should create `defmethod`s for the messages they want to process. (Other methods will be logged and responded to with a generic "Method not found" response.)
35
+
These handlers receive 3 arguments, the method name, a "context", and the `params` of the [JSON-RPC request or notification object](https://www.jsonrpc.org/specification#request_object). The keys of the params will have been converted (recursively) to kebab-case keywords. Read on for an explanation of what a "context" is and how to set it.
33
36
34
-
These `defmethod`s receive 3 arguments, the method name, a "context", and the `params` of the [JSON-RPC request or notification object](https://www.jsonrpc.org/specification#request_object). The keys of the params will have been converted (recursively) to kebab-case keywords. Read on for an explanation of what a "context" is and how to set it.
37
+
When a message is not understood by the server, these handlers should return the value `:lsp4clj.server/method-not-found`. For requests, lsp4clj will then report an appropriate error message to the client.
38
+
39
+
lsp4clj provides two multimethods as default handlers, `lsp4clj.server/receive-notification` and `lsp4clj.server/receive-request`, that dispatch on the method name (as defined by the LSP spec) of an incoming JSON-RPC message. Instead of passing custom `:request-handler` and `:notification-handler` options when creating the server, implementors can create `defmethod`s for the messages they want to process. (Other methods will be logged and responded to with a generic "Method not found" response.)
40
+
41
+
Note that the use of these multimethods is deprecated and they will be removed in a future release of lsp4clj. New code should pass their own handlers instead, potentially defining their own multimethod.
;; client may cancel request while we are waiting for analysis
@@ -187,7 +197,7 @@ You must not print to stdout while a `stdio-server` is running. This will corrup
187
197
188
198
Fromexperience, it'sdismayinglyeasytoleaveinanerrant `prn` or `time` andendupwithanon-responsiveclient.Forthisreason, wehighlyrecommendsupportingcommunicationoversockets (see [other types of servers](#other-types-of-servers)) whichareimmunetothisproblem.However, sincethechoiceofwhethertousesocketsorstdioisultimatelyuptotheclient, youmayhavenochoicebuttosupportboth.
189
199
190
-
lsp4cljprovidesonetooltoavoidaccidentalwritestostdout (or rather to `*out*`, which is usually the same as `System.out`).Toprotectablockofcodefromwritingto `*out*`, wrapitwith `lsp4clj.server/discarding-stdout`.The`receive-notification`and`receive-request` multimethodsarealreadyprotectedthisway, buttasksstartedoutsideofthesemultimethodsorthatruninseparatethreadsneedthisprotectionadded.
200
+
lsp4cljprovidesonetooltoavoidaccidentalwritestostdout (or rather to `*out*`, which is usually the same as `System.out`).Toprotectablockofcodefromwritingto `*out*`, wrapitwith `lsp4clj.server/discarding-stdout`.Therequestandnotificationhandlersarealreadyprotectedthisway, buttasksstartedoutsideofthesehandlersorthatruninseparatethreadsneedthisprotectionadded.
0 commit comments