mirror of
https://github.com/c-cube/linol.git
synced 2025-12-05 19:00:34 -05:00
Wrapper around the OCaml
lsp library to make it easier to write LSP servers
Problem: Linol can only send notifications from the server to the client, but not requests. Solution: The solution was inspired by Haskell's `lsp` package. We first maintain a `server_request_handler_pair` data structure which represents some server request and its associated response handler. Now `notify_back` may take these fields and use it to actually handle a request and its response. Changes to `notify_back` are propagated throughout `server.ml`. On `jsonrpc2.ml`, we refactor the notification and request handlers so that we may handle the response and batch response handlers and batch call as a courtesy. For a response, we keep a hash table that tracks an ID to the `server_request_handler_pair` in other to be able to call the handler that was associated with the response. After we get such response (indexed by the server request's ID), we remove it from the hash table to prevent a memory leak. Since the server needs to keep track of the server request IDs, I added a mutable `id_counter` in order to generate a fresh LSP ID (using `fresh_lsp_id`) for every outgoing request. For debugging, if we error while decoding a JSON, I now print the exception too. |
||
|---|---|---|
| .github/workflows | ||
| example/template | ||
| src | ||
| .gitignore | ||
| .ocamlformat | ||
| dune-project | ||
| linol-lwt.opam | ||
| linol.opam | ||
| Makefile | ||
| README.md | ||