From e54bc144099d6c16427113c1ddd92dc14a7b4622 Mon Sep 17 00:00:00 2001 From: Ward Truyen Date: Sat, 24 May 2025 12:20:45 +0200 Subject: [PATCH] Chore: Added DAP config --- lua/ward/.luarc.json | 5 ++ lua/ward/plugins/dap-ui.lua | 22 ++++++++ lua/ward/plugins/dap.lua | 100 ++++++++++++++++++++++++++++++++++ lua/ward/plugins/gitsigns.lua | 2 +- lua/ward/plugins/mason.lua | 1 + 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 lua/ward/.luarc.json create mode 100644 lua/ward/plugins/dap-ui.lua create mode 100644 lua/ward/plugins/dap.lua diff --git a/lua/ward/.luarc.json b/lua/ward/.luarc.json new file mode 100644 index 0000000..1e1765c --- /dev/null +++ b/lua/ward/.luarc.json @@ -0,0 +1,5 @@ +{ + "diagnostics.globals": [ + "vim" + ] +} \ No newline at end of file diff --git a/lua/ward/plugins/dap-ui.lua b/lua/ward/plugins/dap-ui.lua new file mode 100644 index 0000000..3ed800f --- /dev/null +++ b/lua/ward/plugins/dap-ui.lua @@ -0,0 +1,22 @@ +-- NOTE: Debug Adapter Protocol User interface, start and close automaticly config +return { + "rcarriga/nvim-dap-ui", + dependencies = { "mfussenegger/nvim-dap", "nvim-neotest/nvim-nio" }, + config = function() + local dap, dapui = require("dap"), require("dapui") + dapui.setup() + dap.listeners.before.attach.dapui_config = function() + dapui.open() + end + dap.listeners.before.launch.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 + vim.keymap.set('n', 'dd', function() require('dapui').toggle() end) + end, +} diff --git a/lua/ward/plugins/dap.lua b/lua/ward/plugins/dap.lua new file mode 100644 index 0000000..aebe6fa --- /dev/null +++ b/lua/ward/plugins/dap.lua @@ -0,0 +1,100 @@ +---@type NvPluginSpec +-- NOTE: Debug Adapter Protocol +-- URL: https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation +return { + "mfussenegger/nvim-dap", + config = function() + -- NOTE: Check out this for guide + vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "DiagnosticSignError", linehl = "", numhl = "" }) + + local wk = require("which-key") + wk.add({ + {"d", group = "DAP"}, + {"dd", desc = "Toggle DAP UI"}, + {"db", desc = "Toggle breakpoint"}, + {"dB", desc = "Set breakpoint"}, + {"dm", desc = "message point"}, + {"dr", desc = "Open repl"}, + {"dl", desc = "Run last"}, + {"dh", desc = "Hover widgets"}, + {"dp", desc = "Preview widgets"}, + {"df", desc = "Float frames"}, + {"ds", desc = "Float scopes"}, + {"d", desc = "Debug start/continue"}, + {"d", desc = "Debug step over"}, + {"d", desc = "Debug step into"}, + {"d", desc = "Debug step out"}, + }) + vim.keymap.set('n', '', function() require('dap').continue() end) + vim.keymap.set('n', '', function() require('dap').step_over() end) + vim.keymap.set('n', '', function() require('dap').step_into() end) + vim.keymap.set('n', '', function() require('dap').step_out() end) + vim.keymap.set('n', 'db', function() require('dap').toggle_breakpoint() end) + vim.keymap.set('n', 'dB', function() require('dap').set_breakpoint() end) + vim.keymap.set('n', 'dm', + function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) end) + vim.keymap.set('n', 'dr', function() require('dap').repl.open() end) + vim.keymap.set('n', 'dl', function() require('dap').run_last() end) + vim.keymap.set({ 'n', 'v' }, 'dh', function() + require('dap.ui.widgets').hover() + end) + vim.keymap.set({ 'n', 'v' }, 'dp', function() + require('dap.ui.widgets').preview() + end) + vim.keymap.set('n', 'df', function() + local widgets = require('dap.ui.widgets') + widgets.centered_float(widgets.frames) + end) + vim.keymap.set('n', 'ds', function() + local widgets = require('dap.ui.widgets') + widgets.centered_float(widgets.scopes) + end) + + + -- NOTE: Make sure to install the needed files/exectubles through mason + local dap = require("dap") + dap.adapters.gdb = { + type = "executable", + command = "gdb", + args = { "--interpreter=dap", "-eval-command", "set print pretty on" }, + } + + dap.configurations.cpp = { + { + name = "Launch", + type = "gdb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + 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.c = dap.configurations.cpp + end, +} diff --git a/lua/ward/plugins/gitsigns.lua b/lua/ward/plugins/gitsigns.lua index 0d6fcf4..d8a22d1 100644 --- a/lua/ward/plugins/gitsigns.lua +++ b/lua/ward/plugins/gitsigns.lua @@ -13,7 +13,7 @@ return { -- untracked = { text = "┆" }, }, numhl = true, -- Toggle with `:Gitsigns toggle_numhl` - linehl = true, -- Toggle with `:Gitsigns toggle_linehl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` } end, } diff --git a/lua/ward/plugins/mason.lua b/lua/ward/plugins/mason.lua index c63a676..ce8b95f 100644 --- a/lua/ward/plugins/mason.lua +++ b/lua/ward/plugins/mason.lua @@ -10,6 +10,7 @@ return { opts = { ensure_installed = { + --C / C++ "clangd", "clang-format", "codelldb",