From 0a25676f731103851eab742b9ffe1068c58cedd9 Mon Sep 17 00:00:00 2001 From: gameloader Date: Tue, 18 Oct 2022 23:23:23 +0800 Subject: [PATCH] add persistent breakpoint for dap --- lua/keybindings.lua | 1 - lua/nvim-dap/init.lua | 119 ++++++++++++++++--------------- lua/nvim-dap/per_breakpoint.lua | 3 + lua/plugin-config/coderunner.lua | 1 + lua/plugins.lua | 4 ++ 5 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 lua/nvim-dap/per_breakpoint.lua diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 846a15a..22fb10b 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -166,7 +166,6 @@ wk.register({ .. ":lua require'dap'.terminate()" .. ":lua require'dap.repl'.close()" .. ":lua require'dapui'.close()" - .. ":lua require('dap').clear_breakpoints()" .. "o", "Stop debug", }, diff --git a/lua/nvim-dap/init.lua b/lua/nvim-dap/init.lua index b7bc3d7..3318a2e 100644 --- a/lua/nvim-dap/init.lua +++ b/lua/nvim-dap/init.lua @@ -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", "", "<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", "" }, - }, - }, - 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", "", "<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", "" }, + }, + }, + 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") diff --git a/lua/nvim-dap/per_breakpoint.lua b/lua/nvim-dap/per_breakpoint.lua new file mode 100644 index 0000000..a9d43b4 --- /dev/null +++ b/lua/nvim-dap/per_breakpoint.lua @@ -0,0 +1,3 @@ +require("persistent-breakpoints").setup({ + load_breakpoints_event = { "BufReadPost" }, +}) diff --git a/lua/plugin-config/coderunner.lua b/lua/plugin-config/coderunner.lua index fae7f30..44ff1ba 100644 --- a/lua/plugin-config/coderunner.lua +++ b/lua/plugin-config/coderunner.lua @@ -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", }, }) diff --git a/lua/plugins.lua b/lua/plugins.lua index 368386a..c18da7f 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -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)