I'm using treesitter inside neovim, for all of the awesome reasons we already know.
My (legacy) code has a lot of SQL statements in PHP strings. Using TS I've got it to recognise SQL inside PHP strings and then get various groups identifying and highlighting nicely, e.g. @keyword.sql, @variable.parameter.sql.
But the only thing that last one matches (that I've noticed so far) is ? - which is great when I'm using that sort of placeholder, but a lot of queries use :myParam etc instead...
Using :Inspect I can see on :myParam that the colon is still just @string.php, while the rest of it is @variable.member.sql.
I want to nicely highlight :myParam in its entirety. At the moment I can only highlight myParam, and only the same as all the other @variable.member.sql, which appears to be (at least) column names.
I spent ages with ChatGPT trying to work through this, and nothing it suggested worked. In the end we ("we"... FML) decided to use a regex rule outside of TS to find such placeholders and apply a new highlighting group to them... which works GREAT... except TreeSitter reapplies its syntax CONSTANTLY, so immediately overwrites the colours 🤦♂️
(I know it's working as my bg colour that I set this way doesn't get overwritten, as my TS highlight groups are only set to change the fg colour)
So............... back to the drawing board. How can I configure TS to recognise these placeholders?
AFAICS, the issue is that :myParam isn't actually valid SQL code. It's a PDO thing. So where do I go from here?
Thank you!
DB::getQuery('SELECT foo FROM bar WHERE id = :bar_id', ['bar_id' => $barId]);I'd like:bar_idto be targetable for syntax highlighting.:bar_idis a valid SQL token.:bar_idisn't part of SQL, it's part of PDO. But in nvim land anything is possible with lua etc, so I feel there must be a way to do this.