From f84fc5c81dc9dc53cb1135524ee6d11a2b2133b1 Mon Sep 17 00:00:00 2001 From: "Nikolas (Daniel) Vincenti" <165183152+NikVince@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:26:35 +0200 Subject: [PATCH] UPDATED init.lua to ADD plugin 'nvim-dap' for debugging. --- init.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/init.lua b/init.lua index 2318371c..db087f9f 100644 --- a/init.lua +++ b/init.lua @@ -1011,6 +1011,86 @@ require('lazy').setup({ -- Or use telescope! -- In normal mode type `sh` then write `lazy.nvim-plugin` -- you can continue same window with `sr` which resumes last telescope search + { + 'mfussenegger/nvim-dap', + dependencies = { + -- Creates a beautiful debugger UI + 'rcarriga/nvim-dap-ui', + + -- Installs the debug adapters for you + 'williamboman/mason.nvim', + 'jay-babu/mason-nvim-dap.nvim', + + -- Add your own adapters here + 'theHamsta/nvim-dap-virtual-text', + }, + config = function() + local dap = require 'dap' + local dapui = require 'dapui' + + -- Set up UI + dapui.setup() + + -- Automatically open UI when debugging starts + dap.listeners.after.event_initialized['dapui_config'] = function() + dapui.open() + end + dap.listeners.before.event_terminated['dapui_config'] = function() + dapui.close() + end + dap.listeners.before.event_exited['dapui_config'] = function() + dapui.close() + end + + -- Configure Rust adapter + dap.adapters.lldb = { + type = 'executable', + command = '/usr/bin/lldb-vscode', -- adjust path as needed + name = 'lldb', + } + + dap.configurations.rust = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/target/debug/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + -- if you need to run with terminal emulation: + runInTerminal = false, + }, + { + name = 'Attach to process', + type = 'lldb', + request = 'attach', + pid = require('dap.utils').pick_process, + args = {}, + }, + } + + -- Add keymaps + vim.keymap.set('n', 'db', dap.toggle_breakpoint, { desc = 'Debug: Toggle [B]reakpoint' }) + vim.keymap.set('n', 'dc', dap.continue, { desc = 'Debug: [C]ontinue' }) + vim.keymap.set('n', 'do', dap.step_over, { desc = 'Debug: Step [O]ver' }) + vim.keymap.set('n', 'di', dap.step_into, { desc = 'Debug: Step [I]nto' }) + vim.keymap.set('n', 'ds', dap.step_out, { desc = 'Debug: [S]tep Out' }) + vim.keymap.set('n', 'dr', dap.repl.open, { desc = 'Debug: Open [R]EPL' }) + vim.keymap.set('n', 'du', dapui.toggle, { desc = 'Debug: Toggle [U]I' }) + + -- Make sure required tools are installed + require('mason-nvim-dap').setup { + ensure_installed = { 'codelldb' }, + automatic_installation = true, + } + + -- Virtual text for debug info + require('nvim-dap-virtual-text').setup() + end, + }, }, { ui = { -- If you are using a Nerd Font: set icons to an empty table which will use the