@@ -243,19 +243,28 @@ defmodule ElixirLS.Debugger.Server do
243
243
Output . debugger_important ( "launch with no debug is not supported" )
244
244
end
245
245
246
- { _ , ref } = spawn_monitor ( fn -> initialize ( config ) end )
246
+ server = self ( )
247
247
248
- receive do
249
- { :DOWN , ^ ref , :process , _pid , reason } ->
250
- if reason != :normal do
251
- Output . debugger_important ( "Initialization failed: " <> Exception . format_exit ( reason ) )
248
+ { _ , ref } = spawn_monitor ( fn -> initialize ( config , server ) end )
252
249
253
- Output . send_event ( "exited" , % { "exitCode" => 1 } )
254
- Output . send_event ( "terminated" , % { "restart" => false } )
255
- end
256
- end
250
+ config =
251
+ receive do
252
+ { :ok , config } ->
253
+ Output . send_event ( "initialized" , % { } )
254
+ send ( self ( ) , :update_threads )
255
+ config
256
+
257
+ { :DOWN , ^ ref , :process , _pid , reason } ->
258
+ if reason != :normal do
259
+ Output . debugger_important ( "Initialization failed: " <> Exception . format_exit ( reason ) )
257
260
258
- send ( self ( ) , :update_threads )
261
+ Output . send_event ( "exited" , % { "exitCode" => 1 } )
262
+ Output . send_event ( "terminated" , % { "restart" => false } )
263
+ config
264
+ else
265
+ raise "exit reason #{ inspect ( reason ) } was not expected"
266
+ end
267
+ end
259
268
260
269
{ % { } , % { state | config: config } }
261
270
end
@@ -397,8 +406,8 @@ defmodule ElixirLS.Debugger.Server do
397
406
defp handle_request ( configuration_done_req ( _ ) , state = % __MODULE__ { } ) do
398
407
:int . auto_attach ( [ :break ] , build_attach_mfa ( :breakpoint_reached ) )
399
408
400
- task = state . config [ "task" ] || Mix.Project . config ( ) [ :default_task ]
401
- args = state . config [ "taskArgs" ] || [ ]
409
+ task = state . config [ "task" ]
410
+ args = state . config [ "taskArgs" ]
402
411
{ _pid , task_ref } = spawn_monitor ( fn -> launch_task ( task , args ) end )
403
412
404
413
{ % { } , % { state | task_ref: task_ref } }
@@ -939,7 +948,7 @@ defmodule ElixirLS.Debugger.Server do
939
948
end
940
949
end
941
950
942
- defp initialize ( % { "projectDir" => project_dir } = config ) do
951
+ defp initialize ( % { "projectDir" => project_dir } = config , server ) do
943
952
task = config [ "task" ]
944
953
task_args = config [ "taskArgs" ] || [ ]
945
954
auto_interpret_files? = Map . get ( config , "debugAutoInterpretAllModules" , true )
@@ -983,9 +992,8 @@ defmodule ElixirLS.Debugger.Server do
983
992
984
993
unless is_list ( task_args ) and "--no-compile" in task_args do
985
994
case Mix.Task . run ( "compile" , [ "--ignore-module-conflict" ] ) do
986
- { :error , _ } ->
987
- Output . debugger_important ( "Aborting debugger due to compile errors" )
988
- System . stop ( 1 )
995
+ { :error , reason } ->
996
+ raise reason
989
997
990
998
_ ->
991
999
:ok
@@ -1016,7 +1024,8 @@ defmodule ElixirLS.Debugger.Server do
1016
1024
interpret_specified_modules ( interpret_modules_patterns , exclude_module_pattern )
1017
1025
end
1018
1026
1019
- ElixirLS.Debugger.Output . send_event ( "initialized" , % { } )
1027
+ updated_config = Map . merge ( config , % { "task" => task , "taskArgs" => task_args } )
1028
+ send ( server , { :ok , updated_config } )
1020
1029
end
1021
1030
1022
1031
defp set_env_vars ( env ) when is_map ( env ) do
@@ -1104,8 +1113,18 @@ defmodule ElixirLS.Debugger.Server do
1104
1113
# debugger as well.
1105
1114
Process . sleep ( 100 )
1106
1115
1116
+ if args != [ ] do
1117
+ Output . debugger_console ( "Running mix #{ task } #{ Enum . join ( args , " " ) } \n " )
1118
+ else
1119
+ Output . debugger_console ( "Running mix #{ task } \n " )
1120
+ end
1121
+
1107
1122
Mix.Task . run ( task , args )
1108
1123
1124
+ Output . debugger_console (
1125
+ "Mix.Task.run returned, sleeping.\n Note that debugger needs to be stopped manually.\n "
1126
+ )
1127
+
1109
1128
# Starting from Elixir 1.9 Mix.Task.run will return so we need to sleep our
1110
1129
# process so that the code keeps running (Note: process is expected to be
1111
1130
# killed by stopping the debugger)
0 commit comments