@@ -90,6 +90,7 @@ defmodule NextLS.Runtime do
90
90
sname = "nextls-runtime-#{ System . system_time ( ) } "
91
91
name = Keyword . fetch! ( opts , :name )
92
92
working_dir = Keyword . fetch! ( opts , :working_dir )
93
+ lsp_pid = Keyword . fetch! ( opts , :lsp_pid )
93
94
uri = Keyword . fetch! ( opts , :uri )
94
95
parent = Keyword . fetch! ( opts , :parent )
95
96
logger = Keyword . fetch! ( opts , :logger )
@@ -222,6 +223,8 @@ defmodule NextLS.Runtime do
222
223
:ok
223
224
end )
224
225
226
+ { :ok , _ } = :rpc . call ( node , :_next_ls_private_compiler , :start , [ ] )
227
+
225
228
send ( me , { :node , node } )
226
229
else
227
230
error ->
@@ -237,6 +240,7 @@ defmodule NextLS.Runtime do
237
240
port: port ,
238
241
task_supervisor: task_supervisor ,
239
242
logger: logger ,
243
+ lsp_pid: lsp_pid ,
240
244
parent: parent ,
241
245
errors: nil ,
242
246
registry: registry ,
@@ -279,54 +283,32 @@ defmodule NextLS.Runtime do
279
283
end
280
284
end
281
285
282
- def handle_call ( { :compile , opts } , from , % { node: node } = state ) do
283
- for { _ref , { task_pid , _from } } <- state . compiler_refs , do: Process . exit ( task_pid , :kill )
284
-
285
- task =
286
- Task.Supervisor . async_nolink ( state . task_supervisor , fn ->
287
- if opts [ :force ] do
288
- File . rm_rf! ( Path . join ( state . working_dir , ".elixir-tools/_build" ) )
289
- end
290
-
291
- case :rpc . call ( node , :_next_ls_private_compiler , :compile , [ ] ) do
292
- { :badrpc , error } ->
293
- NextLS.Logger . error ( state . logger , "Bad RPC call to node #{ node } : #{ inspect ( error ) } " )
294
- [ ]
295
-
296
- { _ , diagnostics } when is_list ( diagnostics ) ->
297
- Registry . dispatch ( state . registry , :extensions , fn entries ->
298
- for { pid , _ } <- entries , do: send ( pid , { :compiler , diagnostics } )
299
- end )
300
-
301
- NextLS.Logger . info ( state . logger , "Compiled #{ state . name } !" )
302
-
303
- diagnostics
304
-
305
- { :error , % Mix.Error { message: "Can't continue due to errors on dependencies" } } ->
306
- { :runtime_failed , state . name , { :error , :deps } }
286
+ def handle_call ( { :compile , opts } , _from , % { node: node } = state ) do
287
+ opts =
288
+ opts
289
+ |> Keyword . put_new ( :working_dir , state . working_dir )
290
+ |> Keyword . put_new ( :registry , state . registry )
291
+ |> Keyword . put ( :from , self ( ) )
307
292
308
- unknown ->
309
- NextLS.Logger . warning ( state . logger , "Unexpected compiler response: #{ inspect ( unknown ) } " )
310
- [ ]
311
- end
312
- end )
293
+ with { :badrpc , error } <- :rpc . call ( node , :_next_ls_private_compiler_worker , :enqueue_compiler , [ opts ] ) do
294
+ NextLS.Logger . error ( state . logger , "Bad RPC call to node #{ node } : #{ inspect ( error ) } " )
295
+ end
313
296
314
- { :noreply , % { state | compiler_refs: Map . put ( state . compiler_refs , task . ref , { task . pid , from } ) } }
297
+ { :reply , :ok , state }
315
298
end
316
299
317
300
@ impl GenServer
318
- def handle_info ( { ref , errors } , % { compiler_refs: compiler_refs } = state ) when is_map_key ( compiler_refs , ref ) do
319
- Process . demonitor ( ref , [ :flush ] )
320
-
321
- orig = elem ( compiler_refs [ ref ] , 1 )
322
- GenServer . reply ( orig , errors )
323
-
324
- { :noreply , % { state | compiler_refs: Map . delete ( compiler_refs , ref ) } }
301
+ # NOTE: these two callbacks are basically to forward the messages from the runtime to the LSP
302
+ # LSP process so that progress messages can be dispatched
303
+ def handle_info ( { :compiler_result , caller_ref , result } , state ) do
304
+ # we add the runtime name into the message
305
+ send ( state . lsp_pid , { :compiler_result , caller_ref , state . name , result } )
306
+ { :noreply , state }
325
307
end
326
308
327
- def handle_info ( { :DOWN , ref , :process , _pid , _reason } , % { compiler_refs: compiler_refs } = state )
328
- when is_map_key ( compiler_refs , ref ) do
329
- { :noreply , % { state | compiler_refs: Map . delete ( compiler_refs , ref ) } }
309
+ def handle_info ( { :compiler_canceled , _caller_ref } = msg , state ) do
310
+ send ( state . lsp_pid , msg )
311
+ { :noreply , state }
330
312
end
331
313
332
314
def handle_info ( { :DOWN , _ , :port , port , _ } , % { port: port } = state ) do
0 commit comments