Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdinand-beyer committed Aug 12, 2024
1 parent 237a57f commit 0cdb5b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ Note that the use of these multimethods is deprecated and they will be removed i

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.)

### Middleware

For cross-cutting concerns of your request and notification handlers, consider middleware functions:

```clojure
(defn wrap-vthread
"Middleware that executes requests in a virtual thread."
[handler]
(fn [method context params]
(promesa.core/vthread (handler method context params))))

;; ...

(defmulti receive-request (fn [method _ _] method))

(def server (server/chan-server {:request-handler (wrap-vthread #'receive-request)}))
```

### Async requests

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.
Expand Down
3 changes: 3 additions & 0 deletions src/lsp4clj/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@
Other options:
- `response-executor` is value supported by Promesa to specify an executor
to handle client responses to server-initiated requests. When none is
specified, uses `:default`, which is mapped to `(ForkJoinPool/commonPool)`.
- `clock` is a `java.time.Clock` that provides the current time for trace
messages.
- `on-close` is a 0-arg fn that the server will call after it has shut down."
Expand Down

0 comments on commit 0cdb5b0

Please sign in to comment.