-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathprogress.ex
45 lines (42 loc) · 1.17 KB
/
progress.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
defmodule NextLS.Progress do
@moduledoc false
@env Mix.env()
def start(lsp, token, msg) do
# FIXME: gen_lsp should allow stubbing requests so we don't have to
# set this in every test. For now, don't send it in the test env
if @env != :test do
GenLSP.request(lsp, %GenLSP.Requests.WindowWorkDoneProgressCreate{
id: System.unique_integer([:positive]),
params: %GenLSP.Structures.WorkDoneProgressCreateParams{
token: token
}
})
end
GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
params: %GenLSP.Structures.ProgressParams{
token: token,
value: %GenLSP.Structures.WorkDoneProgressBegin{
kind: "begin",
title: msg
}
}
})
end
def stop(lsp, token, msg \\ nil) do
GenLSP.notify(lsp, %GenLSP.Notifications.DollarProgress{
params: %GenLSP.Structures.ProgressParams{
token: token,
value: %GenLSP.Structures.WorkDoneProgressEnd{
kind: "end",
message: msg
}
}
})
end
def token do
8
|> :crypto.strong_rand_bytes()
|> Base.url_encode64(padding: false)
|> binary_part(0, 8)
end
end