Skip to content

Commit

Permalink
[nvim] dap
Browse files Browse the repository at this point in the history
  • Loading branch information
w3ye committed Sep 2, 2024
1 parent 4a9cbc8 commit ea8aa83
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 2 deletions.
3 changes: 1 addition & 2 deletions nvim/.config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
"nvim-dap": { "branch": "master", "commit": "281a2e4cd1e7a17cea7ecb1745d84a8ab1249925" },
"nvim-dap-ui": { "branch": "master", "commit": "1c351e4e417d4691da12948b6ecf966936a56d28" },
"nvim-dap-vscode-js": { "branch": "main", "commit": "03bd29672d7fab5e515fc8469b7d07cc5994bbf6" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "484995d573c0f0563f6a66ebdd6c67b649489615" },
"nvim-lspconfig": { "branch": "master", "commit": "3ad562700d0615818bf358268ac8914f6ce2b079" },
"nvim-navbuddy": { "branch": "master", "commit": "f22bac988f2dd073601d75ba39ea5636ab6e38cb" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
Expand All @@ -62,7 +62,6 @@
"undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" },
"vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" },
"vim-visual-multi": { "branch": "master", "commit": "a6975e7c1ee157615bbc80fc25e4392f71c344d4" },
"vscode-js-debug": { "branch": "main", "commit": "4d7c704d3f07c65ba99b29c2a6ddff6e318e5391" },
"which-key.nvim": { "branch": "main", "commit": "bfec3d6bc0a9b0b2cb11644642f78c2c3915eef0" },
"window-picker": { "branch": "main", "commit": "41cfaa428577c53552200a404ae9b3a0b5719706" }
}
34 changes: 34 additions & 0 deletions nvim/.config/nvim/lua/plugins/dap-ui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
return {
"rcarriga/nvim-dap-ui",
event = "LspAttach",
dependencies = {
"mfussenegger/nvim-dap",
"nvim-neotest/nvim-nio",
},
config = function()
require("dapui").setup({})
local dap, dapui = require("dap"), require("dapui")
dap.listeners.before.attach.dapui_config = function()
dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
dapui.close()
end
end,
keys = {
{ "<leader>ui", "<cmd>lua require'dapui'.toggle()<cr>", desc = "Toggle DAP UI" },
{
"<leader>uw",
function()
require("dapui").float_element("watches", { enter = true })
end,
desc = "Toggle DAP UI",
},
},
}
100 changes: 100 additions & 0 deletions nvim/.config/nvim/lua/plugins/dap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
js = function(dap)
dap.adapters["pwa-node"] = {
type = "server",
host = "localhost",
port = "${port}",
executable = {
command = "js-debug-adapter",
args = { "${port}" },
},
}
for _, language in ipairs({ "typescript", "javascript" }) do
require("dap").configurations[language] = {
{
name = "Custom Debug Platform Model",
type = "pwa-node",
request = "attach",
remoteRoot = "/usr/src/app",
localRoot = "${workspaceFolder}",
-- protocol = "inspector",
port = 9229,
restart = true,
address = "0.0.0.0",
skipFiles = { "<node_internals>/**" },
sourceMaps = true,
},
{
type = "pwa-node",
request = "attach",
name = "Attach to node",
processId = require("dap.utils").pick_process,
cwd = "${workspaceFolder}",
},
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = "${workspaceFolder}",
},
---@diagnostic disable-next-line: missing-fields
{
name = "-- launch.json --",
},
}
end
end

return {
"mfussenegger/nvim-dap",
event = "LspAttach",
dependencies = {
{
"theHamsta/nvim-dap-virtual-text",
opts = {},
},
},
config = function()
local dap = require("dap")
-- setup dap config by VsCode launch.json file
local vscode = require("dap.ext.vscode")
local json = require("plenary.json")
vscode.json_decode = function(str)
return vim.json.decode(json.json_strip_comments(str))
end

-- Extends dap.configurations with entries read from .vscode/launch.json
if vim.fn.filereadable(".vscode/launch.json") then
vscode.load_launchjs()
end
require("mason-nvim-dap").setup({})
js(dap)
end,
keys = {
{
"<leader>b",
"<cmd>lua require'dap'.toggle_breakpoint()<cr>",
desc = "Toggle breakpoint",
},
{
"<leader>bc",
conditional_breakpoint,
desc = "Conditional breakpoint",
},
{
"<leader>bs",
"<cmd>lua require'dap'.continue()<cr>",
desc = "Debug continue",
},
{
"<leader>bi",
"<cmd>lua require'dap'.step_into()<cr>",
desc = "Debug step into",
},
{
"<leader>bo",
"<cmd>lua require'dap'.step_over()<cr>",
desc = "Debug step over",
},
},
}

0 comments on commit ea8aa83

Please sign in to comment.