File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Expand file tree Collapse file tree 2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 3131(defprotocol IBlockingDerefOrCancel
3232 (deref-or-cancel [this timeout-ms timeout-val]))
3333
34- (defrecord PendingRequest [p id method started server ]
34+ (defrecord PendingRequest [p id method started]
3535 clojure.lang.IDeref
3636 (deref [_] (deref p))
3737 clojure.lang.IBlockingDeref
5656 (isCancelled [_] (p/cancelled? p))
5757 (isDone [_] (p/done? p))
5858 (cancel [_ _interrupt?]
59- (if (p/done? p)
60- false
61- (do
62- (p/cancel! p)
63- (protocols.endpoint/send-notification server " $/cancelRequest" {:id id})
64- true )))
59+ (p/cancel! p)
60+ (p/cancelled? p))
6561 p.protocols /IPromiseFactory
6662 (-promise [_] p))
6763
9187 Sends `$/cancelRequest` only once, though `lsp4clj.server/deref-or-cancel` or
9288 `future-cancel` can be called multiple times."
9389 [id method started server]
94- (map->PendingRequest {:p (p/deferred )
95- :id id
96- :method method
97- :started started
98- :server server}))
90+ ; ; Chaining `(-> (p/deferred) (p/catch ...))` seems like it should work, but
91+ ; ; doesn't.
92+ (let [p (p/deferred )]
93+ (p/catch p CancellationException
94+ (fn [ex]
95+ (protocols.endpoint/send-notification server " $/cancelRequest" {:id id})
96+ (p/rejected ex)))
97+ (map->PendingRequest {:p p
98+ :id id
99+ :method method
100+ :started started})))
99101
100102(defn ^:private format-error-code [description error-code]
101103 (let [{:keys [code message]} (lsp.errors/by-key error-code)]
Original file line number Diff line number Diff line change 290290 (h/assert-take output-ch)
291291 (is (future-cancel req))
292292 (is (= " $/cancelRequest" (:method (h/assert-take output-ch))))
293- (is (not ( future-cancel req) ))
293+ (is (future-cancel req))
294294 (h/assert-no-take output-ch)
295295 (server/shutdown server)))
296296
402402 :input-ch input-ch})
403403 _ (server/start server nil )
404404 req (p/promise (server/send-request server " req" {:body " foo" }))]
405+ (h/assert-take output-ch)
405406 (p/cancel! req)
406407 (is (p/done? req))
407408 (is (p/cancelled? req))
409+ (is (= {:jsonrpc " 2.0" , :method " $/cancelRequest" , :params {:id 1 }}
410+ (h/assert-take output-ch)))
408411 (server/shutdown server))))
409412
410413(def fixed-clock
You can’t perform that action at this time.
0 commit comments