diff --git a/README.md b/README.md index 0784e41..7f1ec41 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,8 @@ require("flutter-tools").setup {} -- use defaults # Usage -- `FlutterRun` - Run the current project. This needs to be run from within a flutter project. +- `FlutterRun` - Run the current project. Respects `config.debugger.enabled` setting. +- `FlutterDebug` - Force run current project in debug mode. - `FlutterDevices` - Brings up a list of connected devices to select from. - `FlutterEmulators` - Similar to devices but shows a list of emulators to choose from. - `FlutterReload` - Reload the running project. diff --git a/lua/flutter-tools.lua b/lua/flutter-tools.lua index e53fe12..98ebb07 100644 --- a/lua/flutter-tools.lua +++ b/lua/flutter-tools.lua @@ -23,6 +23,7 @@ end local function setup_commands() -- Commands command("FlutterRun", function(data) commands.run_command(data.args) end, { nargs = "*" }) + command("FlutterDebug", function(data) commands.run_command(data.args) end, { nargs = "*" }) command("FlutterLspRestart", lsp.restart) command("FlutterDetach", commands.detach) command("FlutterReload", commands.reload) diff --git a/lua/flutter-tools/commands.lua b/lua/flutter-tools/commands.lua index 9026307..faa464d 100644 --- a/lua/flutter-tools/commands.lua +++ b/lua/flutter-tools/commands.lua @@ -15,7 +15,7 @@ local parser = lazy.require("flutter-tools.utils.yaml_parser") local M = {} ----@alias RunOpts {cli_args: string[]?, args: string[]?, device: Device?} +---@alias RunOpts {cli_args: string[]?, args: string[]?, device: Device?, force_debug: boolean?} ---@type table? local current_device = nil @@ -29,11 +29,13 @@ local current_device = nil ---@type flutter.Runner? local runner = nil -local function use_debugger_runner() - if not config.debugger.enabled then return false end - local dap_ok, _ = pcall(require, "dap") - if dap_ok then return true end - ui.notify("debugger runner was request but nvim-dap is not installed!", ui.ERROR) +local function use_debugger_runner(force_debug) + if force_debug or config.debugger.enabled then + local dap_ok, _ = pcall(require, "dap") + if dap_ok then return true end + ui.notify("debugger runner was request but nvim-dap is not installed!", ui.ERROR) + return false + end return false end @@ -95,9 +97,10 @@ end --- Take arguments from the commandline and pass --- them to the run command ---@param args string -function M.run_command(args) +---@param force_debug boolean true if the command is a debug command +function M.run_command(args, force_debug) args = args and args ~= "" and vim.split(args, " ") or nil - M.run({ args = args }) + M.run({ args = args, force_debug = force_debug }) end ---@param callback fun(project_config: flutter.ProjectConfig?) @@ -137,7 +140,7 @@ local function get_run_args(opts, conf) local dev_url = dev_tools.get_url() local additional_args = conf and conf.additional_args - if not use_debugger_runner() then vim.list_extend(args, { "run" }) end + if not use_debugger_runner(opts.force_debug) then vim.list_extend(args, { "run" }) end if not cmd_args and device then vim.list_extend(args, { "-d", device }) end if web_port then vim.list_extend(args, { "--web-port", web_port }) end if cmd_args then vim.list_extend(args, cmd_args) end @@ -266,7 +269,7 @@ local function run(opts, project_conf) else ui.notify("Starting dart project...") end - runner = use_debugger_runner() and debugger_runner or job_runner + runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner runner:run(paths, args, cwd, on_run_data, on_run_exit, is_flutter_project, project_conf) end) end