prepare for message batching

This commit is contained in:
XeroOl 2025-09-14 18:24:26 -05:00
parent cd9821cd80
commit 03addbf312
2 changed files with 21 additions and 20 deletions

View File

@ -49,7 +49,7 @@
(local server {}) (local server {})
(while true (while true
(let [msg (json-rpc.read in)] (let [msg (json-rpc.read in)]
(dispatch.handle server send msg)))) (dispatch.handle server send [msg]))))
(local {: version} (require :fennel-ls.utils)) (local {: version} (require :fennel-ls.utils))
(local help "Usage: fennel-ls [FLAG] [FILES] (local help "Usage: fennel-ls [FLAG] [FILES]

View File

@ -25,7 +25,7 @@ In general, this involves:
id)))) id))))
(λ handle-response [_server _send _id _result] (λ handle-response [_server _send _id _result]
;; I don't care about responses yet ;; fennel-ls doesn't care about responses yet
nil) nil)
(λ handle-bad-response [_server _send _id err] (λ handle-bad-response [_server _send _id err]
@ -38,7 +38,7 @@ In general, this involves:
callback (callback server send ?params))) callback (callback server send ?params)))
;; Silent error for unknown notifications ;; Silent error for unknown notifications
(λ handle [server send msg] (λ handle [server send batch]
"Figures out what to do with a message. "Figures out what to do with a message.
This can involve updating the state of the server, and/or sending messages to the This can involve updating the state of the server, and/or sending messages to the
server. server.
@ -46,7 +46,8 @@ server.
Takes: Takes:
* `server`, which is the state of the server, * `server`, which is the state of the server,
* `send`, which is a callback for sending responses, and * `send`, which is a callback for sending responses, and
* `msg`, which is the message to receive." * `msgs`, which is a list of incoming messages."
(each [_ msg (ipairs batch)]
(case (values msg (type msg)) (case (values msg (type msg))
{:jsonrpc "2.0" : id : method :params ?params} {:jsonrpc "2.0" : id : method :params ?params}
(handle-request server send id method ?params) (handle-request server send id method ?params)
@ -61,12 +62,12 @@ Takes:
_ _
(send (message.create-error :BadMessage nil msg.id))) (send (message.create-error :BadMessage nil msg.id)))
(while (next server.queue) (while (next server.queue)
(send (table.remove server.queue 1)))) (send (table.remove server.queue 1)))))
(λ handle* [server msg] (λ handle* [server msg]
"handles a message, and returns all the responses in a table" "handles a message, and returns all the responses in a table"
(let [out []] (let [out []]
(handle server (partial table.insert out) msg) (handle server (partial table.insert out) [msg])
out)) out))
{: handle {: handle