feat: make clang lsp install optional

This commit is contained in:
Ching Pei Yang 2023-09-19 01:30:45 +02:00
parent ed09cb7ed6
commit 232d93024c

View file

@ -9,6 +9,10 @@ with builtins; let
cfg = config.vim.languages.clang; cfg = config.vim.languages.clang;
defaultServer = "ccls"; defaultServer = "ccls";
packageToCmd = package: defaultCmd:
if isList cfg.lsp.package
then nvim.lua.expToLua cfg.lsp.package
else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }'';
servers = { servers = {
ccls = { ccls = {
package = pkgs.ccls; package = pkgs.ccls;
@ -16,7 +20,7 @@ with builtins; let
lspconfig.ccls.setup{ lspconfig.ccls.setup{
capabilities = capabilities; capabilities = capabilities;
on_attach=default_on_attach; on_attach=default_on_attach;
cmd = {"${cfg.lsp.package}/bin/ccls"}; cmd = ${packageToCmd cfg.lsp.package "ccls"};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
} }
''; '';
@ -30,7 +34,7 @@ with builtins; let
lspconfig.clangd.setup{ lspconfig.clangd.setup{
capabilities = clangd_cap; capabilities = clangd_cap;
on_attach=default_on_attach; on_attach=default_on_attach;
cmd = {"${cfg.lsp.package}/bin/clangd"}; cmd = ${packageToCmd cfg.lsp.package "clangd"};
${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"}
} }
''; '';
@ -95,7 +99,7 @@ in {
package = mkOption { package = mkOption {
description = "clang LSP server package"; description = "clang LSP server package";
type = types.package; type = with types; either package (listOf str);
default = servers.${cfg.lsp.server}.package; default = servers.${cfg.lsp.server}.package;
}; };