lib/neovim-plugin: Add lua configuration scoped to the plugin

This commit adds a `plugins.<name>.luaConfig` section controlling the
plugin specific configuration.

The section contains the internal `init` option, containing the plugin's
initialization code.

It also contains the public `pre` and `post` options, that allow to add
code before & after the `init` section

Finally, it contains the `final` option, being the concatenation of the
three previous options.
This commit is contained in:
Quentin Boyer 2024-08-19 23:31:57 +02:00 committed by nix-infra-bot
parent 2bc6a94992
commit d2f9e011d9
21 changed files with 129 additions and 35 deletions

View file

@ -246,7 +246,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
# ccc requires `termguicolors` to be enabled.
opts.termguicolors = lib.mkDefault true;
extraConfigLua = ''
plugins.ccc.luaConfig.content = ''
ccc = require('ccc')
ccc.setup(${helpers.toLuaObject cfg.settings})
'';

View file

@ -82,7 +82,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
coq_settings = cfg.settings;
};
extraConfigLua = "require('coq')";
plugins.coq-nvim.luaConfig.content = "require('coq')";
plugins.lsp = {
preConfig = ''

View file

@ -36,7 +36,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
callSetup = false;
extraConfig = cfg: {
extraConfigLua = ''
plugins.hydra.luaConfig.content = ''
hydra = require('hydra')
hydra.setup(${helpers.toLuaObject cfg.settings})

View file

@ -99,7 +99,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
'';
}
];
extraConfigLua =
plugins.mini.luaConfig.content =
lib.foldlAttrs (lines: name: config: ''
${lines}
require(${lib.nixvim.toLuaObject "mini.${name}"}).setup(${lib.nixvim.toLuaObject config})

View file

@ -48,6 +48,8 @@ helpers.neovim-plugin.mkNeovimPlugin {
};
callSetup = false;
hasConfigAttrs = false;
configLocation = null;
extraConfig =
cfg:
mkMerge [

View file

@ -122,7 +122,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
}
) cfg.keymaps;
extraConfigLua = ''
plugins.telescope.luaConfig.content = ''
require('telescope').setup(${toLuaObject cfg.settings})
local __telescopeExtensions = ${toLuaObject cfg.enabledExtensions}

View file

@ -431,7 +431,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
installPackage = false;
extraConfig = cfg: {
extraConfigLua =
plugins.treesitter.luaConfig.content =
# NOTE: Upstream state that the parser MUST be at the beginning of runtimepath.
# Otherwise the parsers from Neovim takes precedent, which may be incompatible with some queries.
(optionalString (cfg.settings.parser_install_dir != null) ''

View file

@ -596,7 +596,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
''
];
extraConfigLua = lib.optionalString opt.registrations.isDefined ''
plugins.which-key.luaConfig.content = lib.optionalString opt.registrations.isDefined ''
require("which-key").register(${toLuaObject cfg.registrations})
'';
};

View file

@ -373,7 +373,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
}
];
extraConfigLua = ''
plugins.yanky.luaConfig.content = ''
do
local utils = require('yanky.utils')
${optionalString config.plugins.telescope.enable "local mapping = require('yanky.telescope.mapping')"}

View file

@ -70,7 +70,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
callSetup = false;
extraConfig = cfg: {
extraConfigLua =
plugins.cmp.luaConfig.content =
''
local cmp = require('cmp')
cmp.setup(${helpers.toLuaObject cfg.settings})

View file

@ -39,7 +39,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
};
extraConfig = cfg: {
extraConfigLuaPre = ''
colorschemes.ayu.luaConfig.content = ''
local ayu = require("ayu")
ayu.setup(${toLuaObject cfg.settings})
ayu.colorscheme()

View file

@ -179,7 +179,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
# `settings` can either be passed to `with_config` before calling `setup`,
# or it can be passed as `setup`'s 2nd argument.
# See https://github.com/RRethy/base16-nvim/blob/6ac181b5733518040a33017dde654059cd771b7c/lua/base16-colorscheme.lua#L107-L125
extraConfigLuaPre = ''
colorschemes.base16.luaConfig.content = ''
do
local base16 = require('${luaName}')
base16.with_config(${toLuaObject cfg.settings})

View file

@ -34,7 +34,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
callSetup = false;
colorscheme = null;
extraConfig = cfg: {
extraConfigLuaPre = ''
colorschemes.onedark.luaConfig.content = ''
_onedark = require('onedark')
_onedark.setup(${lib.nixvim.toLuaObject cfg.settings})
_onedark.load()

View file

@ -31,7 +31,7 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
};
extraConfig = cfg: {
extraConfigLuaPre = ''
colorschemes.vscode.luaConfig.content = ''
local _vscode = require("vscode")
_vscode.setup(${toLuaObject cfg.settings})
_vscode.load()

View file

@ -147,7 +147,7 @@ helpers.neovim-plugin.mkNeovimPlugin {
];
# We only do this here because of enableLspFormat
extraConfigLua = ''
plugins.none-ls.luaConfig.content = ''
require("null-ls").setup(${helpers.toLuaObject setupOptions})
'';
};

View file

@ -190,7 +190,7 @@ nixvim.neovim-plugin.mkNeovimPlugin {
extraConfig = cfg: {
globals.lz_n = modules.mkAliasAndWrapDefsWithPriority id options.plugins.lz-n.settings;
extraConfigLua = mkIf (cfg.plugins != [ ]) ''
plugins.lz-n.luaConfig.content = mkIf (cfg.plugins != [ ]) ''
require('lz.n').load( ${nixvim.toLuaObject cfg.plugins})
'';
};

View file

@ -434,7 +434,8 @@ lib.nixvim.neovim-plugin.mkNeovimPlugin {
}
];
extraConfigLua = lib.mkIf cfg.enableTelescope ''require("telescope").load_extension("rest")'';
# TODO: There may be some interactions between this & telescope, maybe requiring #2292
plugins.rest.luaConfig.post = lib.mkIf cfg.enableTelescope ''require("telescope").load_extension("rest")'';
extraPackages = [ cfg.curlPackage ];