languages/zig: add dap support (#581)

* languages/zig: Added dap support

Implemented DAP support for zig. Included comment regarding redundant
`dap.adapters.lldb` code when both clang and zig dap modules are
enabled.

* languages/zig: Added dap support cleanup

Cleaned up code from the zig dap implementation for consistency.
This commit is contained in:
ARCIII 2025-01-25 08:17:48 -05:00 committed by GitHub
parent 8df64accab
commit 547cbd28b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 2 deletions

View file

@ -122,3 +122,8 @@
[ruff]: (https://github.com/astral-sh/ruff) [ruff]: (https://github.com/astral-sh/ruff)
- Add [ruff] as a formatter option in `vim.languages.python.format.type`. - Add [ruff] as a formatter option in `vim.languages.python.format.type`.
[ARCIII](https://github.com/ArmandoCIII):
- Add `vim.languages.zig.dap` support through pkgs.lldb dap adapter.
Code Inspiration from `vim.languages.clang.dap` implementation.

View file

@ -8,10 +8,12 @@
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.modules) mkIf mkMerge mkDefault; inherit (lib.modules) mkIf mkMerge mkDefault;
inherit (lib.lists) isList; inherit (lib.lists) isList;
inherit (lib.types) either listOf package str enum; inherit (lib.types) bool either listOf package str enum;
inherit (lib.nvim.lua) expToLua; inherit (lib.nvim.lua) expToLua;
inherit (lib.nvim.types) mkGrammarOption; inherit (lib.nvim.types) mkGrammarOption;
cfg = config.vim.languages.zig;
defaultServer = "zls"; defaultServer = "zls";
servers = { servers = {
zls = { zls = {
@ -31,7 +33,35 @@
}; };
}; };
cfg = config.vim.languages.zig; # TODO: dap.adapter.lldb is duplicated when enabling the
# vim.languages.clang.dap module. This does not cause
# breakage... but could be cleaner.
defaultDebugger = "lldb-vscode";
debuggers = {
lldb-vscode = {
package = pkgs.lldb;
dapConfig = ''
dap.adapters.lldb = {
type = 'executable',
command = '${cfg.dap.package}/bin/lldb-dap',
name = 'lldb'
}
dap.configurations.zig = {
{
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 = {},
},
}
'';
};
};
in { in {
options.vim.languages.zig = { options.vim.languages.zig = {
enable = mkEnableOption "Zig language support"; enable = mkEnableOption "Zig language support";
@ -56,6 +86,26 @@ in {
default = pkgs.zls; default = pkgs.zls;
}; };
}; };
dap = {
enable = mkOption {
type = bool;
default = config.vim.languages.enableDAP;
description = "Enable Zig Debug Adapter";
};
debugger = mkOption {
type = enum (attrNames debuggers);
default = defaultDebugger;
description = "Zig debugger to use";
};
package = mkOption {
type = package;
default = debuggers.${cfg.dap.debugger}.package;
description = "Zig debugger package.";
};
};
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
@ -77,5 +127,12 @@ in {
globals.zig_fmt_autosave = mkDefault 0; globals.zig_fmt_autosave = mkDefault 0;
}; };
}) })
(mkIf cfg.dap.enable {
vim = {
debugger.nvim-dap.enable = true;
debugger.nvim-dap.sources.zig-debugger = debuggers.${cfg.dap.debugger}.dapConfig;
};
})
]); ]);
} }