diff --git a/modules/languages/rust.nix b/modules/languages/rust.nix index 1298c9fd..21ab58d6 100644 --- a/modules/languages/rust.nix +++ b/modules/languages/rust.nix @@ -40,6 +40,19 @@ in { default = ""; }; }; + + dap = { + enable = mkOption { + description = "Rust Debug Adapter support"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + package = mkOption { + description = "lldb pacakge"; + type = types.package; + default = pkgs.lldb; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -62,8 +75,8 @@ in { vim.treesitter.enable = true; vim.treesitter.grammars = [cfg.treesitter.package]; }) - (mkIf cfg.lsp.enable { - vim.startPlugins = ["rust-tools"]; + (mkIf (cfg.lsp.enable || cfg.dap.enable) { + vim.startPlugins = ["rust-tools"] ++ optionals cfg.dap.enable [cfg.dap.package]; vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.sources.rust-lsp = '' @@ -78,6 +91,21 @@ in { vim.keymap.set("n", "rm", rt.expand_macro.expand_macro, opts) vim.keymap.set("n", "rc", rt.open_cargo_toml.open_cargo_toml, opts) vim.keymap.set("n", "rg", function() rt.crate_graph.view_crate_graph("x11", nil) end, opts) + ${optionalString cfg.dap.enable '' + vim.keymap.set("n", "rd", ":RustDebuggables", opts) + vim.keymap.set( + "n", "${config.vim.debugger.nvim-dap.mappings.continue}", + function() + local dap = require("dap") + if dap.status() == "" then + vim.cmd "RustDebuggables" + else + dap.continue() + end + end, + opts + ) + ''} end local rustopts = { tools = { @@ -94,7 +122,17 @@ in { settings = { ${cfg.lsp.opts} } - } + }, + + ${optionalString cfg.dap.enable '' + dap = { + adapter = { + type = "executable", + command = "${cfg.dap.package}/bin/lldb-vscode", + name = "rt_lldb", + }, + }, + ''} } rt.setup(rustopts) '';