3 ms·
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
by aidos 4y ago
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.
- lordgroff 4y agoI didn't even know you could do that, this is why I come to this site.
- aidos 4y agoIf 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.