add debugger support

This commit is contained in:
Never Gude 2026-01-20 00:45:49 +01:00
parent 248b29db47
commit 686a3ece75
3 changed files with 88 additions and 6 deletions

View file

@ -58,9 +58,6 @@ vim.keymap.set({ "n" }, "<A-j>", "<C-w>j")
vim.keymap.set({ "n" }, "<A-k>", "<C-w>k")
vim.keymap.set({ "n" }, "<A-l>", "<C-w>l")
vim.keymap.set('n', '<leader>ld', vim.lsp.buf.definition, { desc = 'vim.lsp.buf.definition()' })
vim.keymap.set('n', '<leader>lf', vim.lsp.buf.format, { desc = 'vim.lsp.buf.format()' })
-- [[ Basic Autocommands ]].
-- See `:h lua-guide-autocommands`, `:h autocmd`, `:h nvim_create_autocmd()`
-- Highlight when yanking (copying) text.
@ -129,6 +126,8 @@ end, { desc = "Print the git blame for the current line" })
-- 'updatetime' and when going to insert mode
vim.cmd("packadd! nohlsearch")
-- [[ Language Setup ]]
-- Treat Ipe stylesheets as xml code
vim.filetype.add({
extension = {
@ -138,14 +137,22 @@ vim.filetype.add({
-- Install nvim-treesitter
vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter" })
require("nvim-treesitter").install('latex', 'lua', 'c', 'ocaml')
require("nvim-treesitter").install('lua', 'latex', 'c', 'java', 'ocaml')
-- See `:h lsp-quickstart` for more details.
vim.pack.add({ "https://github.com/mason-org/mason.nvim" })
require("mason").setup()
vim.lsp.enable({ 'lua_ls', 'texlab', 'clangd', 'ocaml-lsp' })
vim.lsp.enable({'lua_ls', 'texlab', 'clangd', 'ocaml-lsp'})
vim.keymap.set('n', '<leader>lf', vim.lsp.buf.format,
{ desc = 'Formats a buffer using the attached language server clients.' })
vim.keymap.set('n', '<leader>lh', vim.lsp.buf.hover,
{ desc = 'Displays hover information about the symbol under the cursor.' })
vim.keymap.set('n', '<leader>lr', vim.lsp.buf.rename,
{ desc = 'Renames all references to the symbol under the cursor.' })
vim.keymap.set('n', '<leader>ld', vim.lsp.buf.definition,
{ desc = 'Jumps to the definition of the symbol under the cursor.' })
vim.diagnostic.config({
signs = {
@ -165,6 +172,74 @@ vim.keymap.set("n", "<leader>dN", "]D", { desc = "Jump to last diagnostic" })
vim.keymap.set("n", "<leader>dP", "[D", { desc = "Jump to first diagnostic" })
vim.keymap.set("n", "<leader>ds", "<C-w>d", { desc = "Display diagnostic on current line" })
vim.pack.add({ "https://github.com/mfussenegger/nvim-dap" })
local dap = require("dap")
local dap_widgets = require("dap.ui.widgets")
local dap_sidebar_s = dap_widgets.sidebar(dap_widgets.scopes)
local dap_sidebar_f = dap_widgets.sidebar(dap_widgets.frames)
vim.keymap.set("n", "<leader>bb", dap.toggle_breakpoint, { desc = "Toggle breakpoint"})
vim.keymap.set("n", "<leader>bc", dap.continue, { desc = "Continue execution"})
dap.listeners.on_session["debug"] = function()
vim.keymap.set("n", "<leader>bs", dap_sidebar_s.toggle, { desc = "Show scopes"})
vim.keymap.set("n", "<leader>bf", dap_sidebar_f.toggle, { desc = "Show frames"})
vim.keymap.set("n", "<Left>", dap.step_out, { desc = "Step out"})
vim.keymap.set("n", "<Right>", dap.step_into, { desc = "Step into"})
vim.keymap.set("n", "<Down>", dap.step_over, { desc = "Step over"})
vim.keymap.set("n", "<Up>", dap.restart_frame, { desc = "Restart frame"})
end
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
}
dap.configurations.c = {
{
name = "Launch",
type = "gdb",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
args = {}, -- provide arguments if needed
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
{
name = "Select and attach to process",
type = "gdb",
request = "attach",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
pid = function()
local name = vim.fn.input('Executable name (filter): ')
return require("dap.utils").pick_process({ filter = name })
end,
cwd = '${workspaceFolder}'
},
{
name = 'Attach to gdbserver :1234',
type = 'gdb',
request = 'attach',
target = 'localhost:1234',
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}'
}
}
dap.configurations.cpp = dap.configurations.c
dap.configurations.rust = dap.configurations.c
-- [[ UI Configuration ]]
vim.pack.add({
"https://github.com/nvim-mini/mini.completion",
@ -176,7 +251,6 @@ vim.pack.add({
"https://github.com/nvim-mini/mini.clue",
"https://github.com/nvim-mini/mini.hipatterns",
"https://github.com/nvim-mini/mini.notify",
}, { confirm = false })
vim.o.winborder = "none"

View file

@ -56,6 +56,14 @@
"rev": "caf23615b9b99bacc79ecd60f61c4e6a8ec18c84",
"src": "https://github.com/nvim-mini/mini.tabline"
},
"nvim-dap": {
"rev": "cdfd55a133f63228c55f91378f12908cb2a78ded",
"src": "https://github.com/mfussenegger/nvim-dap"
},
"nvim-dap-virtual-text": {
"rev": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6",
"src": "https://github.com/theHamsta/nvim-dap-virtual-text"
},
"nvim-lspconfig": {
"rev": "92ee7d42320edfbb81f3cad851314ab197fa324a",
"src": "https://github.com/neovim/nvim-lspconfig"