Re:Vim After 15 Years
by aidos on Wednesday October 26, 2022 @07:27PM
(#33351001)
Treesitter is amazing. We have a bunch of sql strings in python and I was able to drop a couple of lines into my injections.scm to isolate them and get perfect sql highlighting within my python code.
[ Parent
| on HN ]
I didn't even know you could do that, this is why I come to this site.
If anyone is interested in how it works, here's the whole thing (I'm looking for strings inside a call to a text function, which is how you wrap sql for sqlalchemy).
# queries/python/injections.scm
; inherits: python
((call
function: (identifier) @_func
arguments: (argument_list (string) @sql))
(#eq? @_func "text"))
There's a little nuance here where the thing that treesitter parses includes the """ (or ") at the start / end but because it can recovery from errors I'm not bothering with wrangling the offsets.