-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Syntax highlighting in macros like println!
and format_args!
is awesome! Unfortunately, it doesn't seem to work with tracing
macros as I would expect it to, since the expansion appears to use format_args!
similarly to other cases. Example:
So far, I have not been able to reproduce this using my own macro definition, and the upstream tracing::event
has a fairly big + complicated definition, but one match arm does use format_args!
and the expansion contains this:
Some(
&(unsafe {
std::fmt::Arguments::new_v1(
&[],
&[std::fmt::ArgumentV1::new(
&("not highlighted"),
std::fmt::Display::fmt,
)],
)
}) as &Value,
),
Please let me know if there's anything I can do to help track down why this expansion doesn't match the criteria for highlighting. Thanks!
rust-analyzer version: rust-analyzer version: 84be2ea 2022-05-23 stable
rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18)
relevant settings: None that I know of
Activity
ian-h-chamberlain commentedon Sep 14, 2023
I know this issue hasn't seen much movement since I first filed it, but I had some renewed interest after seeing #15559 in the recent weekly changelog. Good news: I was able to find a minimum viable reproduction! Using
0.3.1657-standalone
(326f37e 2023-09-10) this time.When
format_args!
is last in the expansion, highlighting works as expected. Whennothing!
is last, highlighting is disabled. It seems that the highlight logic is based on whichever expansion is encountered most recently while traversing.I'm not sure if this is really supported, since of course macros can do whatever they want with the literal, but I'd suggest that usually, if any part of the expansion is
format_args!($lit)
it is probably safe to assume the macro is intended to be used this way. Maybe the logic could be updated to turn on highlighting in this scenario? It seems this might affect other highlight use cases though so might be a bigger change than just forformat_args!
.Veykril commentedon Sep 14, 2023
Yes, syntax highlighting currently only looks at the first (as in iteration order) mapping it encounters for performance reasons. That might change in the future as we are rewriting some of the mapping stuff soon.
SE2Dev commentedon Dec 7, 2023
Just out of curiosity, which PR / commit fixed this issue? Was it #16027?
I did confirm that the current pre-release version of
rust-lang.rust-analyzer
(v0.4.1760
) does seem to fix this issue.Edit: The stable version of
rust-lang.rust-analyzer
(v0.3.1766
) now includes the fix!Veykril commentedon Dec 7, 2023
Yes, 9b7ec5e specifically