tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
338 stars 96 forks source link

feat: Add a content field and element to raw string literals. #201

Closed Natr1x closed 4 months ago

Natr1x commented 9 months ago

This makes it possible to use language injection for this content. Which is useful since this is something that raw string literals are often used for.

A query like the following could for example be used to provide sql highlighting when using sqlx:

; extends
((macro_invocation
   macro: (scoped_identifier
            path: (identifier) @macropath (#eq? @macropath "sqlx")
            name: (identifier) @macroname)
   (token_tree
     (raw_string_literal
       content: (_) @injection.content)))
 (#set! injection.language "sql")
)

Note: I have not ran tree-sitter-cli generate in order to keep the commit smaller for review purposes.

If you are interested in merging this but want me to change or add something (or run that code generation) then I am willing to do so.

mkatychev commented 6 months ago

@Natr1x what else needs to get done for this PR to move out of draft. This would be extremely useful for sql injections and would remove #offset! guesswork.

amaanq commented 4 months ago

reworked it in #220