diff options
author | Matthieu Coudron <mcoudron@hotmail.com> | 2022-08-18 01:06:54 +0200 |
---|---|---|
committer | Matthieu Coudron <teto@users.noreply.github.com> | 2022-08-20 21:12:18 +0200 |
commit | e3c0484acd72b45dcfbf82dc0d26d232230ac172 (patch) | |
tree | 6c4c5e9ecbe0021647af57773287f5020e42e5df /pkgs/applications/editors/neovim | |
parent | 96905cef35b29e54169ca6811e679a318c571bd8 (diff) | |
download | nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar.gz nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar.bz2 nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar.lz nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar.xz nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.tar.zst nixlib-e3c0484acd72b45dcfbf82dc0d26d232230ac172.zip |
neovim: correctly concat single line configs
The changes introduced in https://github.com/NixOS/nixpkgs/pull/184364#discussion_r945772144 didn't concat correctly the plugin configs when they were a single string see: https://github.com/nix-community/home-manager/pull/3147 This adds a test for it.
Diffstat (limited to 'pkgs/applications/editors/neovim')
-rw-r--r-- | pkgs/applications/editors/neovim/tests/default.nix (renamed from pkgs/applications/editors/neovim/tests.nix) | 30 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/tests/init-override.vim (renamed from pkgs/applications/editors/neovim/neovim-override.vim) | 0 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/tests/init-single-lines.vim | 3 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/utils.nix | 23 | ||||
-rw-r--r-- | pkgs/applications/editors/neovim/wrapper.nix | 2 |
5 files changed, 48 insertions, 10 deletions
diff --git a/pkgs/applications/editors/neovim/tests.nix b/pkgs/applications/editors/neovim/tests/default.nix index 3f38abee5005..97c7a2505a5c 100644 --- a/pkgs/applications/editors/neovim/tests.nix +++ b/pkgs/applications/editors/neovim/tests/default.nix @@ -2,6 +2,7 @@ , lib, fetchFromGitHub, neovimUtils, wrapNeovimUnstable , neovim-unwrapped , fetchFromGitLab +, runCommandLocal , pkgs }: let @@ -19,6 +20,24 @@ let } ]; + packagesWithSingleLineConfigs = with vimPlugins; [ + { + plugin = vim-obsession; + config = ''map <Leader>$ <Cmd>Obsession<CR>''; + } + { + plugin = trouble-nvim; + config = ''" placeholder config''; + } + ]; + + nvimConfSingleLines = makeNeovimConfig { + plugins = packagesWithSingleLineConfigs; + customRC = '' + " just a comment + ''; + }; + nvimConfNix = makeNeovimConfig { inherit plugins; customRC = '' @@ -47,8 +66,9 @@ let sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc"; }; + # neovim-drv must be a wrapped neovim runTest = neovim-drv: buildCommand: - pkgs.runCommandLocal "test-${neovim-drv.name}" ({ + runCommandLocal "test-${neovim-drv.name}" ({ nativeBuildInputs = [ ]; meta.platforms = neovim-drv.meta.platforms; }) ('' @@ -68,6 +88,12 @@ rec { ################## nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix; + singlelinesconfig = runTest (wrapNeovim2 "-single-lines" nvimConfSingleLines) '' + assertFileContent \ + "$vimrcGeneric" \ + "${./init-single-lines.vim}" + ''; + nvim_via_override = neovim.override { extraName = "-via-override"; configure = { @@ -131,7 +157,7 @@ rec { nvim_via_override-test = runTest nvim_via_override '' assertFileContent \ "$vimrcGeneric" \ - "${./neovim-override.vim}" + "${./init-override.vim}" ''; diff --git a/pkgs/applications/editors/neovim/neovim-override.vim b/pkgs/applications/editors/neovim/tests/init-override.vim index 04ee66760185..04ee66760185 100644 --- a/pkgs/applications/editors/neovim/neovim-override.vim +++ b/pkgs/applications/editors/neovim/tests/init-override.vim diff --git a/pkgs/applications/editors/neovim/tests/init-single-lines.vim b/pkgs/applications/editors/neovim/tests/init-single-lines.vim new file mode 100644 index 000000000000..7b4df7787614 --- /dev/null +++ b/pkgs/applications/editors/neovim/tests/init-single-lines.vim @@ -0,0 +1,3 @@ +map <Leader>$ <Cmd>Obsession<CR> +" placeholder config +" just a comment diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index c3e41966534e..cb0c005759b8 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -49,12 +49,17 @@ let }; # transform all plugins into an attrset - # { optional = bool; plugin = package; dest = filename; } - pluginsNormalized = map (x: if x ? plugin then { dest = "init.vim"; optional = false; } // x else { plugin = x; optional = false;}) plugins; - - - - pluginRC = lib.concatMapStrings (p: p.config or "") pluginsNormalized; + # { optional = bool; plugin = package; } + pluginsNormalized = let + defaultPlugin = { + plugin = null; + config = null; + optional = false; + }; + in + map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; })) plugins; + + pluginRC = lib.foldl (acc: p: if p.config != null then acc ++ [p.config] else acc) [] pluginsNormalized; pluginsPartitioned = lib.partition (x: x.optional == true) pluginsNormalized; requiredPlugins = vimUtils.requiredPluginsForPackage myVimPackage; @@ -116,7 +121,11 @@ let manifestRc = vimUtils.vimrcContent ({ customRC = ""; }) ; # we call vimrcContent without 'packages' to avoid the init.vim generation - neovimRcContent = vimUtils.vimrcContent ({ beforePlugins = ""; customRC = pluginRC + customRC; packages = null; }); + neovimRcContent = vimUtils.vimrcContent ({ + beforePlugins = ""; + customRC = lib.concatStringsSep "\n" (pluginRC ++ [customRC]); + packages = null; + }); in builtins.removeAttrs args ["plugins"] // { diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index 2a0d60ce5a79..d0df6b7356ed 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -123,7 +123,7 @@ let unwrapped = neovim; initRc = neovimRcContent; - tests = callPackage ./tests.nix { + tests = callPackage ./tests { }; }; |