on master help sign in
Highlight sqlx's `query_scalar{,_unchecked}` macros as SQL (#6793)
6dd5054Cole Helbling
runtime/queries/rust/injections.scm+4−31
@@ -25,11 +25,11 @@
25 arguments: (arguments (raw_string_literal) @injection.content)
25 arguments: (arguments (raw_string_literal) @injection.content)
26 (#set! injection.language "regex"))
26 (#set! injection.language "regex"))
27
27
28−; Highlight SQL in `sqlx::query!()`
28+; Highlight SQL in `sqlx::query!()`, `sqlx::query_scalar!()`, and `sqlx::query_scalar_unchecked!()`
29(macro_invocation
29(macro_invocation
30 macro: (scoped_identifier
30 macro: (scoped_identifier
31 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
31 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
32− name: (identifier) @_query (#eq? @_query "query"))
32+ name: (identifier) @_query (#match? @_query "^query(_scalar|_scalar_unchecked)?$"))
33 (token_tree
33 (token_tree
34 ; Only the first argument is SQL
34 ; Only the first argument is SQL
35 .
35 .
@@ -37,38 +37,11 @@
37 )
37 )
38 (#set! injection.language "sql"))
38 (#set! injection.language "sql"))
39
39
40−; Highlight SQL in `sqlx::query_as!()`
40+; Highlight SQL in `sqlx::query_as!()` and `sqlx::query_as_unchecked!()`
41(macro_invocation
41(macro_invocation
42 macro: (scoped_identifier
42 macro: (scoped_identifier
43 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
43 path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
44− name: (identifier) @_query_as (#eq? @_query_as "query_as"))
44+ name: (identifier) @_query_as (#match? @_query_as "^query_as(_unchecked)?$"))
45− (token_tree
46− ; Only the second argument is SQL
47− .
48− ; Allow anything as the first argument in case the user has lower case type
49− ; names for some reason
50− (_)
51− [(string_literal) (raw_string_literal)] @injection.content
52− )
53− (#set! injection.language "sql"))
54−
55−; Highlight SQL in `sqlx::query_unchecked!()`
56−(macro_invocation
57− macro: (scoped_identifier
58− path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
59− name: (identifier) @_query_as (#eq? @_query_as "query_unchecked"))
60− (token_tree
61− ; Only the first argument is SQL
62− .
63− [(string_literal) (raw_string_literal)] @injection.content
64− )
65− (#set! injection.language "sql"))
66−
67−; Highlight SQL in `sqlx::query_as_unchecked!()`
68−(macro_invocation
69− macro: (scoped_identifier
70− path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
71− name: (identifier) @_query_as (#eq? @_query_as "query_as_unchecked"))
72 (token_tree
45 (token_tree
73 ; Only the second argument is SQL
46 ; Only the second argument is SQL
74 .
47 .