Adding a new tree sitter parser to neovim

I’d like to add an unpackaged tree-sitter parser for justfiles for use in neovim.

One way that might work would be forking nixpkgs, adding the new parser to this file, run this script which I think will generate the right nix files, and I can then install it from my forked nixpkgs.

While this has the advantage of being able to open a PR in future (which I would like to eventually), but I don’t know the quality of the justfile parser, and would like a less involved way to try it out first.

Is there an easier way to add an arbitrary TS parser to neovim config?

For reference my neovim config is defined here GitHub - jay-aye-see-kay/neovim-flake: Neovim Config with flake

I figured it out, posting in the hope it helps someone else. Build the grammar with tree-sitter.buildGrammar and append it to your list of nvim-treesitter grammars (in my config I use nvim-treesitter.allGrammars).

{
  # in your neovim config
  plugins = with pkgs.vimPlugins; [
    # ... your other plugins
    (nvim-treesitter.withPlugins (_: nvim-treesitter.allGrammars ++ [
      (pkgs.tree-sitter.buildGrammar {
        language = "just";
        version = "8af0aab";
        src = pkgs.fetchFromGitHub {
          owner = "IndianBoy42";
          repo = "tree-sitter-just";
          rev = "8af0aab79854aaf25b620a52c39485849922f766";
          sha256 = "sha256-hYKFidN3LHJg2NLM1EiJFki+0nqi1URnoLLPknUbFJY=";
        };
      })
    ]))
  ];
}
6 Likes