add persistent breakpoint for dap

This commit is contained in:
gameloader 2022-10-18 23:23:23 +08:00
parent c7757805df
commit 0a25676f73
5 changed files with 69 additions and 59 deletions

View File

@ -166,7 +166,6 @@ wk.register({
.. ":lua require'dap'.terminate()<CR>" .. ":lua require'dap'.terminate()<CR>"
.. ":lua require'dap.repl'.close()<CR>" .. ":lua require'dap.repl'.close()<CR>"
.. ":lua require'dapui'.close()<CR>" .. ":lua require'dapui'.close()<CR>"
.. ":lua require('dap').clear_breakpoints()<CR>"
.. "<C-w>o<CR>", .. "<C-w>o<CR>",
"Stop debug", "Stop debug",
}, },

View File

@ -7,83 +7,86 @@ local dap = require("dap")
local dapui = require("dapui") local dapui = require("dapui")
require("nvim-dap-virtual-text").setup({ require("nvim-dap-virtual-text").setup({
commented = true, commented = true,
}) })
vim.fn.sign_define("DapBreakpoint", { vim.fn.sign_define("DapBreakpoint", {
text = "🛑", text = "🛑",
texthl = "LspDiagnosticsSignError", texthl = "LspDiagnosticsSignError",
linehl = "", linehl = "",
numhl = "", numhl = "",
}) })
vim.fn.sign_define("DapStopped", { vim.fn.sign_define("DapStopped", {
text = "", text = "",
texthl = "LspDiagnosticsSignInformation", texthl = "LspDiagnosticsSignInformation",
linehl = "DiagnosticUnderlineInfo", linehl = "DiagnosticUnderlineInfo",
numhl = "LspDiagnosticsSignInformation", numhl = "LspDiagnosticsSignInformation",
}) })
vim.fn.sign_define("DapBreakpointRejected", { vim.fn.sign_define("DapBreakpointRejected", {
text = "", text = "",
texthl = "LspDiagnosticsSignHint", texthl = "LspDiagnosticsSignHint",
linehl = "", linehl = "",
numhl = "", numhl = "",
}) })
dapui.setup({ dapui.setup({
icons = { expanded = "", collapsed = "" }, icons = { expanded = "", collapsed = "" },
mappings = { mappings = {
-- Use a table to apply multiple mappings -- Use a table to apply multiple mappings
expand = { "o", "<CR>", "<2-LeftMouse>" }, expand = { "o", "<CR>", "<2-LeftMouse>" },
open = "o", open = "o",
remove = "d", remove = "d",
edit = "e", edit = "e",
repl = "r", repl = "r",
toggle = "t", toggle = "t",
}, },
layouts = {{ layouts = {
-- You can change the order of elements in the sidebar {
elements = { -- You can change the order of elements in the sidebar
-- Provide as ID strings or tables with "id" and "size" keys elements = {
{ -- Provide as ID strings or tables with "id" and "size" keys
id = "scopes", {
size = 0.25, -- Can be float or integer > 1 id = "scopes",
}, size = 0.25, -- Can be float or integer > 1
{ id = "breakpoints", size = 0.25 }, },
{ id = "stacks", size = 0.25 }, { id = "breakpoints", size = 0.25 },
{ id = "watches", size = 00.25 }, { id = "stacks", size = 0.25 },
}, { id = "watches", size = 00.25 },
size = 40, },
position = "left", -- Can be "left", "right", "top", "bottom" size = 40,
}, position = "left", -- Can be "left", "right", "top", "bottom"
{ },
elements = { "repl" }, {
size = 10, elements = { "repl" },
position = "bottom", -- Can be "left", "right", "top", "bottom" size = 10,
},}, position = "bottom", -- Can be "left", "right", "top", "bottom"
floating = { },
max_height = nil, -- These can be integers or a float between 0 and 1. },
max_width = nil, -- Floats will be treated as percentage of your screen. floating = {
border = "single", -- Border style. Can be "single", "double" or "rounded" max_height = nil, -- These can be integers or a float between 0 and 1.
mappings = { max_width = nil, -- Floats will be treated as percentage of your screen.
close = { "q", "<Esc>" }, border = "single", -- Border style. Can be "single", "double" or "rounded"
}, mappings = {
}, close = { "q", "<Esc>" },
windows = { indent = 1 }, },
render = { },
max_type_length = nil, -- Can be integer or nil. windows = { indent = 1 },
}, render = {
max_type_length = nil, -- Can be integer or nil.
},
}) -- use default }) -- use default
dap.listeners.after.event_initialized["dapui_config"] = function() dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open() dapui.open()
end end
dap.listeners.before.event_terminated["dapui_config"] = function() dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close() dapui.close()
end end
dap.listeners.before.event_exited["dapui_config"] = function() dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close() dapui.close()
end end
require("nvim-dap.cpptools") require("nvim-dap.cpptools")
require("nvim-dap.per_breakpoint")

View File

@ -0,0 +1,3 @@
require("persistent-breakpoints").setup({
load_breakpoints_event = { "BufReadPost" },
})

View File

@ -4,5 +4,6 @@ require("code_runner").setup({
c = "cd $dir && gcc $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt", c = "cd $dir && gcc $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt",
cpp = "cd $dir && g++ $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt", cpp = "cd $dir && g++ $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt",
go = "cd $dir && go run $fileName", go = "cd $dir && go run $fileName",
python = "cd $dir && python3 $fileName",
}, },
}) })

View File

@ -199,4 +199,8 @@ return require("packer").startup(function()
-- dap for neovim -- dap for neovim
-- dap ui和适配器 -- dap ui和适配器
use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap", "theHamsta/nvim-dap-virtual-text" } }) use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap", "theHamsta/nvim-dap-virtual-text" } })
-- persistent breakpoints
-- 持久化断点
use({ "Weissle/persistent-breakpoints.nvim" })
end) end)