Skip to content

Commit 52df404

Browse files
committed
Tidy trace ns
1 parent 46f6927 commit 52df404

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

src/lsp4clj/server.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
(defn trace [{:keys [tracer* trace-ch]} trace-f & params]
159159
(when-let [trace-body (apply trace-f @tracer* params)]
160-
(async/put! trace-ch trace-body)))
160+
(async/put! trace-ch [:debug trace-body])))
161161

162162
;; TODO: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
163163
;; * receive-request should return error until initialize request is received

src/lsp4clj/trace.clj

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@
2525
(format-body "Error data" (:data error))
2626
(format-body "Result" result)))
2727

28-
(defn ^:private format-header [at direction message-type header-details]
29-
(str (format-tag at) " " direction " " message-type " " header-details))
30-
31-
(defn ^:private basic-trace [at direction message-type header-details]
32-
[:debug
33-
(format-header at direction message-type header-details)])
34-
35-
(defn ^:private verbose-trace [at direction message-type header-details body]
36-
[:debug
37-
(str (format-header at direction message-type header-details) "\n"
38-
body "\n\n\n")])
39-
4028
(defn ^:private latency [^java.time.Instant started ^java.time.Instant finished]
4129
(format "%sms" (- (.toEpochMilli finished) (.toEpochMilli started))))
4230

@@ -47,21 +35,11 @@
4735
(latency started finished)
4836
(:message error) (:code error)))
4937

50-
(defn ^:private format-unmatched-notif-header-details [notif]
51-
(format "for unmatched request (%s):" (:id (:params notif))))
52-
53-
(defn ^:private verbose-notification [direction notif at]
54-
(verbose-trace at direction "notification" (format-notification-signature notif)
55-
(format-params notif)))
56-
57-
(defn ^:private verbose-request [direction req at]
58-
(verbose-trace at direction "request" (format-request-signature req)
59-
(format-params req)))
38+
(defn ^:private basic-trace [at direction message-type header-details]
39+
(str (format-tag at) " " direction " " message-type " " header-details))
6040

61-
(defn ^:private verbose-response [direction req resp started finished]
62-
(verbose-trace finished direction "response"
63-
(format-response-header-details req resp started finished)
64-
(format-response-body resp)))
41+
(defn ^:private verbose-trace [header body]
42+
(str header "\n" body "\n\n\n"))
6543

6644
(defn ^:private basic-notification [direction notif at]
6745
(basic-trace at direction "notification" (format-notification-signature notif)))
@@ -72,6 +50,24 @@
7250
(defn ^:private basic-response [direction req resp started finished]
7351
(basic-trace finished direction "response" (format-response-header-details req resp started finished)))
7452

53+
(defn ^:private basic-received-unmatched-response [at]
54+
(basic-trace at "Received" "response" "for unmatched request"))
55+
56+
(defn ^:private basic-received-unmatched-cancellation [at notif]
57+
(basic-trace at "Received" "cancellation notification" (format "for unmatched request (%s):" (:id (:params notif)))))
58+
59+
(defn ^:private verbose-notification [direction notif at]
60+
(verbose-trace (basic-notification direction notif at)
61+
(format-params notif)))
62+
63+
(defn ^:private verbose-request [direction req at]
64+
(verbose-trace (basic-request direction req at)
65+
(format-params req)))
66+
67+
(defn ^:private verbose-response [direction req resp started finished]
68+
(verbose-trace (basic-response direction req resp started finished)
69+
(format-response-body resp)))
70+
7571
(defprotocol ITracer
7672
(received-notification [this notif at])
7773
(received-request [this req at])
@@ -91,11 +87,9 @@
9187
(received-response [_this req resp started finished]
9288
(verbose-response "Received" req resp started finished))
9389
(received-unmatched-response [_this resp at]
94-
(verbose-trace at "Received" "response" "for unmatched request:"
95-
(format-body "Body" resp)))
90+
(verbose-trace (basic-received-unmatched-response at) (format-body "Body" resp)))
9691
(received-unmatched-cancellation-notification [_this notif at]
97-
(verbose-trace at "Received" "cancellation notification" (format-unmatched-notif-header-details notif)
98-
(format-params notif)))
92+
(verbose-trace (basic-received-unmatched-cancellation at notif) (format-params notif)))
9993
(sending-notification [_this notif at]
10094
(verbose-notification "Sending" notif at))
10195
(sending-request [_this req at]
@@ -112,9 +106,9 @@
112106
(received-response [_this req resp started finished]
113107
(basic-response "Received" req resp started finished))
114108
(received-unmatched-response [_this _resp at]
115-
(basic-trace at "Received" "response" "for unmatched request:"))
109+
(basic-received-unmatched-response at))
116110
(received-unmatched-cancellation-notification [_this notif at]
117-
(basic-trace at "Received" "cancellation notification" (format-unmatched-notif-header-details notif)))
111+
(basic-received-unmatched-cancellation at notif))
118112
(sending-notification [_this notif at]
119113
(basic-notification "Sending" notif at))
120114
(sending-request [_this req at]

test/lsp4clj/server_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
trace-ch (:trace-ch server)]
370370
(server/start server nil)
371371
(async/put! input-ch (lsp.responses/response 100 {:processed true}))
372-
(is (= (trace-log ["[Trace - 2022-03-05T13:35:23Z] Received response for unmatched request:"
372+
(is (= (trace-log ["[Trace - 2022-03-05T13:35:23Z] Received response for unmatched request"
373373
"Body: {"
374374
" \"jsonrpc\" : \"2.0\","
375375
" \"id\" : 100,"

0 commit comments

Comments
 (0)