From 51e69413cfc928d02e19c27c9342af2931166d4d Mon Sep 17 00:00:00 2001 From: Mango The Fourth <40720523+MangoIV@users.noreply.github.com> Date: Sun, 30 Jun 2024 19:17:04 +0200 Subject: [PATCH] neovimUtils.grammarToPlugin: also move the queries (#321550) This installs queries from source into the neovim expected folder. Some grammar queries are already in a folder like expected by neovim but others (notably the treesitter official ones) are not so the code deals with both. For instance the koka grammar puts its queries directly in "queries" folder https://github.com/mtoohey31/tree-sitter-koka/tree/main/queries but some others puts it in a folder expected by neovim like https://github.com/tjdevries/tree-sitter-lua/tree/master/queries/lua . --- pkgs/applications/editors/neovim/utils.nix | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/editors/neovim/utils.nix b/pkgs/applications/editors/neovim/utils.nix index 8f9a5b880032..438c9904829c 100644 --- a/pkgs/applications/editors/neovim/utils.nix +++ b/pkgs/applications/editors/neovim/utils.nix @@ -7,7 +7,6 @@ , ruby , lua , python3Packages -, writeText , wrapNeovimUnstable , runCommand }: @@ -78,7 +77,7 @@ let ++ (extraPython3Packages ps) ++ (lib.concatMap (f: f ps) pluginPython3Packages)); - luaEnv = neovim-unwrapped.lua.withPackages(extraLuaPackages); + luaEnv = neovim-unwrapped.lua.withPackages extraLuaPackages; # as expected by packdir packpathDirs.myNeovimPackages = myVimPackage; @@ -101,13 +100,13 @@ let "--prefix" "LUA_CPATH" ";" (neovim-unwrapped.lua.pkgs.luaLib.genLuaCPathAbsStr luaEnv) ]; - manifestRc = vimUtils.vimrcContent ({ customRC = ""; }) ; + manifestRc = vimUtils.vimrcContent { customRC = ""; }; # we call vimrcContent without 'packages' to avoid the init.vim generation - neovimRcContent = vimUtils.vimrcContent ({ + neovimRcContent = vimUtils.vimrcContent { beforePlugins = ""; customRC = lib.concatStringsSep "\n" (pluginRC ++ [customRC]); packages = null; - }); + }; in builtins.removeAttrs args ["plugins"] // { @@ -225,8 +224,25 @@ let } // grammar.meta; } '' - mkdir -p $out/parser - ln -s ${grammar}/parser $out/parser/${name}.so + mkdir -p "$out/parser" + ln -s "${grammar}/parser" "$out/parser/${name}.so" + + mkdir -p "$out/queries/${name}" + if [ -d "${grammar}/queries/${name}" ]; then + echo "moving queries from neovim queries dir" + for file in "${grammar}/queries/${name}"*; do + ln -s "$file" "$out/queries/${name}/$(basename "$file")" + done + else + if [ -d "${grammar}/queries" ]; then + echo "moving queries from standard queries dir" + for file in "${grammar}/queries/"*; do + ln -s "$file" "$out/queries/${name}/$(basename "$file")" + done + else + echo "missing queries for ${name}" + fi + fi ''); in