Syntax Highlighting in Clientside Callbacks Using TreeSitter

New Year, new me + it’s time to start blogging about stuff.

With that said, last year, I found a really nice way to get syntax highlighting working in clientside callbacks using TreeSitter.

You can read my full thoughts here, but the treesitter injection I use is

;extends
; look for calls to functions named clientside_callback
(call 
  (identifier) @name (#eq? @name clientside_callback) 
  (argument_list 
; if the first argument is a string, 
; set the language of the child string_content to javascript
((string (string_content) 
	 @injection.content 
	 (#set! injection.include-children)
	 (#set! injection.language "javascript")))
)
)

Before Injection:

After Injection: