diff options
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 54 | ||||
-rw-r--r-- | crates/completion/src/render.rs | 1 |
2 files changed, 29 insertions, 26 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 86c143b63..f452c98e4 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -79,32 +79,34 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
79 | 79 | ||
80 | let potential_import_name = ctx.token.to_string(); | 80 | let potential_import_name = ctx.token.to_string(); |
81 | 81 | ||
82 | let possible_imports = | 82 | let possible_imports = imports_locator::find_similar_imports( |
83 | imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, 400) | 83 | &ctx.sema, |
84 | .filter_map(|import_candidate| match import_candidate { | 84 | ctx.krate?, |
85 | // when completing outside the use declaration, modules are pretty useless | 85 | &potential_import_name, |
86 | // and tend to bloat the completion suggestions a lot | 86 | 50, |
87 | Either::Left(ModuleDef::Module(_)) => None, | 87 | true, |
88 | Either::Left(module_def) => Some(( | 88 | ) |
89 | current_module.find_use_path(ctx.db, module_def)?, | 89 | .filter_map(|import_candidate| { |
90 | ScopeDef::ModuleDef(module_def), | 90 | Some(match import_candidate { |
91 | )), | 91 | Either::Left(module_def) => { |
92 | Either::Right(macro_def) => Some(( | 92 | (current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def)) |
93 | current_module.find_use_path(ctx.db, macro_def)?, | 93 | } |
94 | ScopeDef::MacroDef(macro_def), | 94 | Either::Right(macro_def) => { |
95 | )), | 95 | (current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def)) |
96 | }) | 96 | } |
97 | .filter(|(mod_path, _)| mod_path.len() > 1) | 97 | }) |
98 | .filter_map(|(import_path, definition)| { | 98 | }) |
99 | render_resolution_with_import( | 99 | .filter(|(mod_path, _)| mod_path.len() > 1) |
100 | RenderContext::new(ctx), | 100 | .take(20) |
101 | import_path.clone(), | 101 | .filter_map(|(import_path, definition)| { |
102 | import_scope.clone(), | 102 | render_resolution_with_import( |
103 | ctx.config.merge, | 103 | RenderContext::new(ctx), |
104 | &definition, | 104 | import_path.clone(), |
105 | ) | 105 | import_scope.clone(), |
106 | }) | 106 | ctx.config.merge, |
107 | .take(20); | 107 | &definition, |
108 | ) | ||
109 | }); | ||
108 | 110 | ||
109 | acc.add_all(possible_imports); | 111 | acc.add_all(possible_imports); |
110 | Some(()) | 112 | Some(()) |
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index e892d4de8..bce02f577 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs | |||
@@ -150,6 +150,7 @@ impl<'a> Render<'a> { | |||
150 | import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, | 150 | import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, |
151 | resolution: &ScopeDef, | 151 | resolution: &ScopeDef, |
152 | ) -> Option<CompletionItem> { | 152 | ) -> Option<CompletionItem> { |
153 | let _p = profile::span("render_resolution"); | ||
153 | use hir::ModuleDef::*; | 154 | use hir::ModuleDef::*; |
154 | 155 | ||
155 | let completion_kind = match resolution { | 156 | let completion_kind = match resolution { |