Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/rust/injections.scm')
-rw-r--r--runtime/queries/rust/injections.scm101
1 files changed, 78 insertions, 23 deletions
diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm
index 0c7cc350..ba58bf36 100644
--- a/runtime/queries/rust/injections.scm
+++ b/runtime/queries/rust/injections.scm
@@ -55,24 +55,14 @@
function: (scoped_identifier
path: (identifier) @_regex (#any-of? @_regex "Regex" "RegexBuilder")
name: (identifier) @_new (#eq? @_new "new"))
- arguments:
- (arguments
- [
- (string_literal (string_content) @injection.content)
- (raw_string_literal (string_content) @injection.content)
- ])
+ arguments: (arguments (raw_string_literal (string_content) @injection.content))
(#set! injection.language "regex"))
(call_expression
function: (scoped_identifier
path: (scoped_identifier (identifier) @_regex (#any-of? @_regex "Regex" "RegexBuilder") .)
name: (identifier) @_new (#eq? @_new "new"))
- arguments:
- (arguments
- [
- (string_literal (string_content) @injection.content)
- (raw_string_literal (string_content) @injection.content)
- ])
+ arguments: (arguments (raw_string_literal (string_content) @injection.content))
(#set! injection.language "regex"))
; Highlight SQL in `sqlx::query!()`, `sqlx::query_scalar!()`, and `sqlx::query_scalar_unchecked!()`
@@ -113,6 +103,8 @@
; the `format_args!` syntax.
;
; This language is injected into a hard-coded set of macros.
+
+; 1st argument is `format_args!`
(
(macro_invocation
macro:
@@ -121,11 +113,13 @@
name: (_) @_macro_name)
(identifier) @_macro_name
]
- (token_tree) @injection.content
+ (token_tree . [
+ (string_literal (string_content) @injection.content)
+ (raw_string_literal (string_content) @injection.content)
+ ]
+ )
)
(#any-of? @_macro_name
- ; 1st argument is `format_args!`
-
; std
"print" "println" "eprint" "eprintln"
"format" "format_args" "todo" "panic"
@@ -146,25 +140,86 @@
"eyre"
; miette
"miette"
+ )
+ (#set! injection.language "rust-format-args")
+ (#set! injection.include-children)
+)
- ; 2nd argument is `format_args!`
-
+; 2nd argument is `format_args!`
+(
+ (macro_invocation
+ macro:
+ [
+ (scoped_identifier
+ name: (_) @_macro_name)
+ (identifier) @_macro_name
+ ]
+ (token_tree
+ . (_)
+ . [
+ (string_literal (string_content) @injection.content)
+ (raw_string_literal (string_content) @injection.content)
+ ]
+ )
+ )
+ (#any-of? @_macro_name
; std
"write" "writeln" "assert" "debug_assert"
; defmt
"expect" "unwrap"
; ratatui
"span"
+ )
+ (#set! injection.language "rust-format-args")
+ (#set! injection.include-children)
+)
- ; 3rd argument is `format_args!`
-
+; 3rd argument is `format_args!`
+(
+ (macro_invocation
+ macro:
+ [
+ (scoped_identifier
+ name: (_) @_macro_name)
+ (identifier) @_macro_name
+ ]
+ (token_tree
+ . (_)
+ . (_)
+ . [
+ (string_literal (string_content) @injection.content)
+ (raw_string_literal (string_content) @injection.content)
+ ]
+ )
+ )
+ (#any-of? @_macro_name
; std
"assert_eq" "debug_assert_eq" "assert_ne" "debug_assert_ne"
+ )
+ (#set! injection.language "rust-format-args")
+ (#set! injection.include-children)
+)
- ; Dioxus's rsx! macro accepts string interpolation in all
- ; strings, across the entire token tree
- "rsx"
+; Dioxus' "rsx!" macro relies heavily on string interpolation as well. The strings can be nested very deeply
+(
+ (macro_invocation
+ macro: [
+ (scoped_identifier
+ name: (_) @_macro_name)
+ (identifier) @_macro_name
+ ]
+ ; TODO: This only captures 1 level of string literals. But in dioxus you can have
+ ; nested string literals. For instance:
+ ;
+ ; rsx! { "{hello} world" }:
+ ; -> (token_tree (string_literal))
+ ; rsx! { div { "{hello} world" } }
+ ; -> (token_tree (token_tree (string_literal)))
+ ; rsx! { div { div { "{hello} world" } } }
+ ; -> (token_tree (token_tree (token_tree (string_literal))))
+ (token_tree (string_literal) @injection.content)
)
- (#set! injection.language "rust-format-args-macro")
+ (#eq? @_macro_name "rsx")
+ (#set! injection.language "rust-format-args")
(#set! injection.include-children)
)