Skip to content

Commit

Permalink
fix(project_config): show project config selector once on start
Browse files Browse the repository at this point in the history
  • Loading branch information
sidlatau committed Dec 28, 2024
1 parent 54314bc commit 5d8738b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
17 changes: 12 additions & 5 deletions lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local current_device = nil

---@class flutter.Runner
---@field is_running fun(runner: flutter.Runner):boolean
---@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?)
---@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?)
---@field cleanup fun(funner: flutter.Runner)
---@field send fun(runner: flutter.Runner, cmd:string, quiet: boolean?)

Expand Down Expand Up @@ -81,14 +81,16 @@ end

---Handle a finished flutter run command
---@param result string[]
local function on_run_exit(result, cli_args)
---@param cli_args string[]
---@param project_config flutter.ProjectConfig?
local function on_run_exit(result, cli_args, project_config)
local matched_error, msg = has_recoverable_error(result)
if matched_error then
local lines = devices.to_selection_entries(result)
ui.select({
title = ("Flutter run (%s)"):format(msg),
lines = lines,
on_select = function(device) devices.select_device(device, cli_args) end,
on_select = function(device) devices.select_device(device, cli_args, project_config) end,
})
end
shutdown()
Expand Down Expand Up @@ -276,9 +278,14 @@ end

---Run the flutter application
---@param opts RunOpts
function M.run(opts)
---@param project_conf flutter.ProjectConfig?
function M.run(opts, project_conf)
if M.is_running() then return ui.notify("Flutter is already running!") end
select_project_config(function(project_conf) run(opts, project_conf) end)
if project_conf then
run(opts, project_conf)
else
select_project_config(function(selected_project_conf) run(opts, selected_project_conf) end)
end
end

---@param cmd string
Expand Down
7 changes: 4 additions & 3 deletions lua/flutter-tools/devices.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ function M.to_selection_entries(result, device_type)
end, devices)
end

function M.select_device(device, args)
---@param project_config flutter.ProjectConfig?
function M.select_device(device, args, project_config)
if not device then return ui.notify("Sorry there is no device on this line") end
if device.type == EMULATOR then
M.launch_emulator(device)
else
if args then
vim.list_extend(args, { "-d", device.id })
commands.run({ cli_args = args })
commands.run({ cli_args = args }, project_config)
else
commands.run({ device = device })
commands.run({ device = device }, project_config)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/flutter-tools/runners/debugger_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function DebuggerRunner:run(
end

local handle_termination = function()
if next(before_start_logs) ~= nil then on_run_exit(before_start_logs, args) end
if next(before_start_logs) ~= nil then on_run_exit(before_start_logs, args, project_config) end
end

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

0 comments on commit 5d8738b

Please sign in to comment.