Get the right analyzer for impls

This commit is contained in:
Aleksey Kladov 2019-12-07 20:05:08 +01:00
parent 7d2080a031
commit f4f8b81474
4 changed files with 23 additions and 2 deletions

View file

@ -37,7 +37,7 @@ use crate::{
InEnvironment, TraitEnvironment, Ty,
},
Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam,
Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
ImplBlock, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias,
};
fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
@ -59,6 +59,10 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -
let src = node.with_value(it);
Some(Enum::from_source(db, src)?.id.resolver(db))
},
ast::ImplBlock(it) => {
let src = node.with_value(it);
Some(ImplBlock::from_source(db, src)?.id.resolver(db))
},
_ => match node.value.kind() {
FN_DEF | CONST_DEF | STATIC_DEF => {
let def = def_with_body_from_child_node(db, node)?;

View file

@ -178,7 +178,6 @@ pub(crate) fn classify_name_ref(
Some(NameDefinition { kind, container, visibility: None })
}
PathResolution::GenericParam(par) => {
// FIXME: get generic param def
let kind = NameKind::GenericParam(par);
Some(NameDefinition { kind, container, visibility })
}

View file

@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.parameter { color: #94BFF3; }
.builtin { color: #DD6718; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.attribute { color: #94BFF3; }
.literal { color: #BFEBBF; }
.macro { color: #94BFF3; }
@ -45,4 +46,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>;
<span class="variable.mut">y</span>;
}
<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type">X</span>&gt; {
<span class="constant">V</span>(<span class="type">X</span>)
}
<span class="keyword">impl</span>&lt;<span class="type">X</span>&gt; <span class="type">E</span>&lt;<span class="type">X</span>&gt; {
<span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type">T</span>&gt;() -&gt; <span class="type">E</span>&lt;<span class="type">T</span>&gt; {}
}</code></pre>

View file

@ -255,6 +255,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.parameter { color: #94BFF3; }
.builtin { color: #DD6718; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.attribute { color: #94BFF3; }
.literal { color: #BFEBBF; }
.macro { color: #94BFF3; }
@ -303,6 +304,14 @@ fn main() {
y;
}
enum E<X> {
V(X)
}
impl<X> E<X> {
fn new<T>() -> E<T> {}
}
"#
.trim(),
);