Issues with tree-sitter not highlighting syntax

Hi All,

I recently started working on a little extension to get into Nova. I managed to find a pre-existing tree-sitter implementation here which is also being used by Neovim. However when I try implement this in Nova it doesn’t highlight anything other than brackets haha! I am certain it is something that I am doing but I haven’t been able to work it out. If I am honest tree-sitter confuses the heck out of me!

My extension repo is nova-cue.

Any advice would be amazingly appreciated!!

You’ll need to provide a file that defines how syntax highlighting works for the language (Documentation).

Most tree-sitter grammars ship with an example highlights file, and it looks like Cue has one. This isn’t a drop in solution for Nova, as every editor that uses Tree-sitter implements different highlighting selectors, but it should hopefully give a good place to start with the documentation above!

Thanks so much @Logan , took me a while to get back to this haha! Now I am remembering why, the whole writing queries part makes very little sense to me. I don’t suppose there is any good tutorials that explain the concepts etc, I find the documentation not the most clear, especially as this is the first time that I’ve worked with tree-sitter.

As an example when defining the Symbols , with Icarus as an example:

; Structs, enums, and classes
  declaration_kind: "struct"
  name: (type_identifier) @name
  (#set! role struct)
) @subtree

How do you identify the class_declaration is the correct thing to use here?

The main extension I am trying to write the Tree-sitter stuff for is my Terraform one.

@BrendanThompson I think Terraform has a tree-sitter on github already, and I suspect you are using that one to port to Nova?

If I were in your shoes, I would generate the parser’s .dylib using the guider provided by Nova’s API Documentation then copy all the highlights.scm from the link above into the Queries folder in your Nova extension.

Your next step is to replace all selectors by Nova specific ones. Use the provided link by @logan above for the example of how it is done.

That should sort of work out of box without you needing to get your hands dirty. BUT if you want to dig and make up your own:

  • Once the .dylib generated and your Syntax definition all set

  • I would just activate the project to make sure all is working without any .scm

  • Then you could use the inspector to inspect a specific node by hovering over the node of interest (it is not AST tree but at least tells you whereabouts tree that node is). For example when you hover over a function name you should get the node

  • Now use that data and gradually build your .scm by making up your capture nodes. The Query language docs used by tree-sitter is here, this will be your friend (I know the docs are terrible and so unorganised there :sweat_smile:)

  • Then use predicates and the theming selector provided by Nova to make Nova specific .scm

  • You do not need to reactivate your extension you should see the updates take place live, as you change anything in your extension, including the .scm file.

  • Also make sure you have the developers console up, it actually gives you helpful errors sometimes, including the .scm syntax error

So the query lang used is the same as all other tree-sitter editors, it is just the predicates and selectors that are different for Nova, as well as location of the .scm files :+1: