From 232d93024c933a65999c38feebbcef9030c2d873 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Tue, 19 Sep 2023 01:30:45 +0200 Subject: [PATCH] feat: make clang lsp install optional --- modules/languages/clang.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/languages/clang.nix b/modules/languages/clang.nix index 7d201e4..3235c45 100644 --- a/modules/languages/clang.nix +++ b/modules/languages/clang.nix @@ -9,6 +9,10 @@ with builtins; let cfg = config.vim.languages.clang; defaultServer = "ccls"; + packageToCmd = package: defaultCmd: + if isList cfg.lsp.package + then nvim.lua.expToLua cfg.lsp.package + else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }''; servers = { ccls = { package = pkgs.ccls; @@ -16,7 +20,7 @@ with builtins; let lspconfig.ccls.setup{ capabilities = capabilities; 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}"} } ''; @@ -30,7 +34,7 @@ with builtins; let lspconfig.clangd.setup{ capabilities = clangd_cap; 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}"} } ''; @@ -95,7 +99,7 @@ in { package = mkOption { description = "clang LSP server package"; - type = types.package; + type = with types; either package (listOf str); default = servers.${cfg.lsp.server}.package; };