From 3784061378fdbeb9ab6c9ca6004d16fbaa3afdbb Mon Sep 17 00:00:00 2001 From: kossLAN Date: Sun, 17 Nov 2024 03:59:26 -0500 Subject: [PATCH] dap: add dapui & add lldb-dap support --- flake.lock | 12 +++--- nix/neovim-overlay.nix | 5 +-- nvim/init.lua | 1 - nvim/plugin/dap.lua | 85 +++++++++++++++++++++++++++++------------- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/flake.lock b/flake.lock index 9aa325e..9a648ae 100644 --- a/flake.lock +++ b/flake.lock @@ -39,11 +39,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -181,11 +181,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1730531603, - "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", "type": "github" }, "original": { diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 1f37e04..a67d3f2 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -87,6 +87,7 @@ with final.pkgs.lib; let mini-nvim # https://github.com/echasnovski/mini.nvim/ # Debugging nvim-dap + nvim-dap-ui # Notifications nvim-notify fidget-nvim @@ -113,10 +114,6 @@ with final.pkgs.lib; let rustfmt # rust formatter prettierd # typescript/javascript formatter # google-java-format # java formatter based off google guidelines - - # misc - nodejs # eww - gcc ]; in { # This is the neovim derivation diff --git a/nvim/init.lua b/nvim/init.lua index 0a1a79d..4c6ee93 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -52,7 +52,6 @@ vim.schedule(function() end) -- Configure Neovim diagnostic messages - local function prefix_diagnostic(prefix, diagnostic) return string.format(prefix .. ' %s', diagnostic.message) end diff --git a/nvim/plugin/dap.lua b/nvim/plugin/dap.lua index ad838ce..94e6165 100644 --- a/nvim/plugin/dap.lua +++ b/nvim/plugin/dap.lua @@ -1,30 +1,65 @@ +-- For some reason this nvim-dap doesn't wan't to find lldb-dap executable... +local function get_binary_path(binary) + local handle = io.popen('whereis -b ' .. binary .. ' | cut -d" " -f2') + if handle then + local result = handle:read('*a') + handle:close() + return result:gsub('\n', '') -- Remove trailing newline + end + return nil +end + local dap = require('dap') -dap.adapters.gdb = { - type = 'executable', - command = 'gdb', - args = { '-i', 'dap' }, -} - -dap.configurations.c = { - { - name = 'Launch', - type = 'gdb', - request = 'launch', - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - end, - stopAtBeginningOfMainSubprogram = false, +dap.adapters = { + lldb = { + type = 'executable', + command = get_binary_path('lldb-dap'), + name = 'lldb', + }, + gdb = { + type = 'executable', + command = 'gdb', + args = { '-i', 'dap' }, }, } -dap.configurations.cpp = { - { - name = 'Launch', - type = 'gdb', - request = 'launch', - program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') - end, - stopAtBeginningOfMainSubprogram = false, - }, +local lldb = { + name = 'lldb', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', + stopOnEntry = false, + args = {}, + runInTerminal = true, } + +local gdb = { + name = 'gdb', + type = 'gdb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = '${workspaceFolder}', +} + +dap.configurations.c = { lldb, gdb } +dap.configurations.cpp = { lldb, gdb } +dap.configurations.rust = lldb + +-- DAP UI +local dapui = require('dapui') +dapui.setup() + +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