Skip to content

Commit ea23da9

Browse files
authored
Merge pull request #26 from clojure-lsp/improve-traces
Improve traces for cancelled requests
2 parents ca2cdf7 + ce59c36 commit ea23da9

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/lsp4clj/server.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,14 @@
265265
(async/>!! output-ch (internal-error-response resp req))))))
266266
(receive-notification [this context {:keys [method params] :as notif}]
267267
(let [now (.instant clock)]
268+
(some-> trace-ch (async/put! (trace/received-notification notif now)))
268269
(if (= method "$/cancelRequest")
269270
(if-let [result-promise (get @pending-received-requests* (:id params))]
270271
(p/cancel! result-promise)
271272
(some-> trace-ch (async/put! (trace/received-unmatched-cancellation-notification notif now))))
272-
(do
273-
(some-> trace-ch (async/put! (trace/received-notification notif now)))
274-
(let [result (receive-notification method context params)]
275-
(when (identical? ::method-not-found result)
276-
(protocols.endpoint/log this :warn "received unexpected notification" method))))))))
273+
(let [result (receive-notification method context params)]
274+
(when (identical? ::method-not-found result)
275+
(protocols.endpoint/log this :warn "received unexpected notification" method)))))))
277276

278277
(defn chan-server
279278
[{:keys [output-ch input-ch log-ch trace? trace-ch clock on-close]

src/lsp4clj/trace.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
(format-body "Body" resp)))
6060

6161
(defn received-unmatched-cancellation-notification [notif at]
62-
(format-trace at "Received" "cancellation notification" "for unmatched request:"
62+
(format-trace at "Received" "cancellation notification" (format "for unmatched request (%s):" (:id (:params notif)))
6363
(format-params notif)))
6464

6565
(defn sending-notification [notif at] (format-notification "Sending" notif at))

test/lsp4clj/server_test.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@
387387
trace-ch (:trace-ch server)]
388388
(server/start server nil)
389389
(async/put! input-ch (lsp.requests/notification "$/cancelRequest" {:id 1}))
390-
(is (= (trace-log ["[Trace - 2022-03-05T13:35:23Z] Received cancellation notification for unmatched request:"
390+
(h/assert-take trace-ch) ;; trace of Received notification '$/cancelRequest'
391+
(is (= (trace-log ["[Trace - 2022-03-05T13:35:23Z] Received cancellation notification for unmatched request (1):"
391392
"Params: {"
392393
" \"id\" : 1"
393394
"}"])

0 commit comments

Comments
 (0)