aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/render.rs')
-rw-r--r--crates/ide_completion/src/render.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 425dd0247..bf59ff57b 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -25,18 +25,20 @@ use crate::{
25 25
26pub(crate) fn render_field<'a>( 26pub(crate) fn render_field<'a>(
27 ctx: RenderContext<'a>, 27 ctx: RenderContext<'a>,
28 receiver: Option<String>,
28 field: hir::Field, 29 field: hir::Field,
29 ty: &hir::Type, 30 ty: &hir::Type,
30) -> CompletionItem { 31) -> CompletionItem {
31 Render::new(ctx).render_field(field, ty) 32 Render::new(ctx).render_field(receiver, field, ty)
32} 33}
33 34
34pub(crate) fn render_tuple_field<'a>( 35pub(crate) fn render_tuple_field<'a>(
35 ctx: RenderContext<'a>, 36 ctx: RenderContext<'a>,
37 receiver: Option<String>,
36 field: usize, 38 field: usize,
37 ty: &hir::Type, 39 ty: &hir::Type,
38) -> CompletionItem { 40) -> CompletionItem {
39 Render::new(ctx).render_tuple_field(field, ty) 41 Render::new(ctx).render_tuple_field(receiver, field, ty)
40} 42}
41 43
42pub(crate) fn render_resolution<'a>( 44pub(crate) fn render_resolution<'a>(
@@ -126,11 +128,19 @@ impl<'a> Render<'a> {
126 Render { ctx } 128 Render { ctx }
127 } 129 }
128 130
129 fn render_field(&self, field: hir::Field, ty: &hir::Type) -> CompletionItem { 131 fn render_field(
132 &self,
133 receiver: Option<String>,
134 field: hir::Field,
135 ty: &hir::Type,
136 ) -> CompletionItem {
130 let is_deprecated = self.ctx.is_deprecated(field); 137 let is_deprecated = self.ctx.is_deprecated(field);
131 let name = field.name(self.ctx.db()).to_string(); 138 let name = field.name(self.ctx.db()).to_string();
132 let mut item = 139 let mut item = CompletionItem::new(
133 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name.clone()); 140 CompletionKind::Reference,
141 self.ctx.source_range(),
142 receiver.map_or_else(|| name.to_string(), |receiver| format!("{}.{}", receiver, name)),
143 );
134 item.kind(SymbolKind::Field) 144 item.kind(SymbolKind::Field)
135 .detail(ty.display(self.ctx.db()).to_string()) 145 .detail(ty.display(self.ctx.db()).to_string())
136 .set_documentation(field.docs(self.ctx.db())) 146 .set_documentation(field.docs(self.ctx.db()))
@@ -151,11 +161,17 @@ impl<'a> Render<'a> {
151 item.build() 161 item.build()
152 } 162 }
153 163
154 fn render_tuple_field(&self, field: usize, ty: &hir::Type) -> CompletionItem { 164 fn render_tuple_field(
165 &self,
166 receiver: Option<String>,
167 field: usize,
168 ty: &hir::Type,
169 ) -> CompletionItem {
155 let mut item = CompletionItem::new( 170 let mut item = CompletionItem::new(
156 CompletionKind::Reference, 171 CompletionKind::Reference,
157 self.ctx.source_range(), 172 self.ctx.source_range(),
158 field.to_string(), 173 receiver
174 .map_or_else(|| field.to_string(), |receiver| format!("{}.{}", receiver, field)),
159 ); 175 );
160 176
161 item.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string()); 177 item.kind(SymbolKind::Field).detail(ty.display(self.ctx.db()).to_string());