mirror of
https://github.com/helix-editor/helix
synced 2026-01-26 05:38:09 +01:00
This is a bit hacky. Injections cannot stack on each other like
highlights because layers can have their own injections. So this new
language `rust-format-args-macro` emulates that. It unconditionally
injects `rust-format-args` into all strings. Rust injects this new
language into known format-args macros like `println!`.
The downside is that this can cause false-positive highlights within
these macros for strings which happen to contain format-args syntax
println!("Hello, {}!", "{}");
// ^ format args syntax
// ^ not format args syntax, but highlighted
// as if it were :(
This false-positive case is expected to be rare.
Injecting this fake language fixes regular non-string highlights in
macro invocations: macro invocations need to inject the entire token
tree and use `injection.include-children` for proper highlighting.
14 lines
471 B
Scheme
14 lines
471 B
Scheme
; inherits: rust
|
|
|
|
; HACK: This language is the same as Rust but all strings are injected
|
|
; with rust-format-args. Rust injects this into known macros which use
|
|
; the format args syntax. This can cause false-positive highlights but
|
|
; those are expected to be rare.
|
|
|
|
([
|
|
(string_literal (string_content) @injection.content)
|
|
(raw_string_literal (string_content) @injection.content)
|
|
]
|
|
(#set! injection.language "rust-format-args")
|
|
(#set! injection.include-children))
|