Could Nova's built-in diff syntax be provided as a tree-sitter grammar?

I recently created my second Nova extension, a syntax highlighter for Git commit messages. It’s written as one of the new-style tree-sitter grammars — tree-sitter, I have to say, is a really impressive piece of software, I’m delighted that Nova has adopted it.

Although the Git commit message format isn’t very complicated, one thing that made writing the extension a little more difficult is that it’s actually made up of two grammars: the commit message itself (subject line, message body, trailers) followed by the diff of the file changes (+/- lines etc). Nova comes with diff syntax highlighting built-in, so my first idea was that I could provide the Git commit syntax highlighter as part of my extension (as a compiled tree-sitter grammar), and use Nova’s built-in diff syntax highlighter as an injected language.

Unfortunately this didn’t work, and it took me a while to work out why. After a fun bit of poking around Nova’s app package I realised it’s because Nova’s diff syntax is still an old-school regex grammar. They of course can’t be injected into a tree-sitter grammar, so I had to come up with a plan B.

Next I thought I could just include two compiled tree-sitter grammars in my extension: one for Git commit messages and one for diff syntax. This worked a treat … until I came to add the style, when I realised that none of Nova’s syntax highlighting selectors are suitable for the plus/minus (red/green) style expected for diffs. So, currently, my extension just styles diffs included in Git commit message as comments. But I really want to add diff syntax highlighting to the extension.

Finally, I come to my feature requests! Would it be possible to convert Nova’s built-in diff grammar into a tree-sitter grammar? And/or would it be possible to add theme selectors for “added” and “deleted” styles? And if so, could they default to red/green for third-party themes that don’t include a style for them?

Thanks — and I hope this doesn’t come off as downbeat, because I’m really enjoying using Nova both for writing code developing extensions.

1 Like