buildVimPlugin: add vimCommandCheckHook

Modeled after pythonImportCheckHook, this checks a command can be run once the plugin is installed
This commit is contained in:
Matthieu Coudron 2022-04-29 10:09:40 +02:00 committed by Matthieu Coudron
parent 2415f1e0a5
commit 9663a29afa
5 changed files with 47 additions and 9 deletions

View File

@ -1,6 +1,7 @@
{ lib, stdenv
, rtpPath
, vim
, vimCommandCheckHook
, vimGenDocHook
}:
@ -30,6 +31,7 @@ rec {
forceShare= [ "man" "info" ];
nativeBuildInputs = attrs.nativeBuildInputs or []
++ [ vimCommandCheckHook ]
++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) vimGenDocHook;
inherit unpackPhase configurePhase buildPhase addonInfo preInstall postInstall;

View File

@ -3,7 +3,7 @@
let
inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix vimGenDocHook;
inherit (vimUtils.override {inherit vim;}) buildVimPluginFrom2Nix vimGenDocHook vimCommandCheckHook;
inherit (lib) extends;
@ -12,7 +12,10 @@ let
toVimPlugin = drv:
drv.overrideAttrs(oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ vimGenDocHook ];
nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [
vimGenDocHook
vimCommandCheckHook
];
passthru = (oldAttrs.passthru or {}) // {
vimPlugin = true;
};

View File

@ -450,11 +450,8 @@ self: super: {
--replace "code-minimap" "${code-minimap}/bin/code-minimap"
'';
doCheck = true;
checkPhase = ''
${neovim-unwrapped}/bin/nvim -n -u NONE -i NONE -V1 --cmd "set rtp+=$out" --cmd "runtime! plugin/*.vim" -c "MinimapToggle" +quit!
'';
doInstallCheck = true;
vimCommandCheck = "MinimapToggle";
});
ncm2 = super.ncm2.overrideAttrs (old: {

View File

@ -0,0 +1,25 @@
# Setup hook for checking whether a vim command exists
echo "Sourcing vim-command-check-hook.sh"
vimCommandCheckHook () {
echo "Executing vimCommandCheckHook"
if [ -n "$vimCommandCheck" ]; then
echo "Check whether the following modules can be imported: $vimCommandCheck"
# editorconfig-checker-disable
export HOME="$TMPDIR"
@vimBinary@ -es -n -u NONE -i NONE --clean -V1 --cmd "set rtp+=$out" \
--cmd "runtime! plugin/*.vim" <<-EOF
if exists(":$vimCommandCheck") == 2
cquit 0
else
cquit 1
fi
EOF
fi
}
echo "Using vimCommandCheckHook"
preDistPhases+=" vimCommandCheckHook"

View File

@ -521,8 +521,19 @@ rec {
};
} ./vim-gen-doc-hook.sh) {};
inherit (import ./build-vim-plugin.nix { inherit lib stdenv rtpPath vim vimGenDocHook; })
buildVimPlugin buildVimPluginFrom2Nix;
vimCommandCheckHook = callPackage ({ neovim-unwrapped }:
makeSetupHook {
name = "vim-command-check-hook";
deps = [ neovim-unwrapped ];
substitutions = {
vimBinary = "${neovim-unwrapped}/bin/nvim";
inherit rtpPath;
};
} ./vim-command-check-hook.sh) {};
inherit (import ./build-vim-plugin.nix {
inherit lib stdenv rtpPath vim vimGenDocHook vimCommandCheckHook;
}) buildVimPlugin buildVimPluginFrom2Nix;
# used to figure out which python dependencies etc. neovim needs
requiredPlugins = {