aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs43
1 files changed, 18 insertions, 25 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 55439d0e5..c6b83da3d 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -48,7 +48,7 @@
48//! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding 48//! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding
49//! capability enabled. 49//! capability enabled.
50 50
51use hir::{AsAssocItem, ItemInNs, ModPath, ScopeDef}; 51use hir::{AsAssocItem, ModPath, ModuleDef, ScopeDef};
52use ide_db::helpers::{ 52use ide_db::helpers::{
53 import_assets::{ImportAssets, ImportCandidate}, 53 import_assets::{ImportAssets, ImportCandidate},
54 insert_use::ImportScope, 54 insert_use::ImportScope,
@@ -91,33 +91,26 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
91 &ctx.sema, 91 &ctx.sema,
92 )?; 92 )?;
93 93
94 let mut all_mod_paths = import_assets 94 let mut all_imports =
95 .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) 95 import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind);
96 .into_iter() 96 all_imports.sort_by_cached_key(|import| {
97 .map(|import| {
98 let def_to_display = match import.item_to_display() {
99 ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()),
100 ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()),
101 ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()),
102 };
103 (import, def_to_display)
104 })
105 .collect::<Vec<_>>();
106 all_mod_paths.sort_by_cached_key(|(import, _)| {
107 compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) 97 compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased)
108 }); 98 });
109 99
110 acc.add_all(all_mod_paths.into_iter().filter_map(|(import, def_to_display)| { 100 acc.add_all(all_imports.into_iter().filter_map(|import| {
111 let import_for_trait_assoc_item = match def_to_display { 101 let import_for_trait_assoc_item = import
112 ScopeDef::ModuleDef(module_def) => module_def 102 .item_to_display()
113 .as_assoc_item(ctx.db) 103 .as_module_def_id()
114 .and_then(|assoc| assoc.containing_trait(ctx.db)) 104 .and_then(|module_def_id| {
115 .is_some(), 105 ModuleDef::from(module_def_id).as_assoc_item(ctx.db)?.containing_trait(ctx.db)
116 _ => false, 106 })
117 }; 107 .is_some();
118 let import_edit = 108 let def_to_display = ScopeDef::from(import.item_to_display());
119 ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; 109 render_resolution_with_import(
120 render_resolution_with_import(RenderContext::new(ctx), import_edit, &def_to_display) 110 RenderContext::new(ctx),
111 ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item },
112 &def_to_display,
113 )
121 })); 114 }));
122 Some(()) 115 Some(())
123} 116}