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 16
16
; ; TODO: The following are helpers used by servers, but not by lsp4clj itself.
17
17
; ; Perhaps they belong in a utils namespace.
18
18
19
+ (defn clamp [n n-min n-max]
20
+ (-> n (max n-min) (min n-max)))
21
+
19
22
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var ]}
20
23
(defn work-done-progress
21
24
" Returns the params for a WorkDone $/progress notification.
22
25
23
26
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workDoneProgress
24
27
"
25
28
[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