Highlight the name in macro declarations

This commit is contained in:
Matthew Jasper 2020-05-10 16:08:54 +01:00
parent 11c0a5bb60
commit 22b75c4cea
3 changed files with 18 additions and 3 deletions

View file

@ -27,13 +27,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
</style>
<pre><code><span class="macro">macro_rules!</span> println {
<pre><code><span class="macro">macro_rules!</span> <span class="macro declaration">println</span> {
($($arg:tt)*) =&gt; ({
$<span class="keyword">crate</span>::io::_print($<span class="keyword">crate</span>::format_args_nl!($($arg)*));
})
}
#[rustc_builtin_macro]
<span class="macro">macro_rules!</span> format_args_nl {
<span class="macro">macro_rules!</span> <span class="macro declaration">format_args_nl</span> {
($fmt:expr) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
($fmt:expr, $($args:tt)*) =&gt; {{ <span class="comment">/* compiler built-in */</span> }};
}

View file

@ -33,11 +33,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
}
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable">STATIC_MUT</span>: <span class="builtin_type">i32</span> = <span class="numeric_literal">0</span>;
<span class="keyword">fn</span> <span class="function declaration">foo</span>&lt;<span class="lifetime declaration">'a</span>, <span class="type_param declaration">T</span>&gt;() -&gt; <span class="type_param">T</span> {
<span class="function">foo</span>::&lt;<span class="lifetime">'a</span>, <span class="builtin_type">i32</span>&gt;()
}
<span class="macro">macro_rules!</span> def_fn {
<span class="macro">macro_rules!</span> <span class="macro declaration">def_fn</span> {
($($tt:tt)*) =&gt; {$($tt)*}
}

View file

@ -167,6 +167,19 @@ pub(crate) fn highlight(
binding_hash: None,
});
}
if let Some(name) = mc.is_macro_rules() {
if let Some((highlight, binding_hash)) = highlight_element(
&sema,
&mut bindings_shadow_count,
name.syntax().clone().into(),
) {
stack.add(HighlightedRange {
range: name.syntax().text_range(),
highlight,
binding_hash,
});
}
}
continue;
}
WalkEvent::Leave(Some(mc)) => {