From 5d8738be27035b396dd8e6cd64bc95e8a8077250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tautvydas=20S=CC=8Cidlauskas?= Date: Sat, 28 Dec 2024 20:38:59 +0200 Subject: [PATCH] fix(project_config): show project config selector once on start --- lua/flutter-tools/commands.lua | 17 ++++++++++++----- lua/flutter-tools/devices.lua | 7 ++++--- lua/flutter-tools/runners/debugger_runner.lua | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 03b82e6..a08741b 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -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?) @@ -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() @@ -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 diff --git a/lua/flutter-tools/devices.lua b/lua/flutter-tools/devices.lua index f4ee2b8..2b8a6fb 100644 --- a/lua/flutter-tools/devices.lua +++ b/lua/flutter-tools/devices.lua @@ -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 diff --git a/lua/flutter-tools/runners/debugger_runner.lua b/lua/flutter-tools/runners/debugger_runner.lua index 85c8769..5b0ec55 100644 --- a/lua/flutter-tools/runners/debugger_runner.lua +++ b/lua/flutter-tools/runners/debugger_runner.lua @@ -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