Add Rust convenience Tree-sitter injections for common crates (#41258)

This commit is contained in:
Cameron Mcloughlin
2025-10-27 19:58:04 +00:00
committed by GitHub
parent ac3d2a338b
commit 00278f43bb
+45 -3
View File
@@ -2,8 +2,10 @@
(#set! injection.language "comment"))
(macro_invocation
macro: [(identifier) (scoped_identifier)] @_macro_name
(#not-any-of? @_macro_name "view" "html")
macro: [
((identifier) @_macro_name)
(scoped_identifier (identifier) @_macro_name .)
]
(token_tree) @injection.content
(#set! injection.language "rust"))
@@ -11,8 +13,48 @@
; it wants to inject inside of rust, instead of modifying the rust
; injections to support leptos injections
(macro_invocation
macro: [(identifier) (scoped_identifier)] @_macro_name
macro: [
((identifier) @_macro_name)
(scoped_identifier (identifier) @_macro_name .)
]
(#any-of? @_macro_name "view" "html")
(token_tree) @injection.content
(#set! injection.language "rstml")
)
(macro_invocation
macro: [
((identifier) @_macro_name)
(scoped_identifier (identifier) @_macro_name .)
]
(#any-of? @_macro_name "sql")
(_) @injection.content
(#set! injection.language "sql")
)
; lazy_regex
(macro_invocation
macro: [
((identifier) @_macro_name)
(scoped_identifier (identifier) @_macro_name .)
]
(token_tree [
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
])
(#set! injection.language "regex")
(#any-of? @_macro_name "regex" "bytes_regex")
)
(call_expression
function: (scoped_identifier) @_fn_path
arguments: (arguments
[
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
]
)
(#match? @_fn_path ".*Regex(Builder)?::new")
(#set! injection.language "regex")
)