Skip to content

Commit fef6bea

Browse files
committed
Handle notify messagepack-rpc messages
1 parent fe3184f commit fef6bea

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/neovim_client/message.clj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
(def +request+ 0)
44
(def +response+ 1)
5+
(def +notify+ 2)
56

67
(defn gen-msg-id
78
"Get a unique message id."
@@ -18,7 +19,6 @@
1819
[id result]
1920
[1 id nil result])
2021

21-
2222
;; TODO - find better way to get [B type.
2323
(def byte-array-type (type (.getBytes "foo")))
2424

@@ -34,10 +34,13 @@
3434

3535
;; ***** Accessor fns *****
3636
(def msg-type first)
37+
38+
;; Only true for request & response, notify has no id
3739
(def id second)
3840

3941
(defn request? [msg] (= +request+ (msg-type msg)))
4042
(defn response? [msg] (= +response+ (msg-type msg)))
43+
(defn notify? [msg] (= +notify+ (msg-type msg)))
4144

4245
(defn value
4346
[msg]
@@ -46,10 +49,10 @@
4649

4750
(defn method
4851
[msg]
49-
{:pre [(request? msg)]}
50-
(bytes->str (nth msg 2)))
52+
{:pre [(or (request? msg) (notify? msg))]}
53+
(bytes->str (nth (reverse msg) 1)))
5154

5255
(defn params
5356
[msg]
54-
{:pre [(or (request? msg) (response? msg))]}
57+
{:pre [(or (request? msg) (response? msg) (notify? msg))]}
5558
(last msg))

src/neovim_client/rpc.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"Read messages from the input stream, put them on a channel."
1818
[input-stream]
1919
(let [chan (async/chan 1024)]
20+
;; TODO make these threads w/ loops, since they're handling IO
21+
;; might explain the wierd drlog blockages
2022
(async/go-loop
2123
[]
2224
(when-let [msg (msgpack/unpack input-stream)]
@@ -101,6 +103,11 @@
101103
(let [f (get @method-table (method msg) method-not-found)
102104
result (f msg)]
103105
(send-message-async!
104-
component (->response-msg (id msg) result) nil)))
106+
component (->response-msg (id msg) result) nil))
107+
108+
msg/+notify+
109+
(let [f (get @method-table (method msg) method-not-found)
110+
result (f msg)]))
111+
105112
(recur))))
106113
component))

0 commit comments

Comments
 (0)