Skip to content

Commit

Permalink
add option to override loaded treesitter grammars
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Apr 1, 2024
1 parent e385190 commit 84ad578
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions lib/buildPlugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,6 @@ let
};
};

treesitterGrammars = ts.withPlugins (p: [
p.tree-sitter-scala
p.tree-sitter-c
p.tree-sitter-nix
p.tree-sitter-elm
p.tree-sitter-haskell
p.tree-sitter-python
p.tree-sitter-rust
p.tree-sitter-markdown
p.tree-sitter-markdown-inline
p.tree-sitter-comment
p.tree-sitter-toml
p.tree-sitter-make
p.tree-sitter-tsx
p.tree-sitter-typescript
p.tree-sitter-html
p.tree-sitter-javascript
p.tree-sitter-css
p.tree-sitter-graphql
p.tree-sitter-json
p.tree-sitter-smithy
]);

smithy-lsp = pkgs.callPackage ./smithy-lspconfig.nix { };

smithyLspHook = ''
Expand All @@ -62,12 +39,12 @@ let
${queriesHook}
'';

tsPostPatchHook = ''
tsPostPatchHook = grammars: ''
rm -r parser
ln -s ${treesitterGrammars} parser
ln -s ${grammars} parser
'';

buildPlug = name: buildVimPlugin {
buildPlug = name: grammars: buildVimPlugin {
pname = name;
version = "master";
src = builtins.getAttr name inputs;
Expand All @@ -77,18 +54,29 @@ let
${writeIf (name == "telescope-media-files") telescopeFixupHook}
'';
postPatch = ''
${writeIf (name == "nvim-treesitter") tsPostPatchHook}
${writeIf (name == "nvim-treesitter") (tsPostPatchHook grammars)}
'';
};

vimPlugins = {
inherit (pkgs.vimPlugins) nerdcommenter;
};
in
{
rec {
# override at use site with your own preferences
treesitterGrammars = t: t.withPlugins (p: [
p.tree-sitter-scala
p.tree-sitter-nix
p.tree-sitter-elm
p.tree-sitter-haskell
p.tree-sitter-markdown
p.tree-sitter-markdown-inline
]);

neovimPlugins =
let
xs = listToAttrs (map (n: nameValuePair n (buildPlug n)) plugins);
tg = treesitterGrammars ts;
xs = listToAttrs (map (n: nameValuePair n (buildPlug n tg)) plugins);
in
xs // vimPlugins;
}

0 comments on commit 84ad578

Please sign in to comment.