mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-22 21:30:51 +00:00
languages/zig: don't bundle zig, improve module
This commit is contained in:
parent
c6ff6bbca6
commit
4f93abc2f2
1 changed files with 29 additions and 26 deletions
|
@ -4,13 +4,33 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
|
inherit (builtins) attrNames;
|
||||||
inherit (lib.options) mkEnableOption mkOption;
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (lib.lists) isList;
|
inherit (lib.lists) isList;
|
||||||
inherit (lib.types) either listOf package str;
|
inherit (lib.types) 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;
|
||||||
|
|
||||||
|
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'}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
cfg = config.vim.languages.zig;
|
cfg = config.vim.languages.zig;
|
||||||
in {
|
in {
|
||||||
options.vim.languages.zig = {
|
options.vim.languages.zig = {
|
||||||
|
@ -22,20 +42,19 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
lsp = {
|
lsp = {
|
||||||
enable = mkEnableOption "Zig LSP support (zls)" // {default = config.vim.languages.enableLSP;};
|
enable = mkEnableOption "Zig LSP support" // {default = config.vim.languages.enableLSP;};
|
||||||
|
|
||||||
|
server = mkOption {
|
||||||
|
type = enum (attrNames servers);
|
||||||
|
default = defaultServer;
|
||||||
|
description = "Zig LSP server to use";
|
||||||
|
};
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
description = "ZLS package, or the command to run as a list of strings";
|
description = "ZLS package, or the command to run as a list of strings";
|
||||||
example = ''[lib.getExe pkgs.jdt-language-server "-data" "~/.cache/jdtls/workspace"]'';
|
|
||||||
type = either package (listOf str);
|
type = either package (listOf str);
|
||||||
default = pkgs.zls;
|
default = pkgs.zls;
|
||||||
};
|
};
|
||||||
|
|
||||||
zigPackage = mkOption {
|
|
||||||
description = "Zig package used by ZLS";
|
|
||||||
type = package;
|
|
||||||
default = pkgs.zig;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
|
@ -46,23 +65,7 @@ in {
|
||||||
|
|
||||||
(mkIf cfg.lsp.enable {
|
(mkIf cfg.lsp.enable {
|
||||||
vim.lsp.lspconfig.enable = true;
|
vim.lsp.lspconfig.enable = true;
|
||||||
vim.lsp.lspconfig.sources.zig-lsp = ''
|
vim.lsp.lspconfig.sources.zig-lsp = servers.${cfg.lsp.server}.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"}''
|
|
||||||
},
|
|
||||||
settings = {
|
|
||||||
["zls"] = {
|
|
||||||
zig_exe_path = "${cfg.lsp.zigPackage}/bin/zig",
|
|
||||||
zig_lib_path = "${cfg.lsp.zigPackage}/lib/zig",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue