Journal 2022-09-04
Nvim tree-sitter
It’s easy to capture nodes with tree-sitter queries, but when it comes to match the text inside the node it’s complicated doing it with just the queries.
Thankfully nvim
has some built in predicates that can help with it. An
example is how to extract the content of a rust line_comment
and inject the
markdown syntax. We need to ignore the first 3 characters that are not valid
markdown:
((line_comment) @markdown (#offset! @markdown 0 3 0 0))
- Capture the
line_comment
- Mark it as
markdown
code - Use the predicate
offset!
event.FootnoteReference
1
You can find more about built in predicates here
`:h lua-treesitter-predicates`