diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 0f03866cc75f..5eea1528d659 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -77,18 +77,6 @@ let luaEnv = neovim-unwrapped.lua.withPackages(extraLuaPackages); - # Mapping a boolean argument to a key that tells us whether to add or not to - # add to nvim's 'embedded rc' this: - # let g:_host_prog=$out/bin/nvim- - # Or this: - # let g:loaded_${prog}_provider=0 - # While the latter tells nvim that this provider is not available - hostprog_check_table = { - node = withNodeJs; - python = false; - python3 = withPython3; - ruby = withRuby; - }; # as expected by packdir packpathDirs.myNeovimPackages = myVimPackage; ## Here we calculate all of the arguments to the 1st call of `makeWrapper` @@ -98,22 +86,9 @@ let 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) - ] ++ lib.optionals (myVimPackage.start != [] || myVimPackage.opt != []) [ - "--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 != "") [ @@ -144,12 +119,6 @@ let inherit rubyEnv; }; - genProviderSettings = prog: withProg: - if withProg then - "let g:${prog}_host_prog='${placeholder "out"}/bin/nvim-${prog}'" - else - "let g:loaded_${prog}_provider=0" - ; # to keep backwards compatibility for people using neovim.override legacyWrapper = neovim: { @@ -191,9 +160,43 @@ let wrapperArgs = lib.escapeShellArgs res.wrapperArgs + " " + extraMakeWrapperArgs; wrapRc = (configure != {}); }); + + /* Generate vim.g._host_prog lua rc to setup host providers + + Mapping a boolean argument to a key that tells us whether to add + vim.g._host_prog=$out/bin/nvim- + Or this: + let g:loaded_${prog}_provider=0 + While the latter tells nvim that this provider is not available */ + generateProviderRc = { + withPython3 ? true + , withNodeJs ? false + , withRuby ? true + + # so that we can pass the full neovim config while ignoring it + , ... + }: let + hostprog_check_table = { + node = withNodeJs; + python = false; + python3 = withPython3; + ruby = withRuby; + }; + + genProviderCommand = prog: withProg: + if withProg then + "vim.g.${prog}_host_prog='${placeholder "out"}/bin/nvim-${prog}'" + else + "vim.g.loaded_${prog}_provider=0"; + + hostProviderLua = lib.mapAttrsToList genProviderCommand hostprog_check_table; + in + lib.concatStringsSep ";" hostProviderLua; + in { inherit makeNeovimConfig; + inherit generateProviderRc; inherit legacyWrapper; buildNeovimPluginFrom2Nix = callPackage ./build-neovim-plugin.nix { diff --git a/pkgs/applications/editors/neovim/wrapper.nix b/pkgs/applications/editors/neovim/wrapper.nix index fac9b3c30990..887d647e2383 100644 --- a/pkgs/applications/editors/neovim/wrapper.nix +++ b/pkgs/applications/editors/neovim/wrapper.nix @@ -4,6 +4,8 @@ , python3 , python3Packages , callPackage +, neovimUtils +, vimUtils }: neovim: @@ -12,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 @@ -26,12 +29,30 @@ let # (e.g., in ~/.config/init.vim or project/.nvimrc) , wrapRc ? true , neovimRcContent ? "" + # entry to load in packpath + , packpathDirs , ... }@args: let wrapperArgsStr = if lib.isString wrapperArgs then wrapperArgs else lib.escapeShellArgs wrapperArgs; + # "--add-flags" (lib.escapeShellArgs flags) + # wrapper args used both when generating the manifest and in the final neovim executable + commonWrapperArgs = (lib.optionals (lib.isList wrapperArgs) wrapperArgs) + # vim accepts a limited number of commands so we join them all + ++ [ + "--add-flags" ''--cmd "lua ${providerLuaRc}"'' + # (lib.intersperse "|" hostProviderViml) + ] ++ lib.optionals (packpathDirs.myNeovimPackages.start != [] || packpathDirs.myNeovimPackages.opt != []) [ + "--add-flags" ''--cmd "set packpath^=${vimUtils.packDir packpathDirs}"'' + "--add-flags" ''--cmd "set rtp^=${vimUtils.packDir packpathDirs}"'' + ] + ; + + providerLuaRc = neovimUtils.generateProviderRc args; + # providerLuaRc = "toto"; + # 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 @@ -42,6 +63,7 @@ let [ "${neovim}/bin/nvim" "${placeholder "out"}/bin/nvim" ] ++ [ "--set" "NVIM_SYSTEM_RPLUGIN_MANIFEST" "${placeholder "out"}/rplugin.vim" ] ++ lib.optionals wrapRc [ "--add-flags" "-u ${writeText "init.vim" neovimRcContent}" ] + ++ commonWrapperArgs ; in assert withPython2 -> throw "Python2 support has been removed from the neovim wrapper, please remove withPython2 and python2Env."; @@ -72,7 +94,7 @@ let '' + lib.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 @@ -116,6 +138,7 @@ let nativeBuildInputs = [ makeWrapper ]; passthru = { + inherit providerLuaRc packpathDirs; unwrapped = neovim; initRc = neovimRcContent;