diff --git a/pkgs/applications/editors/neovim/tests.nix b/pkgs/applications/editors/neovim/tests/default.nix similarity index 86% rename from pkgs/applications/editors/neovim/tests.nix rename to 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 $ Obsession''; + } + { + 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 similarity index 100% rename from pkgs/applications/editors/neovim/neovim-override.vim rename to 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 $ Obsession +" 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; + # { 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.concatMapStrings (p: p.config or "") pluginsNormalized; + 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 { }; };