Skip to content

Commit

Permalink
feat: improved nvim-dap configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-kulik committed Mar 12, 2024
1 parent 62f18e5 commit 1227802
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,6 @@ This plugin supports only iOS and macOS applications. However, if you develop Sw

[nvim-dap](https://github.com/mfussenegger/nvim-dap) plugin lets you debug applications like in any other IDE. On top of that [nvim-dap-ui](https://github.com/rcarriga/nvim-dap-ui) extension will present for you all panels with stack, breakpoints, variables, logs, etc.

<details>
<summary>See nvim-dap configuration</summary>

To configure DAP for development:

- Download codelldb VS Code plugin from: [HERE](https://github.com/vadimcn/codelldb/releases). For macOS use `darwin` version. Just unzip `vsix` file and set paths below.
Expand All @@ -520,40 +517,23 @@ return {
"wojciech-kulik/xcodebuild.nvim"
},
config = function()
local dap = require("dap")
local xcodebuild = require("xcodebuild.integrations.dap")
-- SAMPLE PATH, change it to your local codelldb path
local codelldbPath = os.getenv("HOME") .. "/tools/codelldb-aarch64-darwin/extension/adapter/codelldb"

xcodebuild.setup(codelldbPath)

-- disables annoying warning that requires hitting enter
local orig_notify = require("dap.utils").notify
require("dap.utils").notify = function(msg, log_level)
if not string.find(msg, "Either the adapter is slow") then
orig_notify(msg, log_level)
end
end

-- sample keymaps to debug application
vim.keymap.set("n", "<leader>dd", xcodebuild.build_and_debug, { desc = "Build & Debug" })
vim.keymap.set("n", "<leader>dr", xcodebuild.debug_without_build, { desc = "Debug Without Building" })
vim.keymap.set("n", "<leader>dt", xcodebuild.debug_tests, { desc = "Debug Tests" })
vim.keymap.set("n", "<leader>dT", xcodebuild.debug_class_tests, { desc = "Debug Class Tests" })
vim.keymap.set("n", "<leader>b", xcodebuild.toggle_breakpoint, { desc = "Toggle Breakpoint" })
vim.keymap.set("n", "<leader>B", xcodebuild.toggle_message_breakpoint, { desc = "Toggle Message Breakpoint" })
vim.keymap.set("n", "<Leader>dx", function()
if dap.session() then
dap.terminate()
end
require("xcodebuild.actions").cancel()
end, { desc = "Terminate debugger" })
vim.keymap.set("n", "<leader>dx", xcodebuild.terminate_session, { desc = "Terminate Debugger" })
end,
}
```

</details>

### 📲 Debugging On iOS 17+ Device

Since iOS 17, a new secure connection between Mac and mobile devices is required. Xcodebuild.nvim uses [pymobiledevice3](https://github.com/doronz88/pymobiledevice3)
Expand Down
22 changes: 6 additions & 16 deletions doc/xcodebuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3059,34 +3059,19 @@ Sample `nvim-dap` configuration:
"wojciech-kulik/xcodebuild.nvim"
},
config = function()
local dap = require("dap")
local xcodebuild = require("xcodebuild.integrations.dap")
-- SAMPLE PATH, change it to your local codelldb path
local codelldbPath = "/YOUR_PATH/codelldb-aarch64-darwin/extension/adapter/codelldb"

xcodebuild.setup(codelldbPath)

-- disables annoying warning that requires hitting enter
local orig_notify = require("dap.utils").notify
require("dap.utils").notify = function(msg, log_level)
if not string.find(msg, "Either the adapter is slow") then
orig_notify(msg, log_level)
end
end

-- sample keymaps to debug application
vim.keymap.set("n", "<leader>dd", xcodebuild.build_and_debug, { desc = "Build & Debug" })
vim.keymap.set("n", "<leader>dr", xcodebuild.debug_without_build, { desc = "Debug Without Building" })
vim.keymap.set("n", "<leader>dt", xcodebuild.debug_tests, { desc = "Debug Tests" })
vim.keymap.set("n", "<leader>dT", xcodebuild.debug_class_tests, { desc = "Debug Class Tests" })
vim.keymap.set("n", "<leader>b", xcodebuild.toggle_breakpoint, { desc = "Toggle Breakpoint" })
vim.keymap.set("n", "<leader>B", xcodebuild.toggle_message_breakpoint, { desc = "Toggle Message Breakpoint" })
vim.keymap.set("n", "<Leader>dx", function()
if dap.session() then
dap.terminate()
end
require("xcodebuild.actions").cancel()
end, { desc = "Terminate debugger" })
vim.keymap.set("n", "<leader>dx", xcodebuild.terminate_session, { desc = "Terminate Debugger" })
end,
}
<
Expand Down Expand Up @@ -3249,6 +3234,11 @@ M.toggle_message_breakpoint()
To print a variable, wrap it with {}: `{myObject.myProperty}`.


*xcodebuild.integrations.dap.terminate_session*
M.terminate_session()
Terminates the debugger session, cancels the current action, and closes the `nvim-dap-ui`.


*xcodebuild.integrations.dap.setup*
M.setup({codelldbPath}, {loadBreakpoints})
Sets up the adapter and configuration for the `nvim-dap` plugin.
Expand Down
39 changes: 23 additions & 16 deletions lua/xcodebuild/integrations/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,19 @@
--- "wojciech-kulik/xcodebuild.nvim"
--- },
--- config = function()
--- local dap = require("dap")
--- local xcodebuild = require("xcodebuild.integrations.dap")
--- -- SAMPLE PATH, change it to your local codelldb path
--- local codelldbPath = "/YOUR_PATH/codelldb-aarch64-darwin/extension/adapter/codelldb"
---
--- xcodebuild.setup(codelldbPath)
---
--- -- disables annoying warning that requires hitting enter
--- local orig_notify = require("dap.utils").notify
--- require("dap.utils").notify = function(msg, log_level)
--- if not string.find(msg, "Either the adapter is slow") then
--- orig_notify(msg, log_level)
--- end
--- end
---
--- -- sample keymaps to debug application
--- vim.keymap.set("n", "<leader>dd", xcodebuild.build_and_debug, { desc = "Build & Debug" })
--- vim.keymap.set("n", "<leader>dr", xcodebuild.debug_without_build, { desc = "Debug Without Building" })
--- vim.keymap.set("n", "<leader>dt", xcodebuild.debug_tests, { desc = "Debug Tests" })
--- vim.keymap.set("n", "<leader>dT", xcodebuild.debug_class_tests, { desc = "Debug Class Tests" })
--- vim.keymap.set("n", "<leader>b", xcodebuild.toggle_breakpoint, { desc = "Toggle Breakpoint" })
--- vim.keymap.set("n", "<leader>B", xcodebuild.toggle_message_breakpoint, { desc = "Toggle Message Breakpoint" })
--- vim.keymap.set("n", "<Leader>dx", function()
--- if dap.session() then
--- dap.terminate()
--- end
--- require("xcodebuild.actions").cancel()
--- end, { desc = "Terminate debugger" })
--- vim.keymap.set("n", "<leader>dx", xcodebuild.terminate_session, { desc = "Terminate Debugger" })
--- end,
--- }
---<
Expand Down Expand Up @@ -511,6 +496,20 @@ function M.toggle_message_breakpoint()
M.save_breakpoints()
end

---Terminates the debugger session, cancels the current action, and closes the `nvim-dap-ui`.
function M.terminate_session()
if require("dap").session() then
require("dap").terminate()
end

require("xcodebuild.actions").cancel()

local success, dapui = pcall(require, "dapui")
if success then
dapui.close()
end
end

---Sets up the adapter and configuration for the `nvim-dap` plugin.
---{codelldbPath} - path to the `codelldb` binary.
---
Expand All @@ -532,6 +531,14 @@ function M.setup(codelldbPath, loadBreakpoints)
end,
})
end

local orig_notify = require("dap.utils").notify
---@diagnostic disable-next-line: duplicate-set-field
require("dap.utils").notify = function(msg, log_level)
if not string.find(msg, "Either the adapter is slow", 1, true) then
orig_notify(msg, log_level)
end
end
end

return M

0 comments on commit 1227802

Please sign in to comment.