145 lines
7.4 KiB
Lua
145 lines
7.4 KiB
Lua
return {
|
|
"jay-babu/mason-nvim-dap.nvim",
|
|
event = "VeryLazy",
|
|
dependencies = {
|
|
"williamboman/mason.nvim",
|
|
"mfussenegger/nvim-dap",
|
|
"nvim-neotest/nvim-nio",
|
|
"rcarriga/nvim-dap-ui",
|
|
"theHamsta/nvim-dap-virtual-text",
|
|
},
|
|
opts = {
|
|
handlers = {},
|
|
},
|
|
config = function()
|
|
local dap = require("dap")
|
|
local dapui = require("dapui")
|
|
dapui.setup()
|
|
-- dap.listeners.after.event_initialized["dapui_config"] = function()
|
|
-- dapui.open()
|
|
-- end
|
|
-- dap.listeners.after.event_terminated["dapui_config"] = function()
|
|
-- dapui.close()
|
|
-- end
|
|
-- dap.listeners.after.event_exited["dapui_config"] = function()
|
|
-- dapui.close()
|
|
-- end
|
|
|
|
function file_exists(name)
|
|
local f = io.open(name, "r")
|
|
return f ~= nil and io.close(f)
|
|
end
|
|
|
|
local dap = require("dap")
|
|
dap.adapters.codelldb = {
|
|
type = "executable",
|
|
command = "codelldb", -- or if not in $PATH: "/absolute/path/to/codelldb"
|
|
}
|
|
dap.configurations.cpp = {
|
|
{
|
|
name = "Launch file",
|
|
type = "codelldb",
|
|
request = "launch",
|
|
program = function()
|
|
if file_exists(vim.fn.getcwd() .. "/a.out") then
|
|
return vim.fn.getcwd() .. "/a.out"
|
|
end
|
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
|
|
end,
|
|
-- args = function()
|
|
-- if file_exists(vim.fn.getcwd() .. "/args") then
|
|
-- local f = io.open(vim.fn.getcwd() .. "/args")
|
|
-- local content = f:read("all")
|
|
-- f:close()
|
|
-- content = content:gsub("\n", " ")
|
|
-- return vim.split(content, " ")
|
|
-- end
|
|
-- local args_string = vim.fn.input("Arguments: ")
|
|
-- return vim.split(args_string, " ")
|
|
-- end,
|
|
cwd = "${workspaceFolder}",
|
|
stopOnEntry = false,
|
|
},
|
|
}
|
|
|
|
vim.keymap.set("n", "<leader>db", "<cmd> DapToggleBreakpoint <CR>")
|
|
vim.keymap.set("n", "<leader>dr", "<cmd> DapContinue <CR>")
|
|
vim.keymap.set("n", "<leader>du", "<cmd> DapStepOut <CR>")
|
|
vim.keymap.set("n", "<leader>di", "<cmd> DapStepInto <CR>")
|
|
vim.keymap.set("n", "<leader>dn", "<cmd> DapStepOver <CR>")
|
|
|
|
vim.keymap.set("n", "<F5>", "<cmd> DapContinue <CR>")
|
|
vim.keymap.set("n", "<F6>", "<cmd> DapToggleBreakpoint <CR>")
|
|
vim.keymap.set("n", "<F8>", "<cmd> DapStepInto <CR>")
|
|
vim.keymap.set("n", "<F9>", "<cmd> DapStepOver <CR>")
|
|
-- stylua: ignore start
|
|
vim.keymap.set("n", "C-<F5>", function() require("dap").run_last() end)
|
|
vim.keymap.set("n", "C-<F5>", function() require("dap").up() end)
|
|
vim.keymap.set("n", "<leader>dd", function() require("dap").down() end)
|
|
vim.keymap.set("n", "<leader>du", function() require("dap").up() end)
|
|
vim.keymap.set("n", "<F5>", function() require("dap").continue() end)
|
|
vim.keymap.set("n", "<leader>do", dapui.open)
|
|
vim.keymap.set("n", "<leader>dc", dapui.close)
|
|
-- { lhs = '<F29>', rhs = function() require('dap').run_last() end, opts = { desc = 'Run last' } },
|
|
|
|
-- stylua: ignore start
|
|
-- require('session-keys').sessions.dap = {
|
|
-- n = { -- mode 'n'
|
|
-- { lhs = '<F5>', rhs = function() require('dap').continue() end, opts = { desc = 'Run, continue' } },
|
|
-- { lhs = '<F17>', rhs = function() require('dap').run_to_cursor() end, opts = { desc = 'Run to cursor' } },
|
|
-- { lhs = '<F9>', rhs = function() require('dap').toggle_breakpoint() end, opts = { desc = 'Toggle breakpoint' } },
|
|
-- { lhs = '<F10>', rhs = function() require('dap').step_over() end, opts = { desc = 'Step over' } },
|
|
-- { lhs = '<F11>', rhs = function() require('dap').step_into() end, opts = { desc = 'Step into' } },
|
|
-- { lhs = '<F23>', rhs = function() require('dap').step_out() end, opts = { desc = 'Step out' } },
|
|
--
|
|
-- { lhs = '<F8>', rhs = function() require('dap').terminate() end, opts = { desc = 'Terminate' } },
|
|
-- { lhs = '<F20>', rhs = function() require('dap').disconnect({ terminateDebuggee = false }) end, opts = { desc = 'Disconnect' } },
|
|
-- { lhs = '<F29>', rhs = function() require('dap').run_last() end, opts = { desc = 'Run last' } },
|
|
--
|
|
-- { lhs = '<F6>', rhs = function() require('dap').down() end, opts = { desc = 'Go down in current stacktrace without stepping' } },
|
|
-- { lhs = '<F18>', rhs = function() require('dap').up() end, opts = { desc = 'Go up in current stacktrace without stepping' } },
|
|
--
|
|
-- { lhs = '<F7>', rhs = function() require('dap').pause() end, opts = { desc = 'Pause thread' } },
|
|
--
|
|
-- { lhs = '<F41>', rhs = function() require('dap').reverse_continue() end, opts = { desc = 'Reverse continue' } },
|
|
-- { lhs = '<F22>', rhs = function() require('dap').step_back() end, opts = { desc = 'Step back' } }
|
|
-- }
|
|
-- stylua: ignore stop
|
|
-- }
|
|
--
|
|
require("nvim-dap-virtual-text").setup {
|
|
enabled = true, -- enable this plugin (the default)
|
|
enabled_commands = true, -- create commands DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, (DapVirtualTextForceRefresh for refreshing when debug adapter did not notify its termination)
|
|
highlight_changed_variables = true, -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText
|
|
highlight_new_as_changed = false, -- highlight new variables in the same way as changed variables (if highlight_changed_variables)
|
|
show_stop_reason = true, -- show stop reason when stopped for exceptions
|
|
commented = false, -- prefix virtual text with comment string
|
|
only_first_definition = true, -- only show virtual text at first definition (if there are multiple)
|
|
all_references = false, -- show virtual text on all all references of the variable (not only definitions)
|
|
clear_on_continue = false, -- clear virtual text on "continue" (might cause flickering when stepping)
|
|
--- A callback that determines how a variable is displayed or whether it should be omitted
|
|
--- @param variable Variable https://microsoft.github.io/debug-adapter-protocol/specification#Types_Variable
|
|
--- @param buf number
|
|
--- @param stackframe dap.StackFrame https://microsoft.github.io/debug-adapter-protocol/specification#Types_StackFrame
|
|
--- @param node userdata tree-sitter node identified as variable definition of reference (see `:h tsnode`)
|
|
--- @param options nvim_dap_virtual_text_options Current options for nvim-dap-virtual-text
|
|
--- @return string|nil A text how the virtual text should be displayed or nil, if this variable shouldn't be displayed
|
|
display_callback = function(variable, buf, stackframe, node, options)
|
|
-- by default, strip out new line characters
|
|
if options.virt_text_pos == 'inline' then
|
|
return ' = ' .. variable.value:gsub("%s+", " ")
|
|
else
|
|
return variable.name .. ' = ' .. variable.value:gsub("%s+", " ")
|
|
end
|
|
end,
|
|
-- position of virtual text, see `:h nvim_buf_set_extmark()`, default tries to inline the virtual text. Use 'eol' to set to end of line
|
|
virt_text_pos = vim.fn.has 'nvim-0.10' == 1 and 'inline' or 'eol',
|
|
|
|
-- experimental features:
|
|
all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine.
|
|
virt_lines = false, -- show virtual lines instead of virtual text (will flicker!)
|
|
virt_text_win_col = nil -- position the virtual text at a fixed window column (starting from the first text column) ,
|
|
}
|
|
end,
|
|
}
|