Skip to content

Commit 0cdb5b0

Browse files
Update docs
1 parent 237a57f commit 0cdb5b0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ Note that the use of these multimethods is deprecated and they will be removed i
5959

6060
The return value of requests will be converted to camelCase json and returned to the client. If the return value looks like `{:error ...}`, it is assumed to indicate an error response, and the `...` part will be set as the `error` of a [JSON-RPC error object](https://www.jsonrpc.org/specification#error_object). It is up to you to conform the `...` object (by giving it a `code`, `message`, and `data`.) Otherwise, the entire return value will be set as the `result` of a [JSON-RPC response object](https://www.jsonrpc.org/specification#response_object). (Message ids are handled internally by lsp4clj.)
6161

62+
### Middleware
63+
64+
For cross-cutting concerns of your request and notification handlers, consider middleware functions:
65+
66+
```clojure
67+
(defn wrap-vthread
68+
"Middleware that executes requests in a virtual thread."
69+
[handler]
70+
(fn [method context params]
71+
(promesa.core/vthread (handler method context params))))
72+
73+
;; ...
74+
75+
(defmulti receive-request (fn [method _ _] method))
76+
77+
(def server (server/chan-server {:request-handler (wrap-vthread #'receive-request)}))
78+
```
79+
6280
### Async requests
6381

6482
lsp4clj passes the language server the client's messages one at a time. It won't provide another message until it receives a result from the message handlers. Therefore, by default, requests and notifications are processed in series.

src/lsp4clj/server.clj

+3
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@
459459
460460
Other options:
461461
462+
- `response-executor` is value supported by Promesa to specify an executor
463+
to handle client responses to server-initiated requests. When none is
464+
specified, uses `:default`, which is mapped to `(ForkJoinPool/commonPool)`.
462465
- `clock` is a `java.time.Clock` that provides the current time for trace
463466
messages.
464467
- `on-close` is a 0-arg fn that the server will call after it has shut down."

0 commit comments

Comments
 (0)