From 60a607d33f1c50acd0a4218da32abe35b2941e38 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 24 Jan 2019 17:54:18 +0300 Subject: new struct id --- crates/ra_ide_api/src/completion/complete_dot.rs | 33 +++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 32fd497be..1a2b0b2f6 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{Ty, Def}; +use hir::{Ty, Def, AdtDef}; use crate::completion::{CompletionContext, Completions, CompletionItem, CompletionItemKind}; use crate::completion::completion_item::CompletionKind; @@ -28,21 +28,24 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) Ty::Adt { def_id, ref substs, .. } => { - match def_id.resolve(ctx.db) { - Def::Struct(s) => { - for field in s.fields(ctx.db) { - CompletionItem::new( - CompletionKind::Reference, - ctx.source_range(), - field.name().to_string(), - ) - .kind(CompletionItemKind::Field) - .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string())) - .add_to(acc); + match def_id { + AdtDef::Struct() => {} + AdtDef::Def(def_id) => match def_id.resolve(ctx.db) { + Def::Struct(s) => { + for field in s.fields(ctx.db) { + CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + field.name().to_string(), + ) + .kind(CompletionItemKind::Field) + .set_detail(field.ty(ctx.db).map(|ty| ty.subst(substs).to_string())) + .add_to(acc); + } } - } - // TODO unions - _ => {} + // TODO unions + _ => {} + }, } } Ty::Tuple(fields) => { -- cgit v1.2.3