Commit 1d355385 authored by teto's avatar teto
Browse files

neovim: support per plugin lua config

Adds a 'type' option to the plugin submodule so the user can precise
what language it is. For now we limit the enum to lua/viml but we can
extend it afterwards (to fennel/teal/free)

This changes the type of userPluginViml, we could even remove it (or add
lua one).

lol
parent 53e39d12
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ let
        plugin = null;
        config = null;
        optional = false;
        type = "viml";
      };
    in
    map (x: defaultPlugin // (if x ? plugin then x else { plugin = x; })) plugins;
@@ -26,6 +27,15 @@ let
          example = "set title";
        };

        type = lib.mkOption {
          type = lib.types.either (lib.types.enum [
            "lua"
            "viml"
          ]) lib.types.str;
          description = "Language used in config. Configurations are aggregated per-language.";
          default = "viml";
        };

        optional = mkEnableOption "optional" // {
          description = "Don't load automatically on startup (load with :packadd)";
        };
@@ -78,12 +88,20 @@ in

    userPluginViml = lib.mkOption {
      readOnly = true;
      type = lib.types.listOf lib.types.lines;
      type = lib.types.nullOr lib.types.lines;
      description = ''
        The viml config set by the user.
      '';
    };

    userPluginConfigs = lib.mkOption {
      readOnly = true;
      type = lib.types.attrsOf lib.types.lines;
      description = ''
        The user configurations (viml, lua, ...) set by the user.
      '';
    };

    pluginPython3Packages = lib.mkOption {
      readOnly = true;
      type = lib.types.listOf (lib.types.functionTo (lib.types.listOf lib.types.package));
@@ -106,6 +124,13 @@ in
  config =
    let
      pluginsNormalized = config.plugins;

      userPluginConfigs =
        let
          grouped = lib.groupBy (x: x.type) pluginsNormalized;
          configsOnly = lib.foldl (acc: p: if p.config != null then acc ++ [ p.config ] else acc) [ ];
        in
        lib.mapAttrs (_name: vals: lib.concatStringsSep "\n" (configsOnly vals)) grouped;
    in
    {
      pluginAdvisedLua =
@@ -125,9 +150,9 @@ in
        in
        lib.foldl' op [ ] pluginsNormalized;

      userPluginViml = lib.foldl (
        acc: p: if p.config != null then acc ++ [ p.config ] else acc
      ) [ ] pluginsNormalized;
      userPluginViml = userPluginConfigs.viml or null;

      inherit userPluginConfigs;

      pluginPython3Packages = map (plugin: plugin.python3Dependencies or (_: [ ])) pluginsNormalized;

+2 −5
Original line number Diff line number Diff line
@@ -6,12 +6,8 @@
  config,
  vimUtils,
  vimPlugins,
  nodejs,
  neovim-unwrapped,
  bundlerEnv,
  ruby,
  lua,
  python3Packages,
  wrapNeovimUnstable,
}:
let
@@ -109,11 +105,12 @@ let

      # viml config set by the user along with the plugin
      inherit (checked_cfg)
        userPluginViml
        userPluginViml # redefine via userPluginConfigs
        runtimeDeps
        pluginAdvisedLua
        pluginPython3Packages
        luaDependencies
        userPluginConfigs
        ;

      # A Vim "package", see ':h packages'
+7 −1
Original line number Diff line number Diff line
@@ -100,7 +100,10 @@ let

        # we call vimrcContent without 'packages' to avoid the init.vim generation
        neovimRcContent' = lib.concatStringsSep "\n" (
          vimPackageInfo.userPluginViml ++ lib.optional (neovimRcContent != null) neovimRcContent
          lib.optional (vimPackageInfo.userPluginConfigs.viml or "" != "") (
            vimPackageInfo.userPluginConfigs.viml
          )
          ++ (lib.optional (neovimRcContent != null) neovimRcContent)
        );

        packpathDirs.myNeovimPackages = vimPackageInfo.vimPackage;
@@ -126,6 +129,9 @@ let
          lib.optional (luaDeps != [ ]) luaPathLuaRc
          ++ [ providerLuaRc ]
          ++ lib.optional (luaRcContent != "") luaRcContent
          ++ lib.optional (
            vimPackageInfo.userPluginConfigs.lua or "" != ""
          ) vimPackageInfo.userPluginConfigs.lua
          ++ lib.optional (neovimRcContent' != "") ''
            vim.cmd.source "${writeText "init.vim" neovimRcContent'}"
          ''