2022-11-16 05:02:14 +00:00
|
|
|
{ lib, callPackage, tree-sitter, neovim, runCommand }:
|
2022-10-30 05:27:25 +00:00
|
|
|
|
|
|
|
self: super:
|
|
|
|
|
|
|
|
let
|
2022-11-02 01:09:23 +00:00
|
|
|
generatedGrammars = callPackage ./generated.nix {
|
2022-10-30 05:27:25 +00:00
|
|
|
buildGrammar = callPackage ../../../../../development/tools/parsing/tree-sitter/grammar.nix { };
|
|
|
|
};
|
|
|
|
|
2022-11-02 01:09:23 +00:00
|
|
|
generatedDerivations = lib.filterAttrs (_: lib.isDerivation) generatedGrammars;
|
|
|
|
|
2022-11-04 13:51:04 +00:00
|
|
|
# add aliases so grammars from `tree-sitter` are overwritten in `withPlugins`
|
|
|
|
# for example, for ocaml_interface, the following aliases will be added
|
|
|
|
# ocaml-interface
|
|
|
|
# tree-sitter-ocaml-interface
|
|
|
|
# tree-sitter-ocaml_interface
|
2022-11-16 17:54:49 +00:00
|
|
|
builtGrammars = generatedGrammars // lib.concatMapAttrs
|
|
|
|
(k: v:
|
|
|
|
let
|
|
|
|
replaced = lib.replaceStrings [ "_" ] [ "-" ] k;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"tree-sitter-${k}" = v;
|
|
|
|
} // lib.optionalAttrs (k != replaced) {
|
|
|
|
${replaced} = v;
|
|
|
|
"tree-sitter-${replaced}" = v;
|
|
|
|
})
|
|
|
|
generatedDerivations;
|
2022-11-02 01:09:23 +00:00
|
|
|
|
|
|
|
allGrammars = lib.attrValues generatedDerivations;
|
2022-10-30 05:27:25 +00:00
|
|
|
|
|
|
|
# Usage:
|
|
|
|
# pkgs.vimPlugins.nvim-treesitter.withPlugins (p: [ p.c p.java ... ])
|
|
|
|
# or for all grammars:
|
|
|
|
# pkgs.vimPlugins.nvim-treesitter.withAllGrammars
|
|
|
|
withPlugins =
|
2022-11-16 19:49:47 +00:00
|
|
|
f: self.nvim-treesitter.overrideAttrs (_: {
|
|
|
|
passthru.dependencies = map
|
|
|
|
(grammar:
|
|
|
|
let
|
|
|
|
name = lib.pipe grammar [
|
|
|
|
lib.getName
|
|
|
|
|
|
|
|
# added in buildGrammar
|
|
|
|
(lib.removeSuffix "-grammar")
|
|
|
|
|
|
|
|
# grammars from tree-sitter.builtGrammars
|
|
|
|
(lib.removePrefix "tree-sitter-")
|
|
|
|
(lib.replaceStrings [ "-" ] [ "_" ])
|
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
runCommand "nvim-treesitter-${name}-grammar" { } ''
|
|
|
|
mkdir -p $out/parser
|
|
|
|
ln -s ${grammar}/parser $out/parser/${name}.so
|
|
|
|
''
|
|
|
|
)
|
|
|
|
(f (tree-sitter.builtGrammars // builtGrammars));
|
2022-10-30 05:27:25 +00:00
|
|
|
});
|
2022-11-16 05:02:14 +00:00
|
|
|
|
|
|
|
withAllGrammars = withPlugins (_: allGrammars);
|
2022-10-30 05:27:25 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2022-11-21 14:17:33 +00:00
|
|
|
postPatch = ''
|
|
|
|
rm -r parser
|
|
|
|
'';
|
|
|
|
|
2022-10-30 05:27:25 +00:00
|
|
|
passthru = {
|
2022-11-16 05:02:14 +00:00
|
|
|
inherit builtGrammars allGrammars withPlugins withAllGrammars;
|
|
|
|
|
|
|
|
tests.check-queries =
|
|
|
|
let
|
|
|
|
nvimWithAllGrammars = neovim.override {
|
|
|
|
configure.packages.all.start = [ withAllGrammars ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
runCommand "nvim-treesitter-check-queries"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ nvimWithAllGrammars ];
|
|
|
|
CI = true;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
touch $out
|
|
|
|
export HOME=$(mktemp -d)
|
|
|
|
ln -s ${withAllGrammars}/CONTRIBUTING.md .
|
2022-10-30 05:27:25 +00:00
|
|
|
|
2022-11-16 05:02:14 +00:00
|
|
|
nvim --headless "+luafile ${withAllGrammars}/scripts/check-queries.lua" | tee log
|
2022-10-30 05:27:25 +00:00
|
|
|
|
2022-11-16 05:02:14 +00:00
|
|
|
if grep -q Warning log; then
|
|
|
|
echo "Error: warnings were emitted by the check"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
2022-10-30 05:27:25 +00:00
|
|
|
};
|
2022-11-02 01:31:59 +00:00
|
|
|
|
2022-12-13 15:58:31 +00:00
|
|
|
meta = with lib; (super.nvim-treesitter.meta or { }) // {
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ figsoda ];
|
|
|
|
};
|
2022-10-30 05:27:25 +00:00
|
|
|
}
|