@@ -243,19 +243,28 @@ defmodule ElixirLS.Debugger.Server do
243243 Output . debugger_important ( "launch with no debug is not supported" )
244244 end
245245
246- { _ , ref } = spawn_monitor ( fn -> initialize ( config ) end )
246+ server = self ( )
247247
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 )
252249
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 ) )
257260
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
259268
260269 { % { } , % { state | config: config } }
261270 end
@@ -397,8 +406,8 @@ defmodule ElixirLS.Debugger.Server do
397406 defp handle_request ( configuration_done_req ( _ ) , state = % __MODULE__ { } ) do
398407 :int . auto_attach ( [ :break ] , build_attach_mfa ( :breakpoint_reached ) )
399408
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" ]
402411 { _pid , task_ref } = spawn_monitor ( fn -> launch_task ( task , args ) end )
403412
404413 { % { } , % { state | task_ref: task_ref } }
@@ -939,7 +948,7 @@ defmodule ElixirLS.Debugger.Server do
939948 end
940949 end
941950
942- defp initialize ( % { "projectDir" => project_dir } = config ) do
951+ defp initialize ( % { "projectDir" => project_dir } = config , server ) do
943952 task = config [ "task" ]
944953 task_args = config [ "taskArgs" ] || [ ]
945954 auto_interpret_files? = Map . get ( config , "debugAutoInterpretAllModules" , true )
@@ -983,9 +992,8 @@ defmodule ElixirLS.Debugger.Server do
983992
984993 unless is_list ( task_args ) and "--no-compile" in task_args do
985994 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
989997
990998 _ ->
991999 :ok
@@ -1016,7 +1024,8 @@ defmodule ElixirLS.Debugger.Server do
10161024 interpret_specified_modules ( interpret_modules_patterns , exclude_module_pattern )
10171025 end
10181026
1019- ElixirLS.Debugger.Output . send_event ( "initialized" , % { } )
1027+ updated_config = Map . merge ( config , % { "task" => task , "taskArgs" => task_args } )
1028+ send ( server , { :ok , updated_config } )
10201029 end
10211030
10221031 defp set_env_vars ( env ) when is_map ( env ) do
@@ -1104,8 +1113,18 @@ defmodule ElixirLS.Debugger.Server do
11041113 # debugger as well.
11051114 Process . sleep ( 100 )
11061115
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+
11071122 Mix.Task . run ( task , args )
11081123
1124+ Output . debugger_console (
1125+ "Mix.Task.run returned, sleeping.\n Note that debugger needs to be stopped manually.\n "
1126+ )
1127+
11091128 # Starting from Elixir 1.9 Mix.Task.run will return so we need to sleep our
11101129 # process so that the code keeps running (Note: process is expected to be
11111130 # killed by stopping the debugger)
0 commit comments