diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-31 14:21:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-31 14:21:31 +0100 |
commit | e6ec860363a140b8aa3dcaafaf6e9d7327838610 (patch) | |
tree | cacaf711d01ce64074ecf675287ab03c85487ec1 /crates/ide_completion/src/render.rs | |
parent | e9a797748daa7e25cde66927b8907b2d976201a5 (diff) | |
parent | fb7105a5801ab1d0ede830cd53bbc3ccbf0b5e2c (diff) |
Merge #9039
9039: feat: Complete fields and methods with `self.` prefixed when inside methods r=matklad a=Veykril
![w65NbjkZiG](https://user-images.githubusercontent.com/3757771/119984385-a0111700-bfc1-11eb-9dbf-52fdaa4d72b5.gif)
Closes #7173
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/render.rs')
-rw-r--r-- | crates/ide_completion/src/render.rs | 30 |
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..a49a60711 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -25,18 +25,20 @@ use crate::{ | |||
25 | 25 | ||
26 | pub(crate) fn render_field<'a>( | 26 | pub(crate) fn render_field<'a>( |
27 | ctx: RenderContext<'a>, | 27 | ctx: RenderContext<'a>, |
28 | receiver: Option<hir::Name>, | ||
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 | ||
34 | pub(crate) fn render_tuple_field<'a>( | 35 | pub(crate) fn render_tuple_field<'a>( |
35 | ctx: RenderContext<'a>, | 36 | ctx: RenderContext<'a>, |
37 | receiver: Option<hir::Name>, | ||
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 | ||
42 | pub(crate) fn render_resolution<'a>( | 44 | pub(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<hir::Name>, | ||
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.clone(), |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<hir::Name>, | ||
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()); |