Debian Codegraph @

runtime/queries/rust/injections.scm

raw symbols SCIP
1 ([(line_comment !doc) (block_comment !doc)] @injection.content
2 (#set! injection.language "comment"))
3
4 ((doc_comment) @injection.content
5 (#set! injection.language "markdown-rustdoc")
6 (#set! injection.combined))
7
8 ((macro_invocation
9 (token_tree) @injection.content)
10 (#set! injection.language "rust")
11 (#set! injection.include-children))
12
13 ((macro_rule
14 (token_tree) @injection.content)
15 (#set! injection.language "rust")
16 (#set! injection.include-children))
17
18 ((macro_invocation
19 macro:
20 [
21 (scoped_identifier
22 name: (_) @_macro_name)
23 (identifier) @_macro_name
24 ]
25 (token_tree) @injection.content)
26 (#eq? @_macro_name "html")
27 (#set! injection.language "html")
28 (#set! injection.include-children))
29
30 ((macro_invocation
31 macro:
32 [
33 (scoped_identifier
34 name: (_) @_macro_name)
35 (identifier) @_macro_name
36 ]
37 (token_tree) @injection.content)
38 (#eq? @_macro_name "slint")
39 (#set! injection.language "slint")
40 (#set! injection.include-children))
41
42 ((macro_invocation
43 macro:
44 [
45 (scoped_identifier name: (_) @_macro_name)
46 (identifier) @_macro_name
47 ]
48 (token_tree
49 (token_tree . "{" "}" .) @injection.content))
50 (#eq? @_macro_name "json")
51 (#set! injection.language "json")
52 (#set! injection.include-children))
53
54 (call_expression
55 function: (scoped_identifier
56 path: (identifier) @_regex (#any-of? @_regex "Regex" "RegexBuilder")
57 name: (identifier) @_new (#eq? @_new "new"))
58 arguments:
59 (arguments
60 [
61 (string_literal (string_content) @injection.content)
62 (raw_string_literal (string_content) @injection.content)
63 ])
64 (#set! injection.language "regex"))
65
66 (call_expression
67 function: (scoped_identifier
68 path: (scoped_identifier (identifier) @_regex (#any-of? @_regex "Regex" "RegexBuilder") .)
69 name: (identifier) @_new (#eq? @_new "new"))
70 arguments:
71 (arguments
72 [
73 (string_literal (string_content) @injection.content)
74 (raw_string_literal (string_content) @injection.content)
75 ])
76 (#set! injection.language "regex"))
77
78 ; Highlight SQL in `sqlx::query!()`, `sqlx::query_scalar!()`, and `sqlx::query_scalar_unchecked!()`
79 (macro_invocation
80 macro: (scoped_identifier
81 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
82 name: (identifier) @_query (#match? @_query "^query(_scalar|_scalar_unchecked)?$"))
83 (token_tree
84 ; Only the first argument is SQL
85 .
86 [
87 (string_literal (string_content) @injection.content)
88 (raw_string_literal (string_content) @injection.content)
89 ]
90 )
91 (#set! injection.language "sql"))
92
93 ; Highlight SQL in `sqlx::query_as!()` and `sqlx::query_as_unchecked!()`
94 (macro_invocation
95 macro: (scoped_identifier
96 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
97 name: (identifier) @_query_as (#match? @_query_as "^query_as(_unchecked)?$"))
98 (token_tree
99 ; Only the second argument is SQL
100 .
101 ; Allow anything as the first argument in case the user has lower case type
102 ; names for some reason
103 (_)
104 [
105 (string_literal (string_content) @injection.content)
106 (raw_string_literal (string_content) @injection.content)
107 ]
108 )
109 (#set! injection.language "sql"))
110
111 ; Highlight SQL in `sqlx::query*` and `sqlx::raw_sql` functions
112 (call_expression
113 function: (scoped_identifier
114 path: (identifier) @_sqlx
115 (#eq? @_sqlx "sqlx")
116 name: (identifier) @_query_function)
117 (#match? @_query_function "^query.*|raw_sql$")
118 arguments: (arguments
119 .
120 [
121 (string_literal
122 (string_content) @injection.content)
123 (raw_string_literal
124 (string_content) @injection.content)
125 ])
126 (#set! injection.language "sql"))
127
128 ; Special language `tree-sitter-rust-format-args` for Rust macros,
129 ; which use `format_args!` under the hood and therefore have
130 ; the `format_args!` syntax.
131 ;
132 ; This language is injected into a hard-coded set of macros.
133 (
134 (macro_invocation
135 macro:
136 [
137 (scoped_identifier
138 name: (_) @_macro_name)
139 (identifier) @_macro_name
140 ]
141 (token_tree) @injection.content
142 )
143 (#any-of? @_macro_name
144 ; 1st argument is `format_args!`
145
146 ; std
147 "print" "println" "eprint" "eprintln"
148 "format" "format_args" "todo" "panic"
149 "unreachable" "unimplemented" "compile_error"
150 ; log
151 "crit" "trace" "debug" "info" "warn" "error"
152 ; anyhow
153 "anyhow" "bail"
154 ; syn
155 "format_ident"
156 ; indoc
157 "formatdoc" "printdoc" "eprintdoc" "writedoc"
158 ; iced
159 "text"
160 ; ratatui
161 "span"
162 ; eyre
163 "eyre"
164 ; miette
165 "miette"
166
167 ; 2nd argument is `format_args!`
168
169 ; std
170 "write" "writeln" "assert" "debug_assert"
171 ; defmt
172 "expect" "unwrap"
173 ; ratatui
174 "span"
175
176 ; 3rd argument is `format_args!`
177
178 ; std
179 "assert_eq" "debug_assert_eq" "assert_ne" "debug_assert_ne"
180
181 ; Dioxus's rsx! macro accepts string interpolation in all
182 ; strings, across the entire token tree
183 "rsx"
184 )
185 (#set! injection.language "rust-format-args-macro")
186 (#set! injection.include-children)
187 )
188
189 ; for some queries (e.g. when you have generic table names) you need to wrap it in `AssertSqlSafe`
190 ; after `format!` so it can overwrite `format!` formatting correctly.
191 (call_expression
192 function: [
193 (scoped_identifier
194 path: (identifier) @_sqlx
195 (#eq? @_sqlx "sqlx")
196 name: (identifier) @_AssertSqlSafe)
197 (identifier) @_AssertSqlSafe
198 ]
199 (#eq? @_AssertSqlSafe "AssertSqlSafe")
200 arguments: (arguments
201 [
202 (string_literal
203 (string_content) @injection.content)
204 (raw_string_literal
205 (string_content) @injection.content)
206 (macro_invocation
207 macro: (identifier) @_format
208 (#eq? @_format "format")
209 (token_tree
210 [
211 (string_literal
212 (string_content) @injection.content)
213 (raw_string_literal
214 (string_content) @injection.content)
215 ]))
216 ])
217 (#set! injection.language "sql"))