1338: Highlight names correctly r=matklad a=lnicola

Part of #1294.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2019-05-29 06:30:48 +00:00
commit b0d84cb8fa
2 changed files with 20 additions and 3 deletions

View file

@ -18,13 +18,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e
.keyword\.control { color: #DC8CC3; }
</style>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
<span class="keyword">struct</span> <span class="function">Foo</span> {
<span class="keyword">struct</span> <span class="type">Foo</span> {
<span class="keyword">pub</span> <span class="function">x</span>: <span class="text">i32</span>,
<span class="keyword">pub</span> <span class="function">y</span>: <span class="text">i32</span>,
}
<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type function">T</span>&gt;() -&gt; <span class="type">T</span> {
<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type type">T</span>&gt;() -&gt; <span class="type">T</span> {
<span class="macro">unimplemented</span><span class="macro">!</span>();
<span class="function">foo</span>::&lt;<span class="type text">i32</span>&gt;();
}
<span class="comment">// comment</span>

View file

@ -1,6 +1,8 @@
use rustc_hash::{FxHashSet, FxHashMap};
use ra_syntax::{ast, AstNode, TextRange, Direction, SmolStr, SyntaxKind, SyntaxKind::*, SyntaxElement, T};
use ra_syntax::{
ast, AstNode, TextRange, Direction, SmolStr, SyntaxKind, SyntaxKind::*, SyntaxElement, T,
};
use ra_db::SourceDatabase;
use ra_prof::profile;
@ -116,6 +118,19 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
calc_binding_hash(file_id, &text, *shadow_count)
});
"variable"
} else if name
.syntax()
.parent()
.map(|x| {
x.kind() == TYPE_PARAM
|| x.kind() == STRUCT_DEF
|| x.kind() == ENUM_DEF
|| x.kind() == TRAIT_DEF
|| x.kind() == TYPE_ALIAS_DEF
})
.unwrap_or(false)
{
"type"
} else {
"function"
}
@ -263,6 +278,7 @@ struct Foo {
fn foo<T>() -> T {
unimplemented!();
foo::<i32>();
}
// comment