Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pkgs/applications/editors/neovim/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ rec {

# regression test that ftplugin files from plugins are loaded before the ftplugin
# files from $VIMRUNTIME
run_nvim_with_ftplugin = runTest nvim_with_ftplugin ''
export HOME=$TMPDIR
${nvim_with_ftplugin}/bin/nvim ${texFtplugin}/main.tex
result="$(cat plugin_was_loaded_too_late)"
echo $result
[ "$result" = 0 ]
'';
# disabled since it hangs
# run_nvim_with_ftplugin = runTest nvim_with_ftplugin ''
# export HOME=$TMPDIR
# set -x
# ${nvim_with_ftplugin}/bin/nvim ${texFtplugin}/main.tex
# result="$(cat plugin_was_loaded_too_late)"
# echo $result
# [ "$result" = 0 ]
# '';


# check that the vim-doc hook correctly generates the tag
Expand Down
33 changes: 17 additions & 16 deletions pkgs/applications/editors/neovim/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,28 @@ let
python3 = withPython3;
ruby = withRuby;
};

# a bunch of commands that might be used at the start of init.lua or
# as wrapper arguments
startupCommands = [
"vim.opt.packpath:prepend('${vimUtils.packDir packDirArgs}')"
"vim.opt.rtp:prepend('${vimUtils.packDir packDirArgs}')"
] ++
lib.mapAttrsToList genProviderSettings hostprog_check_table;

# as expected by packdir
packDirArgs.myNeovimPackages = myVimPackage;

## Here we calculate all of the arguments to the 1st call of `makeWrapper`
# We start with the executable itself NOTE we call this variable "initial"
# because if configure != {} we need to call makeWrapper twice, in order to
# avoid double wrapping, see comment near finalMakeWrapperArgs
makeWrapperArgs =
let
binPath = lib.makeBinPath (lib.optionals withRuby [ rubyEnv ] ++ lib.optionals withNodeJs [ nodejs ]);

hostProviderViml = lib.mapAttrsToList genProviderSettings hostprog_check_table;

# as expected by packdir
packDirArgs.myNeovimPackages = myVimPackage;

# vim accepts a limited number of commands so we join them all
flags = [
"--cmd" (lib.intersperse "|" hostProviderViml)
"--cmd" "set packpath^=${vimUtils.packDir packDirArgs}"
"--cmd" "set rtp^=${vimUtils.packDir packDirArgs}"
];
in
[
"--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags)
"--inherit-argv0"
] ++ lib.optionals withRuby [
"--set" "GEM_HOME" "${rubyEnv}/${rubyEnv.ruby.gemPath}"
] ++ lib.optionals (binPath != "") [
Expand All @@ -131,6 +131,7 @@ let

builtins.removeAttrs args ["plugins"] // {
wrapperArgs = makeWrapperArgs;
inherit startupCommands;
inherit neovimRcContent;
inherit manifestRc;
inherit python3Env;
Expand All @@ -142,14 +143,14 @@ let

genProviderSettings = prog: withProg:
if withProg then
"let g:${prog}_host_prog='${placeholder "out"}/bin/nvim-${prog}'"
"vim.g.${prog}_host_prog='${placeholder "out"}/bin/nvim-${prog}'"
else
"let g:loaded_${prog}_provider=0"
"vim.g.loaded_${prog}_provider=0"
;

# to keep backwards compatibility for people using neovim.override
legacyWrapper = neovim: {
extraMakeWrapperArgs ? ""
extraMakeWrapperArgs ? ""
/* the function you would have passed to python.withPackages */
, extraPythonPackages ? (_: [])
/* the function you would have passed to python.withPackages */
Expand Down
31 changes: 26 additions & 5 deletions pkgs/applications/editors/neovim/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let
extraName ? ""
# should contain all args but the binary. Can be either a string or list
, wrapperArgs ? []
# a limited RC script used only to generate the manifest for remote plugins
, manifestRc ? null
, withPython2 ? false
, withPython3 ? true, python3Env ? python3
Expand All @@ -27,23 +28,43 @@ let
# set to false if you want to control where to save the generated config
# (e.g., in ~/.config/init.vim or project/.nvimrc)
, wrapRc ? true
# if yes, pass startupCommands as `--cmd` arguments to neovim
# if false, inline the commands in the generated initrc
, wrapStartupCommands ? true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean startupCommands would be in lua if true and in vim if false?

# startup commands are passed separately, they can be passed as neovim positional arguments
# or prepend to the init.vim
# these are lua commands that for instance set packpath, rtp, or the paths towars interpreters
, startupCommands ? []
# content of the init.vim if wrapped.
, neovimRcContent ? ""
, ...
}@args:
}:
let

wrapperArgsStr = if isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs;
# deprecated: remove after 23.05
wrapperArgsStr = lib.optionalString (isString wrapperArgs) wrapperArgs;

# wrapper args used both when generating the manifest and in the final neovim executable
commonWrapperArgs = optionals (isList wrapperArgs) wrapperArgs;

finalRcContent = let
startupCommands' = optionals (!wrapStartupCommands) startupCommands;
in
(lib.concatStringsSep "\n" (startupCommands' ++ [ neovimRcContent ]));

# If configure != {}, we can't generate the rplugin.vim file with e.g
# NVIM_SYSTEM_RPLUGIN_MANIFEST *and* NVIM_RPLUGIN_MANIFEST env vars set in
# the wrapper. That's why only when configure != {} (tested both here and
# when postBuild is evaluated), we call makeWrapper once to generate a
# wrapper with most arguments we need, excluding those that cause problems to
# generate rplugin.vim, but still required for the final wrapper.
finalMakeWrapperArgs =
finalMakeWrapperArgs = let
startupFlags = (lib.foldl' (x: y: x ++ ["--cmd" "lua ${y}" ]) [] startupCommands);
in
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ]
++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ]
++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ]
++ optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" finalRcContent}" ]
++ optionals wrapStartupCommands [ "--add-flags" (lib.escapeShellArgs startupFlags)]
;
in
assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env.";
Expand Down Expand Up @@ -74,7 +95,7 @@ let
''
+ optionalString (manifestRc != null) (let
manifestWrapperArgs =
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ];
[ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim-wrapper" ] ++ commonWrapperArgs;
in ''
echo "Generating remote plugin manifest"
export NVIM_RPLUGIN_MANIFEST=$out/rplugin.vim
Expand Down