Tree Sitter Queries with supersets and `syntax="<subset>"`

I’m currently working with a superset of a language covered by a built in extension. To avoid redundant copies of the tree-sitter dynamic library and queries I looked to existing examples, namely the relationship between Javascript and TSX, and noticed TSX references the Javascript queries by seemingly specifying another syntax and subsequent relative query path. <highlights syntax="javascript" path="javascript/highlights-jsx.scm" />

Near verbatim replication attempts have shown no success with no notable way to debug. Further more the Tree Sitter documentation doesn’t seem to note this functionality anywhere. It appears that a redundant tree-sitter dynamic library is ultimately required for the base syntax, but hoping there may be an alternative.

Third-party extensions cannot reference built-in languages to duplicate behavior, as built-in languages are not packaged as dynamic libraries in the same way, and are not loaded in the same process.

To clarify some of what you’ve found: the built-in TSX grammar is built as its own fully-contained language (it does not use the JavaScript parser). However, the syntax highlighting queries are shared between the two, as the tree-sitter project maintains both languages in tandem and ensures the parser rules are compatible. A different grammar from another source would not necessarily be compatible with the queries for JavaScript and / or TSX, especially if they changed over time in updates to Nova.

Since we can’t predict whether we’d break third-party extensions by modifying our own highlighting queries, third-party extensions are not allowed to reference the built-in ones.

If you are working on building a parser (or integrating a parser) for a language that is a superset of JavaScript, you will need to provide your own parser dynamic library and highlighting queries. You are, of course, welcome to refer to the built-in ones for assistance in building yours (they are in the JavaScript extension, as you’ve found) and copy what pieces might be compatible with the grammar you provide.