Skip to content

Commit

Permalink
neovim: add 'autoconfigure' setting
Browse files Browse the repository at this point in the history
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 #352741

This will make testing those plugins easier.
  • Loading branch information
teto committed Nov 23, 2024
1 parent 2b1d107 commit 0e67d16
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
20 changes: 19 additions & 1 deletion pkgs/applications/editors/neovim/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ let
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:
runCommandLocal "test-${neovim-drv.name}" ({
nativeBuildInputs = [ ];
Expand Down Expand Up @@ -164,6 +169,13 @@ in
${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
# 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
Expand Down Expand Up @@ -324,6 +336,12 @@ in

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
# for instance luasnip has a dependency on jsregexp
can_require_transitive_deps =
Expand Down
16 changes: 14 additions & 2 deletions pkgs/applications/editors/neovim/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ let

wrapper = {
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
, wrapperArgs ? []
, withPython2 ? false
Expand Down Expand Up @@ -87,11 +91,19 @@ let
packpathDirs.myNeovimPackages = myVimPackage;
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 = ''
${luaRcContent}
'' + lib.optionalString (neovimRcContent' != null) ''
vim.cmd.source "${writeText "init.vim" neovimRcContent'}"
'';
'' +
lib.concatStringsSep "\n" luaPluginRC
;

getDeps = attrname: map (plugin: plugin.${attrname} or (_: [ ]));

Expand Down Expand Up @@ -155,7 +167,7 @@ let
__structuredAttrs = true;
dontUnpack = true;
inherit viAlias vimAlias withNodeJs withPython3 withPerl withRuby;
inherit wrapRc providerLuaRc packpathDirs;
inherit autoconfigure wrapRc providerLuaRc packpathDirs;
inherit python3Env rubyEnv;
inherit wrapperArgs generatedWrapperArgs;
luaRcContent = rcContent;
Expand Down

0 comments on commit 0e67d16

Please sign in to comment.