mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Fix syntax highlighting of recursive macros
Add syntax highlighting for the BANG (`!`) token if the parent is `MACRO_CALL`.
This commit is contained in:
parent
017331a53c
commit
06f89e5f3a
3 changed files with 37 additions and 16 deletions
|
@ -62,6 +62,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
}
|
||||
}
|
||||
|
||||
<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
|
||||
($expr:expr) => {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
|
||||
<span class="comment">// comment</span>
|
||||
<span class="keyword">fn</span> <span class="function declaration">main</span>() {
|
||||
<span class="macro">println!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
|
||||
|
@ -80,6 +86,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||
<span class="comment">// Do nothing</span>
|
||||
}
|
||||
|
||||
<span class="macro">noop!</span>(<span class="macro">noop</span><span class="macro">!</span>(<span class="numeric_literal">1</span>));
|
||||
|
||||
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable">x</span> = <span class="numeric_literal">42</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
|
||||
<span class="keyword">let</span> <span class="variable declaration">z</span> = &<span class="variable mutable">y</span>;
|
||||
|
|
|
@ -160,9 +160,12 @@ pub(crate) fn highlight(
|
|||
// Check if macro takes a format string and remember it for highlighting later.
|
||||
// The macros that accept a format string expand to a compiler builtin macros
|
||||
// `format_args` and `format_args_nl`.
|
||||
if let Some(fmt_macro_call) = parent.parent().and_then(ast::MacroCall::cast) {
|
||||
if let Some(name) =
|
||||
fmt_macro_call.path().and_then(|p| p.segment()).and_then(|s| s.name_ref())
|
||||
if let Some(name) = parent
|
||||
.parent()
|
||||
.and_then(ast::MacroCall::cast)
|
||||
.and_then(|mc| mc.path())
|
||||
.and_then(|p| p.segment())
|
||||
.and_then(|s| s.name_ref())
|
||||
{
|
||||
match name.text().as_str() {
|
||||
"format_args" | "format_args_nl" => {
|
||||
|
@ -178,7 +181,6 @@ pub(crate) fn highlight(
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We only care Name and Name_ref
|
||||
match (token.kind(), parent.kind()) {
|
||||
|
@ -493,6 +495,9 @@ fn highlight_element(
|
|||
h |= HighlightModifier::Unsafe;
|
||||
h
|
||||
}
|
||||
T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
|
||||
Highlight::new(HighlightTag::Macro)
|
||||
}
|
||||
|
||||
k if k.is_keyword() => {
|
||||
let h = Highlight::new(HighlightTag::Keyword);
|
||||
|
|
|
@ -43,6 +43,12 @@ def_fn! {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! noop {
|
||||
($expr:expr) => {
|
||||
$expr
|
||||
}
|
||||
}
|
||||
|
||||
// comment
|
||||
fn main() {
|
||||
println!("Hello, {}!", 92);
|
||||
|
@ -61,6 +67,8 @@ fn main() {
|
|||
// Do nothing
|
||||
}
|
||||
|
||||
noop!(noop!(1));
|
||||
|
||||
let mut x = 42;
|
||||
let y = &mut x;
|
||||
let z = &y;
|
||||
|
|
Loading…
Reference in a new issue