Implement beginnings of generics

- add HIR for generic params
 - resolve generic params in type paths
 - add substitions for ADTs
 - insert type variables for substitutions
This commit is contained in:
Florian Diebold 2019-01-12 21:27:35 +01:00
parent 415cdc5210
commit 688a45e00b
13 changed files with 288 additions and 82 deletions

View file

@ -24,7 +24,9 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
for receiver in receiver.autoderef(ctx.db) {
match receiver {
Ty::Adt { def_id, .. } => {
Ty::Adt {
def_id, ref substs, ..
} => {
match def_id.resolve(ctx.db) {
Def::Struct(s) => {
for field in s.fields(ctx.db) {
@ -33,7 +35,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
field.name().to_string(),
)
.kind(CompletionItemKind::Field)
.set_detail(field.ty(ctx.db).map(|ty| ty.to_string()))
.set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string()))
.add_to(acc);
}
}

View file

@ -129,6 +129,7 @@ salsa::database_storage! {
fn body_hir() for hir::db::BodyHirQuery;
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
fn fn_signature() for hir::db::FnSignatureQuery;
fn generics() for hir::db::GenericsQuery;
}
}
}