Skip to content

Commit

Permalink
Debugger: add support for nvim-dap & codelldb
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanisaacs committed Jul 29, 2023
1 parent 7888bab commit dfd6c3a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 7 deletions.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
plugin-cmp-treesitter.url = "github:ray-x/cmp-treesitter";
plugin-cmp-treesitter.flake = false;

plugin-cmp-dap.url = "github:rcarriga/cmp-dap";
plugin-cmp-dap.flake = false;

# snippets
plugin-vim-vsnip.url = "github:hrsh7th/vim-vsnip";
plugin-vim-vsnip.flake = false;
Expand Down Expand Up @@ -219,6 +222,7 @@
enableFormat = overrideable true;
enableTreesitter = overrideable true;
enableExtraDiagnostics = overrideable true;
enableDebugger = overrideable true;

nix.enable = overrideable true;
markdown.enable = overrideable true;
Expand Down
30 changes: 23 additions & 7 deletions modules/completion/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ with lib;
with builtins; let
cfg = config.vim.autocomplete;
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
debuggerEnabled = config.vim.debugger.enable;

builtSources =
concatMapStringsSep
"\n"
Expand Down Expand Up @@ -86,12 +88,14 @@ in {
};

config = mkIf cfg.enable {
vim.startPlugins = [
"nvim-cmp"
"cmp-buffer"
"cmp-vsnip"
"cmp-path"
];
vim.startPlugins =
[
"nvim-cmp"
"cmp-buffer"
"cmp-vsnip"
"cmp-path"
]
++ optional debuggerEnabled "cmp-dap";

vim.autocomplete.sources = {
"nvim-cmp" = null;
Expand Down Expand Up @@ -175,12 +179,24 @@ in {
then "lspkind.cmp_format(lspkind_opts)"
else cfg.formatting.format
},
}
},
${optionalString debuggerEnabled ''
enabled = function()
return vim.api.nvim_buf_get_option(0, "buftype") ~= "prompt"
or require("cmp_dap").is_dap_buffer()
end,
''}
})
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} }))
''}
${optionalString debuggerEnabled ''
cmp.setup.filetype({ "dap-repl", "dapui_watches", "dapui_hover" }, {
sources = { name = "dap" };
})
''}
'');

vim.snippets.vsnip.enable =
Expand Down
58 changes: 58 additions & 0 deletions modules/debugger/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
config,
lib,
pkgs,
...
}:
with lib;
with builtins; let
cfg = config.vim.debugger;
in {
options.vim.debugger = {
enable = mkEnableOption "LSP, also enabled automatically through null-ls and lspconfig options";

port = mkOption {
description = "Port to start the debugger on";
type = types.int;
default = 13000;
};

enrichConfig = mkOption {
description = "Lua script that enriches the config";
type = types.lines;
default = "";
example = nvim.nmd.literalAsciiDoc ''
[source,lua]
---
if config["cargo"] ~= nil then on_config(cargo_inspector(config)) end
---
'';
};
};

config = mkIf cfg.enable {
vim.startPlugins = ["nvim-dap"];

vim.autocomplete.sources = {"nvim_lsp" = "[LSP]";};

vim.luaConfigRC.dap-setup = ''
local dap = require('dap')
local codelldb_bin = "${pkgs.code-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb"
local codelldb_lib = "${pkgs.code-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/lldb/lib/liblldb.dylib"
local port = "${port}",
dap.adapters.codelldb = {
type = 'server',
port = "${port}",
executable = {
command = codelldb_bin,
args = {"--liblldb", codelldb_lib, "--port", "${port}"},
enrich_config = function(config, on_config)
${enrichConfig}
end,
}
}
'';
};
}
1 change: 1 addition & 0 deletions modules/languages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ in {
enableTreesitter = mkEnable "treesitter";
enableFormat = mkEnable "formatting";
enableExtraDiagnostics = mkEnable "extra diagnostics";
enableDebugger = mkEnable "debuggers";
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
./telescope
./git
./build
./debugger
];

pkgsModule = {config, ...}: {
Expand Down

0 comments on commit dfd6c3a

Please sign in to comment.