2023-04-17 22:27:27 +02:00
|
|
|
{
|
|
|
|
config,
|
2024-03-09 06:49:22 +01:00
|
|
|
pkgs,
|
2023-04-17 22:27:27 +02:00
|
|
|
lib,
|
|
|
|
...
|
2023-11-08 03:16:46 +01:00
|
|
|
}: let
|
2024-11-10 02:05:48 +01:00
|
|
|
inherit (builtins) attrNames;
|
2024-03-09 06:49:22 +01:00
|
|
|
inherit (lib.options) mkEnableOption mkOption;
|
|
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
|
|
inherit (lib.lists) isList;
|
2024-11-10 02:05:48 +01:00
|
|
|
inherit (lib.types) either listOf package str enum;
|
2024-03-09 06:49:22 +01:00
|
|
|
inherit (lib.nvim.lua) expToLua;
|
|
|
|
inherit (lib.nvim.types) mkGrammarOption;
|
2023-11-08 03:16:46 +01:00
|
|
|
|
2024-11-10 02:05:48 +01: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 22:27:27 +02:00
|
|
|
cfg = config.vim.languages.zig;
|
|
|
|
in {
|
|
|
|
options.vim.languages.zig = {
|
2023-07-30 17:36:10 +02:00
|
|
|
enable = mkEnableOption "Zig language support";
|
2023-04-17 22:27:27 +02:00
|
|
|
|
|
|
|
treesitter = {
|
2023-10-21 19:15:36 +02:00
|
|
|
enable = mkEnableOption "Zig treesitter" // {default = config.vim.languages.enableTreesitter;};
|
2024-03-09 06:49:22 +01:00
|
|
|
package = mkGrammarOption pkgs "zig";
|
2023-04-17 22:27:27 +02:00
|
|
|
};
|
2023-06-05 22:10:25 +02:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
lsp = {
|
2024-11-10 02:05:48 +01: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 22:10:25 +02:00
|
|
|
|
2023-04-17 22:27:27 +02:00
|
|
|
package = mkOption {
|
2023-09-23 00:28:39 +02:00
|
|
|
description = "ZLS package, or the command to run as a list of strings";
|
2024-03-09 06:49:22 +01:00
|
|
|
type = either package (listOf str);
|
2023-05-01 17:32:47 +02:00
|
|
|
default = pkgs.zls;
|
2023-04-17 22:27:27 +02: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 02:05:48 +01:00
|
|
|
vim.lsp.lspconfig.sources.zig-lsp = servers.${cfg.lsp.server}.lspConfig;
|
2023-04-17 22:27:27 +02:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|