neovim: add 'autoconfigure' setting (#356271)

certain plugins need a custom configuration (available in passthru.initLua)
to work with nix. For instance unicode-vim needs to configure where to
find the data:
```
vim.g.Unicode_data_directory="${self.unicode-vim}/autoload/unicode"
```
if true, the wrapper automatically appends those snippets when necessary

first appearance of initLua in https://github.com/NixOS/nixpkgs/issues/352741

This will make testing those plugins easier.
This commit is contained in:
Matthieu Coudron 2024-11-24 16:29:58 +01:00 committed by GitHub
parent b675ca747f
commit d11140fa35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 3 deletions

View File

@ -80,7 +80,12 @@ let
sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc"; sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc";
}; };
# neovim-drv must be a wrapped neovim /* neovim-drv must be a wrapped neovim
- exposes lua config in $luarcGeneric
- exposes vim config in $vimrcGeneric
*/
runTest = neovim-drv: buildCommand: runTest = neovim-drv: buildCommand:
runCommandLocal "test-${neovim-drv.name}" ({ runCommandLocal "test-${neovim-drv.name}" ({
nativeBuildInputs = [ ]; nativeBuildInputs = [ ];
@ -164,6 +169,13 @@ in
${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e ${nvim_with_plug}/bin/nvim -V3log.txt -i NONE -c 'color base16-tomorrow-night' +quit! -e
''; '';
nvim_with_autoconfigure = pkgs.neovim.overrideAttrs(oa: {
plugins = [ vimPlugins.unicode-vim ];
autoconfigure = true;
# legacy wrapper sets it to false
wrapRc = true;
});
nvim_with_ftplugin = let nvim_with_ftplugin = let
# this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex # this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
# $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin # $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
@ -324,6 +336,12 @@ in
inherit nvim-with-luasnip; inherit nvim-with-luasnip;
autoconfigure = runTest nvim_with_autoconfigure ''
assertFileContains \
"$luarc" \
'${vimPlugins.unicode-vim.passthru.initLua}'
'';
# check that bringing in one plugin with lua deps makes those deps visible from wrapper # check that bringing in one plugin with lua deps makes those deps visible from wrapper
# for instance luasnip has a dependency on jsregexp # for instance luasnip has a dependency on jsregexp
can_require_transitive_deps = can_require_transitive_deps =

View File

@ -20,6 +20,10 @@ let
wrapper = { wrapper = {
extraName ? "" extraName ? ""
# certain plugins need a custom configuration (available in passthru.initLua)
# to work with nix.
# if true, the wrapper automatically appends those snippets when necessary
, autoconfigure ? false
# should contain all args but the binary. Can be either a string or list # should contain all args but the binary. Can be either a string or list
, wrapperArgs ? [] , wrapperArgs ? []
, withPython2 ? false , withPython2 ? false
@ -87,11 +91,19 @@ let
packpathDirs.myNeovimPackages = myVimPackage; packpathDirs.myNeovimPackages = myVimPackage;
finalPackdir = neovimUtils.packDir packpathDirs; finalPackdir = neovimUtils.packDir packpathDirs;
luaPluginRC = let
op = acc: normalizedPlugin:
acc ++ lib.optional (finalAttrs.autoconfigure && normalizedPlugin.plugin.passthru ? initLua) normalizedPlugin.plugin.passthru.initLua;
in
lib.foldl' op [] pluginsNormalized;
rcContent = '' rcContent = ''
${luaRcContent} ${luaRcContent}
'' + lib.optionalString (neovimRcContent' != null) '' '' + lib.optionalString (neovimRcContent' != null) ''
vim.cmd.source "${writeText "init.vim" neovimRcContent'}" vim.cmd.source "${writeText "init.vim" neovimRcContent'}"
''; '' +
lib.concatStringsSep "\n" luaPluginRC
;
getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ])); getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));
@ -155,7 +167,7 @@ let
__structuredAttrs = true; __structuredAttrs = true;
dontUnpack = true; dontUnpack = true;
inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby; inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby;
inherit wrapRc providerLuaRc packpathDirs; inherit autoconfigure wrapRc providerLuaRc packpathDirs;
inherit python3Env rubyEnv; inherit python3Env rubyEnv;
inherit wrapperArgs generatedWrapperArgs; inherit wrapperArgs generatedWrapperArgs;
luaRcContent = rcContent; luaRcContent = rcContent;