Fork me on GitHub

Folks, does anyone uses NeoVim with tree-sitter? I can't make it work...

Noah Bogart05:01:26

I do. I use and then use TSInstall clojure and it works great. I run TSUpdate every month or so just in case.


Ok... it's weird, but it indeed was working. The thing is, I was testing with Ruby code, and highlighting Ruby got worse and it's also not consistent on what tree-sitter highlight does 😅

😂 2

Each language defines it's own grammar. The grammar has nodes which can be picked up by the queries. In tree-sitter-clojure the query

(num_lit) @number
will pick up any num_lit type node and bind them to the name @number If that were used by some kind of syntax highlighting system, it run that query on an entire document, and get all the number tokens in the document, along with there positions. The syntax highlighting could then use those nodes and there positions to apply the number font color to every token.


A more complicated query for picking up keywords

(kwd_lit (kwd_ns) @ns
         delimiter: (_) @delimit
         (kwd_name) @name)
This will match different parts of a keyword to the names ns delimit and name . These are matched against the nodes that tree-sitter-clojure defines named kwd_ns and kwd_name. There is also a field named delimiter defined by tree-sitter-clojure that is matched. In a document containing only the keyword :clojure.core/my-keyword @ns is bound to clojure.core @delimit is bound to / @name is bound to my-keyword The names starting with @ are arbitrary names that you choose to bind results to. Most editors using tree-sitter will specify what capture names will apply what types of highlighting. But for the purposes of just playing with tree-sitter and querying the document it doesn't matter.