@@ -33,7 +33,9 @@ defmodule NextLS do
33
33
ServerCapabilities ,
34
34
TextDocumentItem ,
35
35
TextDocumentSyncOptions ,
36
- TextEdit
36
+ TextEdit ,
37
+ WorkDoneProgressBegin ,
38
+ WorkDoneProgressEnd
37
39
}
38
40
39
41
alias NextLS.Runtime
@@ -156,6 +158,10 @@ defmodule NextLS do
156
158
157
159
GenLSP . log ( lsp , "[NextLS] Booting runime..." )
158
160
161
+ token = token ( )
162
+
163
+ progress_start ( lsp , token , "Initializing NextLS runtime..." )
164
+
159
165
{ :ok , runtime } =
160
166
DynamicSupervisor . start_child (
161
167
lsp . assigns . dynamic_supervisor ,
@@ -181,7 +187,11 @@ defmodule NextLS do
181
187
:ready
182
188
end )
183
189
184
- { :noreply , assign ( lsp , refresh_refs: Map . put ( lsp . assigns . refresh_refs , task . ref , task . ref ) , runtime_task: task ) }
190
+ { :noreply ,
191
+ assign ( lsp ,
192
+ refresh_refs: Map . put ( lsp . assigns . refresh_refs , task . ref , { token , "NextLS runtime has initialized!" } ) ,
193
+ runtime_task: task
194
+ ) }
185
195
end
186
196
187
197
def handle_notification ( % TextDocumentDidSave { } , % { assigns: % { ready: false } } = lsp ) do
@@ -197,6 +207,10 @@ defmodule NextLS do
197
207
} ,
198
208
% { assigns: % { ready: true } } = lsp
199
209
) do
210
+ token = token ( )
211
+
212
+ progress_start ( lsp , token , "Compiling..." )
213
+
200
214
task =
201
215
Task.Supervisor . async_nolink ( lsp . assigns . task_supervisor , fn ->
202
216
Runtime . compile ( lsp . assigns . runtime )
@@ -205,7 +219,7 @@ defmodule NextLS do
205
219
{ :noreply ,
206
220
lsp
207
221
|> then ( & put_in ( & 1 . assigns . documents [ uri ] , String . split ( text , "\n " ) ) )
208
- |> then ( & put_in ( & 1 . assigns . refresh_refs [ task . ref ] , task . ref ) ) }
222
+ |> then ( & put_in ( & 1 . assigns . refresh_refs [ task . ref ] , { token , "Compiled!" } ) ) }
209
223
end
210
224
211
225
def handle_notification ( % TextDocumentDidChange { } , % { assigns: % { ready: false } } = lsp ) do
@@ -268,20 +282,32 @@ defmodule NextLS do
268
282
{ :noreply , lsp }
269
283
end
270
284
271
- def handle_info ( { ref , resp } , % { assigns: % { refresh_refs: refs } } = lsp )
272
- when is_map_key ( refs , ref ) do
285
+ def handle_info ( { ref , resp } , % { assigns: % { refresh_refs: refs } } = lsp ) when is_map_key ( refs , ref ) do
273
286
Process . demonitor ( ref , [ :flush ] )
274
- { _token , refs } = Map . pop ( refs , ref )
287
+ { { token , msg } , refs } = Map . pop ( refs , ref )
288
+
289
+ GenLSP . notify ( lsp , % GenLSP.Notifications.DollarProgress {
290
+ params: % GenLSP.Structures.ProgressParams {
291
+ token: token ,
292
+ value: % WorkDoneProgressEnd {
293
+ kind: "end" ,
294
+ message: msg
295
+ }
296
+ }
297
+ } )
275
298
276
299
lsp =
277
300
case resp do
278
301
:ready ->
302
+ token = token ( )
303
+ progress_start ( lsp , token , "Compiling..." )
304
+
279
305
task =
280
306
Task.Supervisor . async_nolink ( lsp . assigns . task_supervisor , fn ->
281
307
Runtime . compile ( lsp . assigns . runtime )
282
308
end )
283
309
284
- assign ( lsp , ready: true , refresh_refs: Map . put ( refs , task . ref , task . ref ) )
310
+ assign ( lsp , ready: true , refresh_refs: Map . put ( refs , task . ref , { token , "Compiled!" } ) )
285
311
286
312
_ ->
287
313
assign ( lsp , refresh_refs: refs )
@@ -332,4 +358,23 @@ defmodule NextLS do
332
358
wait_until ( n - 1 , cb )
333
359
end
334
360
end
361
+
362
+ defp progress_start ( lsp , token , msg ) do
363
+ GenLSP . notify ( lsp , % GenLSP.Notifications.DollarProgress {
364
+ params: % GenLSP.Structures.ProgressParams {
365
+ token: token ,
366
+ value: % WorkDoneProgressBegin {
367
+ kind: "begin" ,
368
+ title: msg
369
+ }
370
+ }
371
+ } )
372
+ end
373
+
374
+ defp token ( ) do
375
+ 8
376
+ |> :crypto . strong_rand_bytes ( )
377
+ |> Base . url_encode64 ( padding: false )
378
+ |> binary_part ( 0 , 8 )
379
+ end
335
380
end
0 commit comments