Reproduction steps
- Start Zed with Rust syntax highlighting, Semantic Tokens OFF.
- Type in a valid arbitrary custom macro invocation: e.g.,
foo! { bar- <b"none"> }
- Tokens are not highlighted correctly (particularly the string literal)
Current vs. Expected behavior
Currently Zed treats syntax highlighting within a Rust macro as Rust code with hard-coded exceptions for view!, html! and now bsn!. These hard-coded exceptions are good for special cases, but for all other macros, syntax should be highlighted generically that won't break whatever syntax a programmer may come up with in a macro.
In a general sense, it is okay to highlight the innards of a macro invocation loosely as Rust, such for key words like let and while, known literals and identifiers, but treating it strictly as Rust leads to inconsistent highlighting issues. These can be fixed as follows:
- Keep all PUNCT tokens (
@!#.,<>?/ etc.) the same color/style (< does not need a corresponding > in macros and may be grouped with any other PUNCT, e.g., Brainfuck)
a. ()[]{} can remain styled differently because they are required to enclose each other.
b. A literal immediately preceding ! can remain a unique color to look like an inner_macro! invocation
c. A literal immediately preceding ( can remain a unique color to look like a function call
- Allow PUNCT tokens directly next to string literals without breaking the highlighting: e.g.,
<c"cstring", <"foo"
b and c do NOT signify c-string/bytestrings if part of a literal, i.e., 123c"foo" tokenizes as 123c followed by "foo"
(Zed currently highlights 123c"foo" incorrectly, with colors separated at 123 and c"foo")
If the above points are fixed, then Rust code written inside of macros will continue to look like Rust code highlighting, while also allowing developers to create any arbitrary custom macros without immediately breaking the highlighting.
Current
Expected
(VS Code handles this perfectly)
Zed version and system specs
Zed 0.227.1
9f9b707
0.227.1+stable.199.9f9b707d39d62468d4cdaed2d8eb95a847da4cf9
Windows 11/macOS Tahoe 26.3.1
Reproduction steps
foo! { bar- <b"none"> }Current vs. Expected behavior
Currently Zed treats syntax highlighting within a Rust macro as Rust code with hard-coded exceptions for
view!,html!and nowbsn!. These hard-coded exceptions are good for special cases, but for all other macros, syntax should be highlighted generically that won't break whatever syntax a programmer may come up with in a macro.In a general sense, it is okay to highlight the innards of a macro invocation loosely as Rust, such for key words like
letandwhile, known literals and identifiers, but treating it strictly as Rust leads to inconsistent highlighting issues. These can be fixed as follows:@!#.,<>?/etc.) the same color/style (<does not need a corresponding>in macros and may be grouped with any other PUNCT, e.g., Brainfuck)a.
()[]{}can remain styled differently because they are required to enclose each other.b. A literal immediately preceding
!can remain a unique color to look like aninner_macro!invocationc. A literal immediately preceding
(can remain a unique color to look like a function call<c"cstring",<"foo"bandcdo NOT signify c-string/bytestrings if part of a literal, i.e.,123c"foo"tokenizes as123cfollowed by"foo"(Zed currently highlights
123c"foo"incorrectly, with colors separated at123andc"foo")If the above points are fixed, then Rust code written inside of macros will continue to look like Rust code highlighting, while also allowing developers to create any arbitrary custom macros without immediately breaking the highlighting.
Current
Expected
(VS Code handles this perfectly)
Zed version and system specs
Zed 0.227.1
9f9b707
0.227.1+stable.199.9f9b707d39d62468d4cdaed2d8eb95a847da4cf9
Windows 11/macOS Tahoe 26.3.1