aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions.rs')
-rw-r--r--crates/ide_completion/src/completions.rs48
1 files changed, 22 insertions, 26 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs
index 7a4d71e91..e07a4c403 100644
--- a/crates/ide_completion/src/completions.rs
+++ b/crates/ide_completion/src/completions.rs
@@ -56,10 +56,16 @@ impl Builder {
56} 56}
57 57
58impl Completions { 58impl Completions {
59 pub(crate) fn add(&mut self, item: CompletionItem) { 59 fn add(&mut self, item: CompletionItem) {
60 self.buf.push(item) 60 self.buf.push(item)
61 } 61 }
62 62
63 fn add_opt(&mut self, item: Option<CompletionItem>) {
64 if let Some(item) = item {
65 self.buf.push(item)
66 }
67 }
68
63 pub(crate) fn add_all<I>(&mut self, items: I) 69 pub(crate) fn add_all<I>(&mut self, items: I)
64 where 70 where
65 I: IntoIterator, 71 I: IntoIterator,
@@ -103,9 +109,10 @@ impl Completions {
103 local_name: hir::Name, 109 local_name: hir::Name,
104 resolution: &hir::ScopeDef, 110 resolution: &hir::ScopeDef,
105 ) { 111 ) {
106 if let Some(item) = render_resolution(RenderContext::new(ctx), local_name, resolution) { 112 if ctx.expects_type() && resolution.is_value_def() {
107 self.add(item); 113 return;
108 } 114 }
115 self.add_opt(render_resolution(RenderContext::new(ctx), local_name, resolution));
109 } 116 }
110 117
111 pub(crate) fn add_macro( 118 pub(crate) fn add_macro(
@@ -118,9 +125,7 @@ impl Completions {
118 Some(it) => it, 125 Some(it) => it,
119 None => return, 126 None => return,
120 }; 127 };
121 if let Some(item) = render_macro(RenderContext::new(ctx), None, name, macro_) { 128 self.add_opt(render_macro(RenderContext::new(ctx), None, name, macro_));
122 self.add(item);
123 }
124 } 129 }
125 130
126 pub(crate) fn add_function( 131 pub(crate) fn add_function(
@@ -129,9 +134,10 @@ impl Completions {
129 func: hir::Function, 134 func: hir::Function,
130 local_name: Option<hir::Name>, 135 local_name: Option<hir::Name>,
131 ) { 136 ) {
132 if let Some(item) = render_fn(RenderContext::new(ctx), None, local_name, func) { 137 if ctx.expects_type() {
133 self.add(item) 138 return;
134 } 139 }
140 self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
135 } 141 }
136 142
137 pub(crate) fn add_method( 143 pub(crate) fn add_method(
@@ -141,10 +147,7 @@ impl Completions {
141 receiver: Option<hir::Name>, 147 receiver: Option<hir::Name>,
142 local_name: Option<hir::Name>, 148 local_name: Option<hir::Name>,
143 ) { 149 ) {
144 if let Some(item) = render_method(RenderContext::new(ctx), None, receiver, local_name, func) 150 self.add_opt(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
145 {
146 self.add(item)
147 }
148 } 151 }
149 152
150 pub(crate) fn add_variant_pat( 153 pub(crate) fn add_variant_pat(
@@ -153,9 +156,7 @@ impl Completions {
153 variant: hir::Variant, 156 variant: hir::Variant,
154 local_name: Option<hir::Name>, 157 local_name: Option<hir::Name>,
155 ) { 158 ) {
156 if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, local_name, None) { 159 self.add_opt(render_variant_pat(RenderContext::new(ctx), variant, local_name, None));
157 self.add(item);
158 }
159 } 160 }
160 161
161 pub(crate) fn add_qualified_variant_pat( 162 pub(crate) fn add_qualified_variant_pat(
@@ -164,9 +165,7 @@ impl Completions {
164 variant: hir::Variant, 165 variant: hir::Variant,
165 path: hir::ModPath, 166 path: hir::ModPath,
166 ) { 167 ) {
167 if let Some(item) = render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)) { 168 self.add_opt(render_variant_pat(RenderContext::new(ctx), variant, None, Some(path)));
168 self.add(item);
169 }
170 } 169 }
171 170
172 pub(crate) fn add_struct_pat( 171 pub(crate) fn add_struct_pat(
@@ -175,21 +174,18 @@ impl Completions {
175 strukt: hir::Struct, 174 strukt: hir::Struct,
176 local_name: Option<hir::Name>, 175 local_name: Option<hir::Name>,
177 ) { 176 ) {
178 if let Some(item) = render_struct_pat(RenderContext::new(ctx), strukt, local_name) { 177 self.add_opt(render_struct_pat(RenderContext::new(ctx), strukt, local_name));
179 self.add(item);
180 }
181 } 178 }
182 179
183 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { 180 pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
184 if let Some(item) = render_const(RenderContext::new(ctx), constant) { 181 if ctx.expects_type() {
185 self.add(item); 182 return;
186 } 183 }
184 self.add_opt(render_const(RenderContext::new(ctx), constant));
187 } 185 }
188 186
189 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { 187 pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
190 if let Some(item) = render_type_alias(RenderContext::new(ctx), type_alias) { 188 self.add_opt(render_type_alias(RenderContext::new(ctx), type_alias));
191 self.add(item)
192 }
193 } 189 }
194 190
195 pub(crate) fn add_qualified_enum_variant( 191 pub(crate) fn add_qualified_enum_variant(