Skip to content

Commit da3682a

Browse files
authored
feat: add FlutterDebug command (#420)
1 parent cb09e56 commit da3682a

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ require("flutter-tools").setup {} -- use defaults
148148

149149
# Usage
150150

151-
- `FlutterRun` - Run the current project. This needs to be run from within a flutter project.
151+
- `FlutterRun` - Run the current project. Respects `config.debugger.enabled` setting.
152+
- `FlutterDebug` - Force run current project in debug mode.
152153
- `FlutterDevices` - Brings up a list of connected devices to select from.
153154
- `FlutterEmulators` - Similar to devices but shows a list of emulators to choose from.
154155
- `FlutterReload` - Reload the running project.

lua/flutter-tools.lua

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ end
2323
local function setup_commands()
2424
-- Commands
2525
command("FlutterRun", function(data) commands.run_command(data.args) end, { nargs = "*" })
26+
command("FlutterDebug", function(data) commands.run_command(data.args) end, { nargs = "*" })
2627
command("FlutterLspRestart", lsp.restart)
2728
command("FlutterDetach", commands.detach)
2829
command("FlutterReload", commands.reload)

lua/flutter-tools/commands.lua

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local parser = lazy.require("flutter-tools.utils.yaml_parser")
1515

1616
local M = {}
1717

18-
---@alias RunOpts {cli_args: string[]?, args: string[]?, device: Device?}
18+
---@alias RunOpts {cli_args: string[]?, args: string[]?, device: Device?, force_debug: boolean?}
1919

2020
---@type table?
2121
local current_device = nil
@@ -29,11 +29,13 @@ local current_device = nil
2929
---@type flutter.Runner?
3030
local runner = nil
3131

32-
local function use_debugger_runner()
33-
if not config.debugger.enabled then return false end
34-
local dap_ok, _ = pcall(require, "dap")
35-
if dap_ok then return true end
36-
ui.notify("debugger runner was request but nvim-dap is not installed!", ui.ERROR)
32+
local function use_debugger_runner(force_debug)
33+
if force_debug or config.debugger.enabled then
34+
local dap_ok, _ = pcall(require, "dap")
35+
if dap_ok then return true end
36+
ui.notify("debugger runner was request but nvim-dap is not installed!", ui.ERROR)
37+
return false
38+
end
3739
return false
3840
end
3941

@@ -95,9 +97,10 @@ end
9597
--- Take arguments from the commandline and pass
9698
--- them to the run command
9799
---@param args string
98-
function M.run_command(args)
100+
---@param force_debug boolean true if the command is a debug command
101+
function M.run_command(args, force_debug)
99102
args = args and args ~= "" and vim.split(args, " ") or nil
100-
M.run({ args = args })
103+
M.run({ args = args, force_debug = force_debug })
101104
end
102105

103106
---@param callback fun(project_config: flutter.ProjectConfig?)
@@ -137,7 +140,7 @@ local function get_run_args(opts, conf)
137140
local dev_url = dev_tools.get_url()
138141
local additional_args = conf and conf.additional_args
139142

140-
if not use_debugger_runner() then vim.list_extend(args, { "run" }) end
143+
if not use_debugger_runner(opts.force_debug) then vim.list_extend(args, { "run" }) end
141144
if not cmd_args and device then vim.list_extend(args, { "-d", device }) end
142145
if web_port then vim.list_extend(args, { "--web-port", web_port }) end
143146
if cmd_args then vim.list_extend(args, cmd_args) end
@@ -266,7 +269,7 @@ local function run(opts, project_conf)
266269
else
267270
ui.notify("Starting dart project...")
268271
end
269-
runner = use_debugger_runner() and debugger_runner or job_runner
272+
runner = use_debugger_runner(opts.force_debug) and debugger_runner or job_runner
270273
runner:run(paths, args, cwd, on_run_data, on_run_exit, is_flutter_project, project_conf)
271274
end)
272275
end

0 commit comments

Comments
 (0)