]> git.sthu.org Git - vimconf.git/commitdiff
plugins: Add nvim-dap and nvim-dap-ui
authorStefan Huber <shuber@sthu.org>
Fri, 18 Apr 2025 20:33:20 +0000 (22:33 +0200)
committerStefan Huber <shuber@sthu.org>
Fri, 18 Apr 2025 20:33:20 +0000 (22:33 +0200)
plugins-full.vim.example

index 1a36bd6bf600acd3a34372f26f65770ed47f5d41..3041ccc9d7208b785873a2062b34deeb113fff6c 100644 (file)
@@ -36,6 +36,11 @@ Plug 'gko/vim-coloresque'
 
 " replace by https://github.com/mfussenegger/nvim-dap
 " Plug 'puremourning/vimspector'
+if has('nvim-0.10')
+    Plug 'mfussenegger/nvim-dap'
+    Plug 'nvim-neotest/nvim-nio'
+    Plug 'rcarriga/nvim-dap-ui'
+endif
 
 Plug 'Konfekt/vim-DetectSpellLang', {'do': 'spell'}
 
@@ -359,6 +364,79 @@ EOF
         au BufWritePost * lua require('lint').try_lint()
     endif
 
+
+    if has('nvim-0.10')
+        lua <<EOF
+            -- See details here:
+            -- https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#ccrust-via-gdb
+            local dap = require("dap")
+            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,
+                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}'
+              },
+            }
+
+            -- See details here:
+            -- https://github.com/rcarriga/nvim-dap-ui?tab=readme-ov-file#usage
+            require("dapui").setup()
+            local dap, dapui = require("dap"), require("dapui")
+            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
+
+            -- https://www.johntobin.ie/blog/debugging_in_neovim_with_nvim-dap/
+            vim.keymap.set('n', '<leader>db', dap.toggle_breakpoint, {desc="toggle breakpoint"});
+            vim.keymap.set('n', '<leader>dc', dap.continue, {desc="continue debugging"});
+            vim.keymap.set('n', '<leader>dC', dap.run_to_cursor, {desc="run to cursor"});
+            vim.keymap.set('n', '<leader>dT', dap.terminate, {desc="terminate debugging"});
+            vim.keymap.set('n', '<leader>de', dapui.eval, {desc="evaluate"});
+EOF
+    endif
+
     let g:fastfold_minlines = 0
 
     let g:detectspelllang_langs = {}