Skip to content

Commit ae0690f

Browse files
authored
Merge pull request #35 from clojure-lsp/fix-progress-message
Fix progress messages in Calva
2 parents 6e15862 + 6d9c80c commit ae0690f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/lsp4clj/lsp/requests.clj

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,31 @@
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})))

0 commit comments

Comments
 (0)