aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-02-24 23:06:31 +0000
committerKirill Bulatov <[email protected]>2021-03-08 21:59:18 +0000
commit582cee2cdf5355b681f14bbb33bd5c431c284d87 (patch)
tree47d25e9c057759b1aa334abf3f584f1d0317d941 /crates/ide_completion/src/completions
parent309421c117fc20e58b9f30fb28a01a89f50b0086 (diff)
Return more data about located imports
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 64b60bbdd..8ff76688e 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -96,21 +96,21 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
96 let mut all_mod_paths = import_assets 96 let mut all_mod_paths = import_assets
97 .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) 97 .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
98 .into_iter() 98 .into_iter()
99 .map(|(mod_path, item_in_ns)| { 99 .map(|import| {
100 let scope_item = match item_in_ns { 100 let proposed_def = match import.item_to_import() {
101 hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), 101 hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()),
102 hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), 102 hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()),
103 hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), 103 hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()),
104 }; 104 };
105 (mod_path, scope_item) 105 (import, proposed_def)
106 }) 106 })
107 .filter(|(_, proposed_def)| !scope_definitions.contains(proposed_def)) 107 .filter(|(_, proposed_def)| !scope_definitions.contains(proposed_def))
108 .collect::<Vec<_>>(); 108 .collect::<Vec<_>>();
109 all_mod_paths.sort_by_cached_key(|(mod_path, _)| { 109 all_mod_paths.sort_by_cached_key(|(import, _)| {
110 compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) 110 compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased)
111 }); 111 });
112 112
113 acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { 113 acc.add_all(all_mod_paths.into_iter().filter_map(|(import, definition)| {
114 let import_for_trait_assoc_item = match definition { 114 let import_for_trait_assoc_item = match definition {
115 ScopeDef::ModuleDef(module_def) => module_def 115 ScopeDef::ModuleDef(module_def) => module_def
116 .as_assoc_item(ctx.db) 116 .as_assoc_item(ctx.db)
@@ -118,11 +118,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
118 .is_some(), 118 .is_some(),
119 _ => false, 119 _ => false,
120 }; 120 };
121 let import_edit = ImportEdit { 121 let import_edit =
122 import_path, 122 ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item };
123 import_scope: import_scope.clone(),
124 import_for_trait_assoc_item,
125 };
126 render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition) 123 render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition)
127 })); 124 }));
128 Some(()) 125 Some(())
@@ -186,11 +183,11 @@ fn compute_fuzzy_completion_order_key(
186 user_input_lowercased: &str, 183 user_input_lowercased: &str,
187) -> usize { 184) -> usize {
188 cov_mark::hit!(certain_fuzzy_order_test); 185 cov_mark::hit!(certain_fuzzy_order_test);
189 let proposed_import_name = match proposed_mod_path.segments().last() { 186 let import_name = match proposed_mod_path.segments().last() {
190 Some(name) => name.to_string().to_lowercase(), 187 Some(name) => name.to_string().to_lowercase(),
191 None => return usize::MAX, 188 None => return usize::MAX,
192 }; 189 };
193 match proposed_import_name.match_indices(user_input_lowercased).next() { 190 match import_name.match_indices(user_input_lowercased).next() {
194 Some((first_matching_index, _)) => first_matching_index, 191 Some((first_matching_index, _)) => first_matching_index,
195 None => usize::MAX, 192 None => usize::MAX,
196 } 193 }