Skip to content

Commit d135e1d

Browse files
authored
fix(flutter-debug): pass run options to runner callbacks (#444)
This fixes `FlutterDebug` command when multiple devices are available. Previously `force_debug` option was not passed to `on_run_exit` callback
1 parent 4a8aad2 commit d135e1d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lua/flutter-tools/commands.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local current_device = nil
2323

2424
---@class flutter.Runner
2525
---@field is_running fun(runner: flutter.Runner):boolean
26-
---@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?)
26+
---@field run fun(runner: flutter.Runner, opts: RunOpts, paths:table, args:table, cwd:string, on_run_data:fun(is_err:boolean, data:string), on_run_exit:fun(data:string[], args: table, opts: RunOpts?, project_conf: flutter.ProjectConfig?,launch_config: dap.Configuration?), is_flutter_project: boolean, project_conf: flutter.ProjectConfig?, launch_config: dap.Configuration?)
2727
---@field cleanup fun(funner: flutter.Runner)
2828
---@field send fun(runner: flutter.Runner, cmd:string, quiet: boolean?)
2929
---@field attach 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?))
@@ -84,9 +84,10 @@ end
8484
---Handle a finished flutter run command
8585
---@param result string[]
8686
---@param cli_args string[]
87+
---@param opts RunOpts?
8788
---@param project_config flutter.ProjectConfig?
8889
---@param launch_config dap.Configuration?
89-
local function on_run_exit(result, cli_args, project_config, launch_config)
90+
local function on_run_exit(result, cli_args, opts, project_config, launch_config)
9091
local matched_error, msg = has_recoverable_error(result)
9192
if matched_error then
9293
local lines = devices.to_selection_entries(result)
@@ -96,7 +97,10 @@ local function on_run_exit(result, cli_args, project_config, launch_config)
9697
on_select = function(device)
9798
vim.list_extend(cli_args, { "-d", device.id })
9899
if launch_config then vim.list_extend(launch_config.args, { "-d", device.id }) end
99-
M.run({ cli_args = cli_args }, project_config, launch_config)
100+
opts = opts or {}
101+
opts.cli_args = cli_args
102+
103+
M.run(opts, project_config, launch_config)
100104
end,
101105
})
102106
end
@@ -281,6 +285,7 @@ local function run(opts, project_conf, launch_config)
281285
end
282286
runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner
283287
runner:run(
288+
opts,
284289
paths,
285290
args,
286291
cwd,

lua/flutter-tools/runners/debugger_runner.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ local function register_dap_listeners(on_run_data, on_run_exit)
143143
end
144144

145145
function DebuggerRunner:run(
146+
opts,
146147
paths,
147148
args,
148149
cwd,
@@ -166,7 +167,7 @@ function DebuggerRunner:run(
166167
end
167168
end,
168169
function(before_start_logs)
169-
on_run_exit(before_start_logs, args, project_config, selected_launch_config)
170+
on_run_exit(before_start_logs, args, opts, project_config, selected_launch_config)
170171
end
171172
)
172173

lua/flutter-tools/runners/job_runner.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ local command_keys = {
2424
function JobRunner:is_running() return run_job ~= nil end
2525

2626
function JobRunner:run(
27+
opts,
2728
paths,
2829
args,
2930
cwd,
@@ -53,7 +54,9 @@ function JobRunner:run(
5354
dev_tools.handle_log(data)
5455
end),
5556
on_stderr = vim.schedule_wrap(function(_, data, _) on_run_data(true, data) end),
56-
on_exit = vim.schedule_wrap(function(j, _) on_run_exit(j:result(), args, project_config) end),
57+
on_exit = vim.schedule_wrap(
58+
function(j, _) on_run_exit(j:result(), args, opts, project_config) end
59+
),
5760
})
5861
run_job:start()
5962
end

0 commit comments

Comments
 (0)