Color for as a regular keyword when it's part of impl _ for _

This commit is contained in:
George Fraser 2020-05-10 11:26:19 -07:00
parent 3f1c73633e
commit 63b75a40c8
3 changed files with 28 additions and 1 deletions

View file

@ -33,6 +33,16 @@ 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">trait</span> <span class="trait declaration">Bar</span> {
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -&gt; <span class="builtin_type">i32</span>;
}
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> {
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -&gt; <span class="builtin_type">i32</span> {
<span class="keyword">self</span>.<span class="field">x</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> {

View file

@ -403,13 +403,13 @@ fn highlight_element(
T![break]
| T![continue]
| T![else]
| T![for]
| T![if]
| T![loop]
| T![match]
| T![return]
| T![while]
| T![in] => h | HighlightModifier::ControlFlow,
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
T![unsafe] => h | HighlightModifier::Unsafe,
_ => h,
}
@ -433,6 +433,13 @@ fn highlight_element(
}
}
fn is_child_of_impl(element: SyntaxElement) -> bool {
match element.parent() {
Some(e) => e.kind() == IMPL_DEF,
_ => false,
}
}
fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
match def {
Definition::Macro(_) => HighlightTag::Macro,

View file

@ -17,6 +17,16 @@ struct Foo {
pub y: i32,
}
trait Bar {
fn bar(&self) -> i32;
}
impl Bar for Foo {
fn bar(&self) -> i32 {
self.x
}
}
static mut STATIC_MUT: i32 = 0;
fn foo<'a, T>() -> T {