Skip to content

Commit a5a6036

Browse files
authoredDec 28, 2024
fix(project_config): show project config selector once on start (#423)
1 parent 54314bc commit a5a6036

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
 

‎lua/flutter-tools/commands.lua

+12-5
Original file line numberDiff line numberDiff line change
@@ -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), 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?), is_flutter_project: boolean, project_conf: flutter.ProjectConfig?)
2626
---@field cleanup fun(funner: flutter.Runner)
2727
---@field send fun(runner: flutter.Runner, cmd:string, quiet: boolean?)
2828

@@ -81,14 +81,16 @@ end
8181

8282
---Handle a finished flutter run command
8383
---@param result string[]
84-
local function on_run_exit(result, cli_args)
84+
---@param cli_args string[]
85+
---@param project_config flutter.ProjectConfig?
86+
local function on_run_exit(result, cli_args, project_config)
8587
local matched_error, msg = has_recoverable_error(result)
8688
if matched_error then
8789
local lines = devices.to_selection_entries(result)
8890
ui.select({
8991
title = ("Flutter run (%s)"):format(msg),
9092
lines = lines,
91-
on_select = function(device) devices.select_device(device, cli_args) end,
93+
on_select = function(device) devices.select_device(device, cli_args, project_config) end,
9294
})
9395
end
9496
shutdown()
@@ -276,9 +278,14 @@ end
276278

277279
---Run the flutter application
278280
---@param opts RunOpts
279-
function M.run(opts)
281+
---@param project_conf flutter.ProjectConfig?
282+
function M.run(opts, project_conf)
280283
if M.is_running() then return ui.notify("Flutter is already running!") end
281-
select_project_config(function(project_conf) run(opts, project_conf) end)
284+
if project_conf then
285+
run(opts, project_conf)
286+
else
287+
select_project_config(function(selected_project_conf) run(opts, selected_project_conf) end)
288+
end
282289
end
283290

284291
---@param cmd string

‎lua/flutter-tools/devices.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ function M.to_selection_entries(result, device_type)
7575
end, devices)
7676
end
7777

78-
function M.select_device(device, args)
78+
---@param project_config flutter.ProjectConfig?
79+
function M.select_device(device, args, project_config)
7980
if not device then return ui.notify("Sorry there is no device on this line") end
8081
if device.type == EMULATOR then
8182
M.launch_emulator(device)
8283
else
8384
if args then
8485
vim.list_extend(args, { "-d", device.id })
85-
commands.run({ cli_args = args })
86+
commands.run({ cli_args = args }, project_config)
8687
else
87-
commands.run({ device = device })
88+
commands.run({ device = device }, project_config)
8889
end
8990
end
9091
end

‎lua/flutter-tools/runners/debugger_runner.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function DebuggerRunner:run(
124124
end
125125

126126
local handle_termination = function()
127-
if next(before_start_logs) ~= nil then on_run_exit(before_start_logs, args) end
127+
if next(before_start_logs) ~= nil then on_run_exit(before_start_logs, args, project_config) end
128128
end
129129

130130
dap.listeners.before["event_exited"][plugin_identifier] = function(_, _) handle_termination() end

0 commit comments

Comments
 (0)