From 51e2d76b9839410020c75ac02ad602675b0a5aa9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 12 Sep 2019 23:35:53 +0300 Subject: Specify desirable namespace when calling resolve That way, we are able to get rid of a number of unreachable statements --- crates/ra_ide_api/src/completion/complete_pattern.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide_api/src/completion/complete_pattern.rs') diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index fb7f9feb8..c17b5b7ee 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -7,22 +7,20 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { } // FIXME: ideally, we should look at the type we are matching against and // suggest variants + auto-imports - let names = ctx.analyzer.all_names(ctx.db); - for (name, res) in names.into_iter() { - let r = res.as_ref(); - let def = match r.take_types().or_else(|| r.take_values()) { - Some(hir::Resolution::Def(def)) => def, - _ => continue, + ctx.analyzer.process_all_names(ctx.db, &mut |name, res| { + let def = match &res { + hir::ScopeDef::ModuleDef(def) => def, + _ => return, }; match def { hir::ModuleDef::Adt(hir::Adt::Enum(..)) | hir::ModuleDef::EnumVariant(..) | hir::ModuleDef::Const(..) | hir::ModuleDef::Module(..) => (), - _ => continue, + _ => return, } acc.add_resolution(ctx, name.to_string(), &res) - } + }); } #[cfg(test)] -- cgit v1.2.3