From e5aedbcbc0d9d643999fe8e5a4e2e1789b369dea Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Tue, 23 Aug 2022 11:46:14 +0200 Subject: [PATCH] feat(neovim): setup rust debugging --- home-manager/neovim/dap.lua | 35 +++++++++++++++++++++++++++++++ home-manager/neovim/default.nix | 10 +++++++++ home-manager/neovim/lspconfig.lua | 8 +++++++ 3 files changed, 53 insertions(+) create mode 100644 home-manager/neovim/dap.lua diff --git a/home-manager/neovim/dap.lua b/home-manager/neovim/dap.lua new file mode 100644 index 0000000..d491267 --- /dev/null +++ b/home-manager/neovim/dap.lua @@ -0,0 +1,35 @@ +local dap = require("dap") +local dapui = require("dapui") + +dapui.setup() + +vim.fn.sign_define("DapBreakpoint", { text = "🔴", texthl = "", linehl = "", numhl = "" }) + +-- debugging keymaps +vim.keymap.set("n", "", dap.continue, { noremap = true, silent = true }) +vim.keymap.set("n", "", dap.toggle_breakpoint, { noremap = true, silent = true }) +vim.keymap.set("n", "", dap.step_over, { noremap = true, silent = true }) +vim.keymap.set("n", "", dap.step_into, { noremap = true, silent = true }) + +vim.keymap.set("n", "", dap.step_out, { noremap = true, silent = true }) +vim.keymap.set("n", "", dap.step_out, { noremap = true, silent = true }) -- in kitty + +vim.keymap.set("n", "", dapui.eval, { noremap = true, silent = true }) + +-- trigger auto-completion in repl +vim.cmd([[ + augroup TriggerDapReplAutoCompletion + autocmd! + autocmd FileType dap-repl lua require("dap.ext.autocompl").attach() + augroup END +]]) + +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 diff --git a/home-manager/neovim/default.nix b/home-manager/neovim/default.nix index 0365ce1..c11c688 100644 --- a/home-manager/neovim/default.nix +++ b/home-manager/neovim/default.nix @@ -53,8 +53,13 @@ in nodePackages.typescript nodePackages.dockerfile-language-server-nodejs nodePackages.vscode-html-languageserver-bin + lldb + vscode-extensions.vadimcn.vscode-lldb ]; + # symlink for a stable path + home.file.".vscode-extensions/vscode-lldb".source = pkgs.vscode-extensions.vadimcn.vscode-lldb; + programs = { neovim = { enable = true; @@ -115,6 +120,10 @@ in lua-dev-nvim null-ls-nvim lsp_lines-nvim + + # debugging + nvim-dap + nvim-dap-ui ]; extraConfig = '' @@ -146,6 +155,7 @@ in vim.opt.background = '${theme}' ${builtins.readFile ./project-nvim.lua } + ${builtins.readFile ./dap.lua } EOF ''; }; diff --git a/home-manager/neovim/lspconfig.lua b/home-manager/neovim/lspconfig.lua index 7e87c2d..30057e1 100644 --- a/home-manager/neovim/lspconfig.lua +++ b/home-manager/neovim/lspconfig.lua @@ -73,6 +73,11 @@ for lsp, settings in pairs(servers) do }) end +-- setup rust tools +local codelldb_base_path = vim.env.HOME .. "/.vscode-extensions/vscode-lldb/share/vscode/extensions/vadimcn.vscode-lldb/" +local codelldb_bin_path = codelldb_base_path .. 'adapter/codelldb' +local codelldb_lib_path = codelldb_base_path .. 'lldb/lib/liblldb.so' + require("rust-tools").setup({ server = { on_attach = on_attach, @@ -89,6 +94,9 @@ require("rust-tools").setup({ }, capabilities = capabilities, }, + dap = { + adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_bin_path, codelldb_lib_path) + }, }) local luadev = require("lua-dev").setup({