diff options
author | adamrk <[email protected]> | 2020-09-02 19:38:08 +0100 |
---|---|---|
committer | adamrk <[email protected]> | 2020-09-02 21:14:37 +0100 |
commit | d9bb86ad7dfd17543e6e1c9ef184337f828b1027 (patch) | |
tree | c177524f22b19839d8e481a3d26b863740c23b7c /crates/ide/src/completion/presentation.rs | |
parent | 04fc937700105951442a9b6fa30591fb48a1e879 (diff) |
Collect locals in context
Diffstat (limited to 'crates/ide/src/completion/presentation.rs')
-rw-r--r-- | crates/ide/src/completion/presentation.rs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/crates/ide/src/completion/presentation.rs b/crates/ide/src/completion/presentation.rs index 0c29d0be2..059fdfdc9 100644 --- a/crates/ide/src/completion/presentation.rs +++ b/crates/ide/src/completion/presentation.rs | |||
@@ -192,20 +192,15 @@ impl Completions { | |||
192 | local_name: Option<String>, | 192 | local_name: Option<String>, |
193 | ) { | 193 | ) { |
194 | fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String { | 194 | fn add_arg(arg: &str, ty: &Type, ctx: &CompletionContext) -> String { |
195 | let mut prefix = ""; | ||
196 | if let Some(derefed_ty) = ty.remove_ref() { | 195 | if let Some(derefed_ty) = ty.remove_ref() { |
197 | ctx.scope.process_all_names(&mut |name, scope| { | 196 | for (name, local) in ctx.locals.iter() { |
198 | if prefix != "" { | 197 | if name == arg && local.can_unify(derefed_ty.clone(), ctx.db) { |
199 | return; | 198 | return (if ty.is_mutable_reference() { "&mut " } else { "&" }).to_string() |
199 | + &arg.to_string(); | ||
200 | } | 200 | } |
201 | if let ScopeDef::Local(local) = scope { | 201 | } |
202 | if name.to_string() == arg && local.can_unify(derefed_ty.clone(), ctx.db) { | ||
203 | prefix = if ty.is_mutable_reference() { "&mut " } else { "&" }; | ||
204 | } | ||
205 | } | ||
206 | }); | ||
207 | } | 202 | } |
208 | prefix.to_string() + arg | 203 | arg.to_string() |
209 | }; | 204 | }; |
210 | let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string()); | 205 | let name = local_name.unwrap_or_else(|| func.name(ctx.db).to_string()); |
211 | let ast_node = func.source(ctx.db).value; | 206 | let ast_node = func.source(ctx.db).value; |