2023-04-17 20:27:27 +00:00
|
|
|
{
|
|
|
|
config,
|
2024-03-09 05:49:22 +00:00
|
|
|
pkgs,
|
2023-04-17 20:27:27 +00:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-08 02:16:46 +00:00
|
|
|
}: let
|
2024-11-10 01:05:48 +00:00
|
|
|
inherit (builtins) attrNames;
|
2024-03-09 05:49:22 +00:00
|
|
|
inherit (lib.options) mkEnableOption mkOption;
|
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.lists) isList;
|
2024-11-10 01:05:48 +00:00
|
|
|
inherit (lib.types) either listOf package str enum;
|
2024-03-09 05:49:22 +00:00
|
|
|
inherit (lib.nvim.lua) expToLua;
|
|
|
|
inherit (lib.nvim.types) mkGrammarOption;
|
2023-11-08 02:16:46 +00:00
|
|
|
|
2024-11-10 01:05:48 +00:00
|
|
|
defaultServer = "zls";
|
|
|
|
servers = {
|
|
|
|
zls = {
|
|
|
|
package = pkgs.zls;
|
|
|
|
internalFormatter = true;
|
|
|
|
lspConfig = ''
|
|
|
|
lspconfig.zls.setup {
|
|
|
|
capabilities = capabilities,
|
|
|
|
on_attach = default_on_attach,
|
|
|
|
cmd = ${
|
|
|
|
if isList cfg.lsp.package
|
|
|
|
then expToLua cfg.lsp.package
|
|
|
|
else "{'${cfg.lsp.package}/bin/zls'}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
cfg = config.vim.languages.zig;
|
|
|
|
in {
|
|
|
|
options.vim.languages.zig = {
|
2023-07-30 15:36:10 +00:00
|
|
|
enable = mkEnableOption "Zig language support";
|
2023-04-17 20:27:27 +00:00
|
|
|
|
|
|
|
treesitter = {
|
2023-10-21 17:15:36 +00:00
|
|
|
enable = mkEnableOption "Zig treesitter" // {default = config.vim.languages.enableTreesitter;};
|
2024-03-09 05:49:22 +00:00
|
|
|
package = mkGrammarOption pkgs "zig";
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
lsp = {
|
2024-11-10 01:05:48 +00:00
|
|
|
enable = mkEnableOption "Zig LSP support" // {default = config.vim.languages.enableLSP;};
|
|
|
|
|
|
|
|
server = mkOption {
|
|
|
|
type = enum (attrNames servers);
|
|
|
|
default = defaultServer;
|
|
|
|
description = "Zig LSP server to use";
|
|
|
|
};
|
2023-06-05 20:10:25 +00:00
|
|
|
|
2023-04-17 20:27:27 +00:00
|
|
|
package = mkOption {
|
2023-09-22 22:28:39 +00:00
|
|
|
description = "ZLS package, or the command to run as a list of strings";
|
2024-03-09 05:49:22 +00:00
|
|
|
type = either package (listOf str);
|
2023-05-01 15:32:47 +00:00
|
|
|
default = pkgs.zls;
|
2023-04-17 20:27:27 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf cfg.treesitter.enable {
|
|
|
|
vim.treesitter.enable = true;
|
|
|
|
vim.treesitter.grammars = [cfg.treesitter.package];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.lsp.enable {
|
|
|
|
vim.lsp.lspconfig.enable = true;
|
2024-11-10 01:05:48 +00:00
|
|
|
vim.lsp.lspconfig.sources.zig-lsp = servers.${cfg.lsp.server}.lspConfig;
|
2023-04-17 20:27:27 +00:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|