@@ -28,10 +28,9 @@ defmodule NextLS do
28
28
alias GenLSP.Structures.TextDocumentItem
29
29
alias GenLSP.Structures.TextDocumentSyncOptions
30
30
alias GenLSP.Structures.TextEdit
31
- alias GenLSP.Structures.WorkDoneProgressBegin
32
- alias GenLSP.Structures.WorkDoneProgressEnd
33
31
alias NextLS.Definition
34
32
alias NextLS.DiagnosticCache
33
+ alias NextLS.Progress
35
34
alias NextLS.Runtime
36
35
alias NextLS.SymbolTable
37
36
@@ -280,30 +279,32 @@ defmodule NextLS do
280
279
281
280
for % { uri: uri , name: name } <- lsp . assigns . workspace_folders do
282
281
token = token ( )
283
- progress_start ( lsp , token , "Initializing NextLS runtime for folder #{ name } ..." )
282
+ Progress . start ( lsp , token , "Initializing NextLS runtime for folder #{ name } ..." )
284
283
parent = self ( )
285
284
286
285
{ :ok , runtime } =
287
286
DynamicSupervisor . start_child (
288
287
lsp . assigns . dynamic_supervisor ,
289
- { NextLS.Runtime ,
290
- name: name ,
291
- task_supervisor: lsp . assigns . runtime_task_supervisor ,
292
- registry: lsp . assigns . registry ,
293
- working_dir: URI . parse ( uri ) . path ,
294
- uri: uri ,
295
- parent: self ( ) ,
296
- on_initialized: fn status ->
297
- if status == :ready do
298
- progress_end ( lsp , token , "NextLS runtime for folder #{ name } has initialized!" )
299
- GenLSP . log ( lsp , "[NextLS] Runtime for folder #{ name } is ready..." )
300
- send ( parent , { :runtime_ready , name , self ( ) } )
301
- else
302
- progress_end ( lsp , token )
303
- GenLSP . error ( lsp , "[NextLS] Runtime for folder #{ name } failed to initialize" )
304
- end
305
- end ,
306
- logger: lsp . assigns . logger }
288
+ { NextLS.RuntimeSupervisor ,
289
+ runtime: [
290
+ name: name ,
291
+ task_supervisor: lsp . assigns . runtime_task_supervisor ,
292
+ registry: lsp . assigns . registry ,
293
+ working_dir: URI . parse ( uri ) . path ,
294
+ uri: uri ,
295
+ parent: parent ,
296
+ on_initialized: fn status ->
297
+ if status == :ready do
298
+ Progress . stop ( lsp , token , "NextLS runtime for folder #{ name } has initialized!" )
299
+ GenLSP . log ( lsp , "[NextLS] Runtime for folder #{ name } is ready..." )
300
+ send ( parent , { :runtime_ready , name , self ( ) } )
301
+ else
302
+ Progress . stop ( lsp , token )
303
+ GenLSP . error ( lsp , "[NextLS] Runtime for folder #{ name } failed to initialize" )
304
+ end
305
+ end ,
306
+ logger: lsp . assigns . logger
307
+ ] }
307
308
)
308
309
309
310
ref = Process . monitor ( runtime )
@@ -335,7 +336,7 @@ defmodule NextLS do
335
336
dispatch ( lsp . assigns . registry , :runtimes , fn entries ->
336
337
for { pid , % { name: name , uri: wuri } } <- entries , String . starts_with? ( uri , wuri ) , into: % { } do
337
338
token = token ( )
338
- progress_start ( lsp , token , "Compiling..." )
339
+ Progress . start ( lsp , token , "Compiling..." )
339
340
340
341
task =
341
342
Task.Supervisor . async_nolink ( lsp . assigns . task_supervisor , fn ->
@@ -418,7 +419,7 @@ defmodule NextLS do
418
419
419
420
def handle_info ( { :runtime_ready , name , runtime_pid } , lsp ) do
420
421
token = token ( )
421
- progress_start ( lsp , token , "Compiling..." )
422
+ Progress . start ( lsp , token , "Compiling..." )
422
423
423
424
task =
424
425
Task.Supervisor . async_nolink ( lsp . assigns . task_supervisor , fn ->
@@ -434,7 +435,7 @@ defmodule NextLS do
434
435
Process . demonitor ( ref , [ :flush ] )
435
436
{ { token , msg } , refs } = Map . pop ( refs , ref )
436
437
437
- progress_end ( lsp , token , msg )
438
+ Progress . stop ( lsp , token , msg )
438
439
439
440
{ :noreply , assign ( lsp , refresh_refs: refs ) }
440
441
end
@@ -443,7 +444,7 @@ defmodule NextLS do
443
444
when is_map_key ( refs , ref ) do
444
445
{ { token , _ } , refs } = Map . pop ( refs , ref )
445
446
446
- progress_end ( lsp , token )
447
+ Progress . stop ( lsp , token )
447
448
448
449
{ :noreply , assign ( lsp , refresh_refs: refs ) }
449
450
end
@@ -462,30 +463,6 @@ defmodule NextLS do
462
463
{ :noreply , lsp }
463
464
end
464
465
465
- defp progress_start ( lsp , token , msg ) do
466
- GenLSP . notify ( lsp , % GenLSP.Notifications.DollarProgress {
467
- params: % GenLSP.Structures.ProgressParams {
468
- token: token ,
469
- value: % WorkDoneProgressBegin {
470
- kind: "begin" ,
471
- title: msg
472
- }
473
- }
474
- } )
475
- end
476
-
477
- defp progress_end ( lsp , token , msg \\ nil ) do
478
- GenLSP . notify ( lsp , % GenLSP.Notifications.DollarProgress {
479
- params: % GenLSP.Structures.ProgressParams {
480
- token: token ,
481
- value: % WorkDoneProgressEnd {
482
- kind: "end" ,
483
- message: msg
484
- }
485
- }
486
- } )
487
- end
488
-
489
466
defp token do
490
467
8
491
468
|> :crypto . strong_rand_bytes ( )
0 commit comments