@@ -22,7 +22,7 @@ local current_device = nil
2222
2323--- @class flutter.Runner
2424--- @field is_running fun ( runner : flutter.Runner ): boolean
25- --- @field run fun ( runner : flutter.Runner , paths : table , args : table , cwd : string , on_run_data : fun ( is_err : boolean , data : string ), on_run_exit : fun ( data : string[] , args : table , project_conf : flutter.ProjectConfig ?), is_flutter_project : boolean , project_conf : flutter.ProjectConfig ?)
25+ --- @field run fun ( runner : flutter.Runner , paths : table , args : table , cwd : string , on_run_data : fun ( is_err : boolean , data : string ), on_run_exit : fun ( data : string[] , args : table , project_conf : flutter.ProjectConfig ?, launch_config : dap.Configuration ? ), is_flutter_project : boolean , project_conf : flutter.ProjectConfig ?, launch_config : dap.Configuration ?)
2626--- @field cleanup fun ( funner : flutter.Runner )
2727--- @field send fun ( runner : flutter.Runner , cmd : string , quiet : boolean ?)
2828
8383--- @param result string[]
8484--- @param cli_args string[]
8585--- @param project_config flutter.ProjectConfig ?
86- local function on_run_exit (result , cli_args , project_config )
86+ --- @param launch_config dap.Configuration ?
87+ local function on_run_exit (result , cli_args , project_config , launch_config )
8788 local matched_error , msg = has_recoverable_error (result )
8889 if matched_error then
8990 local lines = devices .to_selection_entries (result )
9091 ui .select ({
9192 title = (" Flutter run (%s)" ):format (msg ),
9293 lines = lines ,
93- on_select = function (device ) devices .select_device (device , cli_args , project_config ) end ,
94+ on_select = function (device )
95+ vim .list_extend (cli_args , { " -d" , device .id })
96+ if launch_config then vim .list_extend (launch_config .args , { " -d" , device .id }) end
97+ M .run ({ cli_args = cli_args }, project_config , launch_config )
98+ end ,
9499 })
95100 end
96101 shutdown ()
245250
246251--- @param opts RunOpts
247252--- @param project_conf flutter.ProjectConfig ?
248- local function run (opts , project_conf )
253+ --- @param launch_config dap.Configuration ?
254+ local function run (opts , project_conf , launch_config )
249255 opts = opts or {}
250256 executable .get (function (paths )
251257 local args = opts .cli_args or get_run_args (opts , project_conf )
@@ -272,19 +278,31 @@ local function run(opts, project_conf)
272278 ui .notify (" Starting dart project..." )
273279 end
274280 runner = use_debugger_runner (opts .force_debug ) and debugger_runner or job_runner
275- runner :run (paths , args , cwd , on_run_data , on_run_exit , is_flutter_project , project_conf )
281+ runner :run (
282+ paths ,
283+ args ,
284+ cwd ,
285+ on_run_data ,
286+ on_run_exit ,
287+ is_flutter_project ,
288+ project_conf ,
289+ launch_config
290+ )
276291 end )
277292end
278293
279294--- Run the flutter application
280295--- @param opts RunOpts
281296--- @param project_conf flutter.ProjectConfig ?
282- function M .run (opts , project_conf )
297+ --- @param launch_config dap.Configuration ?
298+ function M .run (opts , project_conf , launch_config )
283299 if M .is_running () then return ui .notify (" Flutter is already running!" ) end
284300 if project_conf then
285- run (opts , project_conf )
301+ run (opts , project_conf , launch_config )
286302 else
287- select_project_config (function (selected_project_conf ) run (opts , selected_project_conf ) end )
303+ select_project_config (
304+ function (selected_project_conf ) run (opts , selected_project_conf , launch_config ) end
305+ )
288306 end
289307end
290308
0 commit comments