From 0d821154aaac085ba23bd602b684001b4c85b4a7 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Wed, 16 Jun 2021 23:03:45 +0200 Subject: vim: use lua generator for variables and LSP config --- usecases/desktop/development.nix | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'usecases/desktop') diff --git a/usecases/desktop/development.nix b/usecases/desktop/development.nix index 5d9697f..fad2596 100644 --- a/usecases/desktop/development.nix +++ b/usecases/desktop/development.nix @@ -13,15 +13,30 @@ let inherit (pkgs.unstable.python3Packages) python-language-server; + luaFormat = inputs.self.lib.generators.lua { }; + in { - options = with lib; { + options = with lib; with luaFormat.lib; { vim.lsp = mkOption { description = '' Configure Neovim to use these LSP servers; ''; - # TODO: change that to submodule with cmd, settings, capabilities, etc. - type = with types; attrsOf (listOf str); + type = with types; attrsOf (submodule { + freeformType = luaFormat.type; + + options = { + capabilities = mkOption { + default = mkRaw "capabilities"; + }; + cmd = mkOption { + type = with types; listOf str; + }; + on_attach = mkOption { + default = mkRaw "on_attach"; + }; + }; + }); default = { }; }; }; @@ -46,24 +61,18 @@ in ]; variables = { - rust_analyzer_path = "'${rust-analyzer-unwrapped}/bin/rust-analyzer'"; + rust_analyzer_path = "${rust-analyzer-unwrapped}/bin/rust-analyzer"; }; lsp = { - clangd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; - elixirls = [ "${elixir_ls}/bin/elixir-ls" ]; - pyls = [ "${python-language-server}/bin/pyls" ]; + clangd.cmd = [ "${clang-tools}/bin/clangd" "--resource-dir=${clang}/resource-root" ]; + elixirls.cmd = [ "${elixir_ls}/bin/elixir-ls" ]; + pyls.cmd = [ "${python-language-server}/bin/pyls" ]; }; luaConfig = with lib; let - toLua = list: "{ ${concatMapStringsSep ", " (elem: "'${escape [ "'" ] elem}'") list} }"; - lspconfigFor = name: cmd: '' - lspconfig["${name}"].setup { - capabilities = capabilities, - cmd = ${toLua cmd}, - on_attach = on_attach, - } - ''; + toLua = luaFormat.generate; + lspconfigFor = name: settings: "lspconfig['${name}'].setup ${toLua settings}"; lspconfig = concatStringsSep "\n" (mapAttrsToList lspconfigFor config.vim.lsp); -- cgit v1.2.3