aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/completion/src/completions/unqualified_path.rs60
-rw-r--r--crates/ide_db/src/imports_locator.rs10
2 files changed, 38 insertions, 32 deletions
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs
index f65709adf..4e4e2b36f 100644
--- a/crates/completion/src/completions/unqualified_path.rs
+++ b/crates/completion/src/completions/unqualified_path.rs
@@ -99,7 +99,6 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
99// 99//
100// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only 100// To avoid an excessive amount of the results returned, completion input is checked for inclusion in the identifiers only
101// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers. 101// (i.e. in `HashMap` in the `std::collections::HashMap` path), also not in the module indentifiers.
102// It also avoids searching for any imports for inputs with their length less that 3 symbols.
103// 102//
104// .Merge Behaviour 103// .Merge Behaviour
105// 104//
@@ -123,40 +122,39 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<()
123 let _p = profile::span("fuzzy_completion"); 122 let _p = profile::span("fuzzy_completion");
124 let potential_import_name = ctx.token.to_string(); 123 let potential_import_name = ctx.token.to_string();
125 124
126 if potential_import_name.len() < 3 {
127 return None;
128 }
129
130 let current_module = ctx.scope.module()?; 125 let current_module = ctx.scope.module()?;
131 let anchor = ctx.name_ref_syntax.as_ref()?; 126 let anchor = ctx.name_ref_syntax.as_ref()?;
132 let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; 127 let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?;
133 128
134 let possible_imports = 129 let possible_imports = imports_locator::find_similar_imports(
135 imports_locator::find_similar_imports(&ctx.sema, ctx.krate?, &potential_import_name, true) 130 &ctx.sema,
136 .filter_map(|import_candidate| { 131 ctx.krate?,
137 Some(match import_candidate { 132 Some(100),
138 Either::Left(module_def) => ( 133 &potential_import_name,
139 current_module.find_use_path(ctx.db, module_def)?, 134 true,
140 ScopeDef::ModuleDef(module_def), 135 )
141 ), 136 .filter_map(|import_candidate| {
142 Either::Right(macro_def) => ( 137 Some(match import_candidate {
143 current_module.find_use_path(ctx.db, macro_def)?, 138 Either::Left(module_def) => {
144 ScopeDef::MacroDef(macro_def), 139 (current_module.find_use_path(ctx.db, module_def)?, ScopeDef::ModuleDef(module_def))
145 ), 140 }
146 }) 141 Either::Right(macro_def) => {
147 }) 142 (current_module.find_use_path(ctx.db, macro_def)?, ScopeDef::MacroDef(macro_def))
148 .filter(|(mod_path, _)| mod_path.len() > 1) 143 }
149 .filter_map(|(import_path, definition)| { 144 })
150 render_resolution_with_import( 145 })
151 RenderContext::new(ctx), 146 .filter(|(mod_path, _)| mod_path.len() > 1)
152 ImportEdit { 147 .filter_map(|(import_path, definition)| {
153 import_path: import_path.clone(), 148 render_resolution_with_import(
154 import_scope: import_scope.clone(), 149 RenderContext::new(ctx),
155 merge_behaviour: ctx.config.merge, 150 ImportEdit {
156 }, 151 import_path: import_path.clone(),
157 &definition, 152 import_scope: import_scope.clone(),
158 ) 153 merge_behaviour: ctx.config.merge,
159 }); 154 },
155 &definition,
156 )
157 });
160 158
161 acc.add_all(possible_imports); 159 acc.add_all(possible_imports);
162 Some(()) 160 Some(())
diff --git a/crates/ide_db/src/imports_locator.rs b/crates/ide_db/src/imports_locator.rs
index 31151ce24..b2980a5d6 100644
--- a/crates/ide_db/src/imports_locator.rs
+++ b/crates/ide_db/src/imports_locator.rs
@@ -34,6 +34,7 @@ pub fn find_exact_imports<'a>(
34pub fn find_similar_imports<'a>( 34pub fn find_similar_imports<'a>(
35 sema: &Semantics<'a, RootDatabase>, 35 sema: &Semantics<'a, RootDatabase>,
36 krate: Crate, 36 krate: Crate,
37 limit: Option<usize>,
37 name_to_import: &str, 38 name_to_import: &str,
38 ignore_modules: bool, 39 ignore_modules: bool,
39) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> { 40) -> impl Iterator<Item = Either<ModuleDef, MacroDef>> {
@@ -44,7 +45,14 @@ pub fn find_similar_imports<'a>(
44 external_query = external_query.exclude_import_kind(import_map::ImportKind::Module); 45 external_query = external_query.exclude_import_kind(import_map::ImportKind::Module);
45 } 46 }
46 47
47 find_imports(sema, krate, symbol_index::Query::new(name_to_import.to_string()), external_query) 48 let mut local_query = symbol_index::Query::new(name_to_import.to_string());
49
50 if let Some(limit) = limit {
51 local_query.limit(limit);
52 external_query = external_query.limit(limit);
53 }
54
55 find_imports(sema, krate, local_query, external_query)
48} 56}
49 57
50fn find_imports<'a>( 58fn find_imports<'a>(