aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs32
-rw-r--r--crates/ide_completion/src/lib.rs28
2 files changed, 50 insertions, 10 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 08df2df3f..eb2cba631 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -947,4 +947,36 @@ fn main() {
947 expect![[]], 947 expect![[]],
948 ) 948 )
949 } 949 }
950
951 #[test]
952 fn unqualified_assoc_items_are_omitted() {
953 check(
954 r#"
955mod something {
956 pub trait BaseTrait {
957 fn test_function() -> i32;
958 }
959
960 pub struct Item1;
961 pub struct Item2;
962
963 impl BaseTrait for Item1 {
964 fn test_function() -> i32 {
965 1
966 }
967 }
968
969 impl BaseTrait for Item2 {
970 fn test_function() -> i32 {
971 2
972 }
973 }
974}
975
976fn main() {
977 test_f$0
978}"#,
979 expect![[]],
980 )
981 }
950} 982}
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index 995970fca..87cddb98e 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -14,7 +14,10 @@ mod completions;
14use completions::flyimport::position_for_import; 14use completions::flyimport::position_for_import;
15use ide_db::{ 15use ide_db::{
16 base_db::FilePosition, 16 base_db::FilePosition,
17 helpers::{import_assets::LocatedImport, insert_use::ImportScope}, 17 helpers::{
18 import_assets::{LocatedImport, NameToImport},
19 insert_use::ImportScope,
20 },
18 items_locator, RootDatabase, 21 items_locator, RootDatabase,
19}; 22};
20use text_edit::TextEdit; 23use text_edit::TextEdit;
@@ -151,15 +154,20 @@ pub fn resolve_completion_edits(
151 let current_module = ctx.sema.scope(position_for_import).module()?; 154 let current_module = ctx.sema.scope(position_for_import).module()?;
152 let current_crate = current_module.krate(); 155 let current_crate = current_module.krate();
153 156
154 let (import_path, item_to_import) = 157 let (import_path, item_to_import) = items_locator::items_with_name(
155 items_locator::with_exact_name(&ctx.sema, current_crate, imported_name) 158 &ctx.sema,
156 .into_iter() 159 current_crate,
157 .filter_map(|candidate| { 160 NameToImport::Exact(imported_name),
158 current_module 161 items_locator::AssocItemSearch::Include,
159 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) 162 Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
160 .zip(Some(candidate)) 163 )
161 }) 164 .into_iter()
162 .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; 165 .filter_map(|candidate| {
166 current_module
167 .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
168 .zip(Some(candidate))
169 })
170 .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?;
163 let import = 171 let import =
164 LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path)); 172 LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path));
165 173