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.repl'.close()<CR>"
.. ":lua require'dapui'.close()<CR>"
.. ":lua require('dap').clear_breakpoints()<CR>"
.. "<C-w>o<CR>",
"Stop debug",
},

View File

@ -7,83 +7,86 @@ local dap = require("dap")
local dapui = require("dapui")
require("nvim-dap-virtual-text").setup({
commented = true,
commented = true,
})
vim.fn.sign_define("DapBreakpoint", {
text = "🛑",
texthl = "LspDiagnosticsSignError",
linehl = "",
numhl = "",
text = "🛑",
texthl = "LspDiagnosticsSignError",
linehl = "",
numhl = "",
})
vim.fn.sign_define("DapStopped", {
text = "",
texthl = "LspDiagnosticsSignInformation",
linehl = "DiagnosticUnderlineInfo",
numhl = "LspDiagnosticsSignInformation",
text = "",
texthl = "LspDiagnosticsSignInformation",
linehl = "DiagnosticUnderlineInfo",
numhl = "LspDiagnosticsSignInformation",
})
vim.fn.sign_define("DapBreakpointRejected", {
text = "",
texthl = "LspDiagnosticsSignHint",
linehl = "",
numhl = "",
text = "",
texthl = "LspDiagnosticsSignHint",
linehl = "",
numhl = "",
})
dapui.setup({
icons = { expanded = "", collapsed = "" },
mappings = {
-- Use a table to apply multiple mappings
expand = { "o", "<CR>", "<2-LeftMouse>" },
open = "o",
remove = "d",
edit = "e",
repl = "r",
toggle = "t",
},
layouts = {{
-- You can change the order of elements in the sidebar
elements = {
-- Provide as ID strings or tables with "id" and "size" keys
{
id = "scopes",
size = 0.25, -- Can be float or integer > 1
},
{ id = "breakpoints", size = 0.25 },
{ id = "stacks", size = 0.25 },
{ id = "watches", size = 00.25 },
},
size = 40,
position = "left", -- Can be "left", "right", "top", "bottom"
},
{
elements = { "repl" },
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.
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.
},
icons = { expanded = "", collapsed = "" },
mappings = {
-- Use a table to apply multiple mappings
expand = { "o", "<CR>", "<2-LeftMouse>" },
open = "o",
remove = "d",
edit = "e",
repl = "r",
toggle = "t",
},
layouts = {
{
-- You can change the order of elements in the sidebar
elements = {
-- Provide as ID strings or tables with "id" and "size" keys
{
id = "scopes",
size = 0.25, -- Can be float or integer > 1
},
{ id = "breakpoints", size = 0.25 },
{ id = "stacks", size = 0.25 },
{ id = "watches", size = 00.25 },
},
size = 40,
position = "left", -- Can be "left", "right", "top", "bottom"
},
{
elements = { "repl" },
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.
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.
},
}) -- use default
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
dapui.close()
end
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",
cpp = "cd $dir && g++ $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt",
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 ui和适配器
use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap", "theHamsta/nvim-dap-virtual-text" } })
-- persistent breakpoints
-- 持久化断点
use({ "Weissle/persistent-breakpoints.nvim" })
end)