From 3a8b614ea9b2d5bcbf6fd03111eb9aa228ac546b Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 20 May 2023 13:46:19 +0200 Subject: [PATCH] feat: add dap support for clang --- modules/languages/clang.nix | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index 32e02f9..7d201e4 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -36,6 +36,35 @@ with builtins; let ''; }; }; + + defaultDebugger = "lldb-vscode"; + debuggers = { + lldb-vscode = { + package = pkgs.lldb; + dapConfig = '' + dap.adapters.lldb = { + type = 'executable', + command = '${cfg.dap.package}/bin/lldb-vscode', + name = 'lldb' + } + dap.configurations.cpp = { + { + name = 'Launch', + type = 'lldb', + request = 'launch', + program = function() + return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + end, + cwd = "''${workspaceFolder}", + stopOnEntry = false, + args = {}, + }, + } + + dap.configurations.c = dap.configurations.cpp + ''; + }; + }; in { options.vim.languages.clang = { enable = mkEnableOption "C/C++ language support"; @@ -76,6 +105,24 @@ in { default = null; }; }; + + dap = { + enable = mkOption { + description = "Enable clang Debug Adapter"; + type = types.bool; + default = config.vim.languages.enableDAP; + }; + debugger = mkOption { + description = "clang debugger to use"; + type = with types; enum (attrNames debuggers); + default = defaultDebugger; + }; + package = mkOption { + description = "clang debugger package."; + type = types.package; + default = debuggers.${cfg.dap.debugger}.package; + }; + }; }; config = mkIf cfg.enable (mkMerge [ @@ -93,5 +140,10 @@ in { vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig; }) + + (mkIf cfg.dap.enable { + vim.debugger.nvim-dap.enable = true; + vim.debugger.nvim-dap.sources.clang-debugger = debuggers.${cfg.dap.debugger}.dapConfig; + }) ]); }