Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dap config selector ui, dap single request with no device #271

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lua/flutter-tools/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,24 @@ local function run(opts, project_conf)
executable.get(function(paths)
local args = opts.cli_args or get_run_args(opts, project_conf)
ui.notify("Starting flutter project...")
runner = use_debugger_runner() and debugger_runner or job_runner
if use_debugger_runner() then
if not debugger_runner.has_config() then
require("flutter-tools.dap")
.select_config(paths, function(launch_config)
debugger_runner:set_config(launch_config)
if not launch_config.deviceId then
-- if no device set in launch_config, get one to avoid selecting config twice
devices.list_devices()
return
end
run(opts, project_conf)
end)
return
end
runner = debugger_runner
else
runner = job_runner
end
runner:run(paths, args, lsp.get_lsp_root_dir(), on_run_data, on_run_exit)
end)
end
Expand Down
32 changes: 32 additions & 0 deletions lua/flutter-tools/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ end

local M = {}

function M.select_config(paths, callback)
local launch_configurations = {}
local launch_configuration_count = 0
require("flutter-tools.config").debugger.register_configurations(paths)
local all_configurations = dap.configurations.dart
for _, c in ipairs(all_configurations) do
if c.request == "launch" then
table.insert(launch_configurations, c)
launch_configuration_count = launch_configuration_count + 1
end
end
if launch_configuration_count == 0 then
ui.notify("No launch configuration for DAP found", ui.ERROR)
return
elseif launch_configuration_count == 1 then
callback(launch_configurations[1])
else
local launch_options = vim.tbl_map(function(item)
return {
text = item.name,
type = ui.entry_type.DEBUG_CONFIG,
data = item,
}
end, launch_configurations)
ui.select({
title = "Select launch configuration",
lines = launch_options,
on_select = callback,
})
end
end

function M.setup(config)
local opts = config.debugger
require("flutter-tools.executable").get(function(paths)
Expand Down
37 changes: 11 additions & 26 deletions lua/flutter-tools/runners/debugger_runner.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local lazy = require("flutter-tools.lazy")
local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
local dev_tools = lazy.require("flutter-tools.dev_tools") ---@module "flutter-tools.dev_tools"
local config = lazy.require("flutter-tools.config") ---@module "flutter-tools.config"
local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.utils"
local _, dap = pcall(require, "dap")

Expand All @@ -26,10 +25,20 @@ local command_requests = {
local service_activation_requests = {
visual_debug = "ext.flutter.debugPaint",
}
local launch_config = nil

function DebuggerRunner:set_config(config) launch_config = config end

function DebuggerRunner:has_config() return launch_config ~= nil end

function DebuggerRunner:is_running() return dap.session() ~= nil end

function DebuggerRunner:run(paths, args, cwd, on_run_data, on_run_exit)
if not launch_config then
ui.notify("No launch configuration for DAP chosen", ui.ERROR)
return
end

local started = false
local before_start_logs = {}
service_extensions_isolateid = {}
Expand Down Expand Up @@ -74,31 +83,6 @@ function DebuggerRunner:run(paths, args, cwd, on_run_data, on_run_exit)
end
end

local launch_configurations = {}
local launch_configuration_count = 0
config.debugger.register_configurations(paths)
local all_configurations = require("dap").configurations.dart
for _, c in ipairs(all_configurations) do
if c.request == "launch" then
table.insert(launch_configurations, c)
launch_configuration_count = launch_configuration_count + 1
end
end

local launch_config
if launch_configuration_count == 0 then
ui.notify("No launch configuration for DAP found", ui.ERROR)
return
elseif launch_configuration_count == 1 then
launch_config = launch_configurations[1]
else
launch_config = require("dap.ui").pick_one_sync(
launch_configurations,
"Select launch configuration",
function(item) return fmt("%s : %s", item.name, item.program, vim.inspect(item.args)) end
)
end
if not launch_config then return end
launch_config = vim.deepcopy(launch_config)
launch_config.cwd = cwd
launch_config.args = vim.list_extend(launch_config.args or {}, args or {})
Expand Down Expand Up @@ -132,6 +116,7 @@ function DebuggerRunner:send(cmd, quiet)
end

function DebuggerRunner:cleanup()
launch_config = nil
if dap.session() then dap.terminate() end
end

Expand Down
7 changes: 7 additions & 0 deletions lua/flutter-tools/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local fmt = string.format
local entry_type = {
CODE_ACTION = 1,
DEVICE = 2,
DEBUG_CONFIG = 3,
}

---@generic T
Expand Down Expand Up @@ -103,6 +104,12 @@ local function get_telescope_picker_config(items, title, on_select)
hint = data.platform,
command = function() on_select(data) end,
}
elseif item.type == entry_type.DEBUG_CONFIG then
return {
id = data.name,
label = data.name,
command = function() on_select(data) end,
}
end
end, filtered),
{ title = title }
Expand Down