From 56b2138d82620db946fe08ddc164c5e7e22be625 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Jan 2019 18:46:02 +0300 Subject: show field types in completion --- crates/ra_ide_api/src/completion/complete_dot.rs | 14 +++++++------- crates/ra_ide_api/src/completion/completion_item.rs | 11 +++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide_api/src/completion') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 5d4e60dc5..65bba6dc7 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -28,13 +28,13 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) Ty::Adt { def_id, .. } => { match def_id.resolve(ctx.db)? { Def::Struct(s) => { - let variant_data = s.variant_data(ctx.db)?; - for field in variant_data.fields() { + for field in s.fields(ctx.db)? { CompletionItem::new( CompletionKind::Reference, field.name().to_string(), ) .kind(CompletionItemKind::Field) + .set_detail(field.ty(ctx.db)?.map(|ty| ty.to_string())) .add_to(acc); } } @@ -72,7 +72,7 @@ mod tests { a.<|> } ", - r#"the_field"#, + r#"the_field "u32""#, ); } @@ -80,14 +80,14 @@ mod tests { fn test_struct_field_completion_self() { check_ref_completion( r" - struct A { the_field: u32 } + struct A { the_field: (u32,) } impl A { fn foo(self) { self.<|> } } ", - r#"the_field"#, + r#"the_field "(u32,)""#, ); } @@ -95,14 +95,14 @@ mod tests { fn test_struct_field_completion_autoderef() { check_ref_completion( r" - struct A { the_field: u32 } + struct A { the_field: (u32, i32) } impl A { fn foo(&self) { self.<|> } } ", - r#"the_field"#, + r#"the_field "(u32, i32)""#, ); } diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index d707a84ef..334449fae 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -126,8 +126,12 @@ impl Builder { self.kind = Some(kind); self } - pub(crate) fn detail(mut self, detail: impl Into) -> Builder { - self.detail = Some(detail.into()); + #[allow(unused)] + pub(crate) fn detail(self, detail: impl Into) -> Builder { + self.set_detail(Some(detail)) + } + pub(crate) fn set_detail(mut self, detail: Option>) -> Builder { + self.detail = detail.map(Into::into); self } pub(super) fn from_resolution( @@ -239,6 +243,9 @@ impl Completions { } else { res.push_str(&c.label); } + if let Some(detail) = &c.detail { + res.push_str(&format!(" {:?}", detail)); + } if let Some(snippet) = &c.snippet { res.push_str(&format!(" {:?}", snippet)); } -- cgit v1.2.3