Skip to content

Commit 6b99a09

Browse files
CobaltCausethomasskk
authored andcommitted
Highlight SQL in sqlx::{query,query_as}!() in Rust (helix-editor#3647)
1 parent 45d3e1e commit 6b99a09

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

runtime/queries/rust/injections.scm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,30 @@
2424
name: (identifier) @_new (#eq? @_new "new"))
2525
arguments: (arguments (raw_string_literal) @injection.content)
2626
(#set! injection.language "regex"))
27+
28+
; Highlight SQL in `sqlx::query!()`
29+
(macro_invocation
30+
macro: (scoped_identifier
31+
path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
32+
name: (identifier) @_query (#eq? @_query "query"))
33+
(token_tree
34+
; Only the first argument is SQL
35+
.
36+
[(string_literal) (raw_string_literal)] @injection.content
37+
)
38+
(#set! injection.language "sql"))
39+
40+
; Highlight SQL in `sqlx::query_as!()`
41+
(macro_invocation
42+
macro: (scoped_identifier
43+
path: (identifier) @_sqlx (#eq? @_sqlx "sqlx")
44+
name: (identifier) @_query_as (#eq? @_query_as "query_as"))
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"))

0 commit comments

Comments
 (0)