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 --- common/vim.nix | 18 ++++++++---------- usecases/desktop/development.nix | 39 ++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/common/vim.nix b/common/vim.nix index 850eaf3..83ac31b 100644 --- a/common/vim.nix +++ b/common/vim.nix @@ -5,6 +5,8 @@ inputs: let inherit (pkgs.unstable) vimPlugins wrapNeovim; + luaFormat = inputs.self.lib.generators.lua { }; + neovim-unwrapped = inputs.neovim-master.defaultPackage.${config.nixpkgs.system}; cfg = config.vim; @@ -18,7 +20,7 @@ let ${(concatStringsSep "\n" (mapAttrsToList - (variable: value: "vim.g.${variable} = ${value}") + (variable: value: "vim.g.${variable} = ${luaFormat.generate value}") cfg.variables))} -- vim.lua from the NixOS configuration @@ -104,13 +106,9 @@ in options.vim = with lib; { variables = mkOption { - type = types.attrsOf types.str; + type = types.attrsOf luaFormat.type; default = {}; - description = '' - Extra global variables to add at the beginning of the vim configuration. - - Remember to escape strings with single-quotes. - ''; + description = "Extra global variables to add at the beginning of the vim configuration."; }; extraPlugins = mkOption { @@ -148,9 +146,9 @@ in vim = { wrappedPackage = myNeovim; variables = { - dominant_color = "'${config.theme.colors.dominant}'"; - ripgrep_path = "'${pkgs.ripgrep}/bin/rg'"; - fd_path = "'${pkgs.fd}/bin/fd'"; + dominant_color = "${config.theme.colors.dominant}"; + ripgrep_path = "${pkgs.ripgrep}/bin/rg"; + fd_path = "${pkgs.fd}/bin/fd"; }; }; 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