This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-29
Channels
- # babashka (4)
- # babashka-sci-dev (96)
- # beginners (79)
- # calva (26)
- # cider (5)
- # clerk (2)
- # clj-kondo (23)
- # clojars (14)
- # clojure (54)
- # clojure-europe (8)
- # clojure-sweden (3)
- # clojurescript (76)
- # datomic (12)
- # deps-new (6)
- # emacs (20)
- # events (3)
- # exercism (1)
- # fulcro (11)
- # funcool (12)
- # hugsql (14)
- # hyperfiddle (6)
- # kaocha (1)
- # lambdaisland (1)
- # lsp (22)
- # malli (1)
- # matcher-combinators (6)
- # nbb (6)
- # off-topic (128)
- # polylith (14)
- # re-frame (4)
- # reagent (1)
- # releases (4)
- # shadow-cljs (8)
- # tools-build (13)
- # tools-deps (13)
- # tree-sitter (5)
Folks, does anyone uses NeoVim with tree-sitter? I can't make it work...
I do. I use https://github.com/nvim-treesitter/nvim-treesitter 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.