Skip to content

Commit

Permalink
feat: added debug actions & sections to XcodebuildPicker
Browse files Browse the repository at this point in the history
Resolves #130
  • Loading branch information
wojciech-kulik committed Apr 13, 2024
1 parent 4f9a63e commit 9b30d80
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 25 deletions.
5 changes: 5 additions & 0 deletions doc/xcodebuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,11 @@ M.terminate_session()
Terminates the debugger session, cancels the current action, and closes the `nvim-dap-ui`.


M.get_actions() *xcodebuild.integrations.dap.get_actions*
Returns a list of actions with names for the `nvim-dap` plugin.
@return table<{name:string,action:function}>


*xcodebuild.integrations.dap.setup*
M.setup({codelldbPath}, {loadBreakpoints})
Sets up the adapter and configuration for the `nvim-dap` plugin.
Expand Down
12 changes: 12 additions & 0 deletions lua/xcodebuild/integrations/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ function M.terminate_session()
end
end

---Returns a list of actions with names for the `nvim-dap` plugin.
---@return table<{name:string,action:function}>
function M.get_actions()
return {
{ name = "Build & Debug", action = M.build_and_debug },
{ name = "Debug Without Building", action = M.debug_without_build },
{ name = "Debug Tests", action = M.debug_tests },
{ name = "Debug Current Test Class", action = M.debug_class_tests },
{ name = "Clear DAP Console", action = M.clear_console },
}
end

---Sets up the adapter and configuration for the `nvim-dap` plugin.
---{codelldbPath} - path to the `codelldb` binary.
---
Expand Down
89 changes: 64 additions & 25 deletions lua/xcodebuild/ui/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,26 +498,29 @@ function M.show_all_actions()
"Build For Testing",
"Run Without Building",
"Cancel Running Action",

"---------------------------------",
"Run Current Test Plan (All Tests)",
"Run Current Test Target",
"Run Current Test Class",
"Run Nearest Test",
"Rerun Failed Tests",
"Repeat Last Test Run",

"---------------------------------",
"Select Scheme",
"Select Device",
"Select Test Plan",

"---------------------------------",
"Toggle Logs",
"---------------------------------",
"Show Project Manager",
"Show Current Configuration",
"Show Configuration Wizard",
"---------------------------------",
"Boot Selected Simulator",
"Clean DerivedData",
"Install Application",
"Uninstall Application",
"---------------------------------",
"Clean DerivedData",
"Open Project in Xcode",
}
local actionsPointers = {
Expand All @@ -528,60 +531,96 @@ function M.show_all_actions()
actions.run,
actions.cancel,

function() end,

actions.run_tests,
actions.run_target_tests,
actions.run_class_tests,
actions.run_nearest_test,
actions.rerun_failed_tests,
actions.repeat_last_test_run,

function() end,

actions.select_scheme,
actions.select_device,
actions.select_testplan,

function() end,

actions.toggle_logs,

function() end,

actions.show_project_manager_actions,
actions.show_current_config,
actions.configure_project,

function() end,

actions.boot_simulator,
actions.clean_derived_data,
actions.install_app,
actions.uninstall_app,

function() end,

actions.clean_derived_data,
actions.open_in_xcode,
}

if not projectConfig.is_project_configured() then
actionsNames = { "Show Configuration Wizard" }
actionsPointers = { actions.configure_project }
end

if config.prepare_snapshot_test_previews then
if util.is_not_empty(snapshots.get_failing_snapshots()) then
table.insert(actionsNames, 13, "Preview Failing Snapshot Tests")
table.insert(actionsPointers, 13, actions.show_failing_snapshot_tests)
else
local loadedDap, dap = pcall(require, "dap")
local isDapConfigured = loadedDap
and dap.configurations
and util.is_not_empty(dap.configurations["swift"])
local toggleLogsIndex = util.indexOf(actionsNames, "Toggle Logs") or 16

if config.prepare_snapshot_test_previews then
if util.is_not_empty(snapshots.get_failing_snapshots()) then
table.insert(actionsNames, toggleLogsIndex, "Preview Failing Snapshot Tests")
table.insert(actionsPointers, toggleLogsIndex, actions.show_failing_snapshot_tests)
end
end
end

if config.code_coverage.enabled then
table.insert(actionsNames, 13, "Toggle Code Coverage")
table.insert(actionsPointers, 13, actions.toggle_code_coverage)
if config.code_coverage.enabled then
if require("xcodebuild.code_coverage.report").is_report_available() then
table.insert(actionsNames, toggleLogsIndex, "Show Code Coverage Report")
table.insert(actionsPointers, toggleLogsIndex, actions.show_code_coverage_report)
table.insert(actionsNames, toggleLogsIndex + 1, "Toggle Code Coverage")
table.insert(actionsPointers, toggleLogsIndex + 1, actions.toggle_code_coverage)
else
table.insert(actionsNames, toggleLogsIndex, "Toggle Code Coverage")
table.insert(actionsPointers, toggleLogsIndex, actions.toggle_code_coverage)
end
end

if require("xcodebuild.code_coverage.report").is_report_available() then
table.insert(actionsNames, 14, "Show Code Coverage Report")
table.insert(actionsPointers, 14, actions.show_code_coverage_report)
if config.test_explorer.enabled then
table.insert(actionsNames, toggleLogsIndex + 1, "Toggle Test Explorer")
table.insert(actionsPointers, toggleLogsIndex + 1, actions.test_explorer_toggle)
end
end

if config.test_explorer.enabled then
local row = util.indexOf(actionsNames, "Toggle Logs")
if row then
table.insert(actionsNames, row + 1, "Toggle Test Explorer")
table.insert(actionsPointers, row + 1, actions.test_explorer_toggle)
if isDapConfigured then
local dapIntegration = require("xcodebuild.integrations.dap")
local dapActions = dapIntegration.get_actions()
local counter = 7

table.insert(dapActions, 1, { name = "---------------------------------", action = function() end })

for _, action in ipairs(dapActions) do
table.insert(actionsNames, counter, action.name)
table.insert(actionsPointers, counter, action.action)
counter = counter + 1
end
end
end

M.show("Xcodebuild Actions", actionsNames, function(_, index)
if index > 12 or #actionsNames == 1 then
local selectSchemeIndex = util.indexOf(actionsNames, "Select Scheme")

if #actionsNames == 1 or index >= selectSchemeIndex then
actionsPointers[index]()
else
vim.defer_fn(actionsPointers[index], 100)
Expand Down

0 comments on commit 9b30d80

Please sign in to comment.