File tree Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Expand file tree Collapse file tree 1 file changed +21
-9
lines changed Original file line number Diff line number Diff line change 1616; ; TODO: The following are helpers used by servers, but not by lsp4clj itself.
1717; ; Perhaps they belong in a utils namespace.
1818
19+ (defn clamp [n n-min n-max]
20+ (-> n (max n-min) (min n-max)))
21+
1922#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var ]}
2023(defn work-done-progress
2124 " Returns the params for a WorkDone $/progress notification.
2225
2326 https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workDoneProgress
2427 "
2528 [percentage message progress-token]
26- (let [percentage (int percentage)
27- progress {:kind (case percentage
28- 0 :begin
29- 100 :end
30- :report )
31- :title message
32- :percentage percentage}]
33- {:token (or progress-token " lsp4clj" )
34- :value progress}))
29+ (when progress-token
30+ (let [percentage (int (clamp percentage 0 100 ))
31+ progress (case percentage
32+ ; ; TODO: this is a bit restricting. Technically the 'begin'
33+ ; ; message can start at a higher `percentage`, and it can
34+ ; ; have a `message`. To work around this, it's possible to
35+ ; ; publish a 'begin' immediately followed by a 'progress'
36+ ; ; with the desired percentage and message.
37+ 0 {:kind :begin
38+ :title message
39+ :percentage 0 }
40+ 100 {:kind :end
41+ :message message}
42+ {:kind :report
43+ :message message
44+ :percentage percentage})]
45+ {:token progress-token
46+ :value progress})))
You can’t perform that action at this time.
0 commit comments