Announcing tree-sitter-nix

I recently did some work to improve highlighting in helix:
https://github.com/helix-editor/helix/pull/3697
https://github.com/helix-editor/helix/pull/3594/commits

You could probably steal the highlighting queries for other editors.

Also included some upstream work:
https://github.com/cstrahan/tree-sitter-nix/pull/33
https://github.com/cstrahan/tree-sitter-nix/pull/31

If you wanted to just testdrive everything here you could build my forked branch:
nix build github:nrdxp/helix/fork

2 Likes

Can this be used to evaluate a flake output and generate a nix file of the result?

Tree-sitter is just a parser, so it can’t do any evaulation, but it can generate either an AST or CST for you. I think Toros would be the program that aspires to eventually evaluate Nix code.

Actually, I was thinking it might be useful to use NixEL (the grammar used by Toros) to generate the tree-sitter grammar, so that various tooling (an LSP, editor highlighing, etc) can have a single source of truth for a Nix grammar. Not sure if that’s feasible though. cc @kamadorueda

1 Like

Hey @cstrahan, I’d like to integrate tree-sitter-nix into ast-grep. I think this might involve making a 0.0.2 release. Would you be open to that?