From 81961dc035106dcfd29b894aae339261a0ba037b Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 11:04:01 +0200 Subject: Do not propose assoc items without qualifiers --- crates/ide_completion/src/completions/flyimport.rs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ide_completion/src') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 08df2df3f..f6c7d507f 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -943,6 +943,38 @@ mod foo { fn main() { bar::Ass$0 +}"#, + expect![[]], + ) + } + + #[test] + fn local_assoc_items_are_omitted() { + check( + r#" +mod something { + pub trait BaseTrait { + fn test_function() -> i32; + } + + pub struct Item1; + pub struct Item2; + + impl BaseTrait for Item1 { + fn test_function() -> i32 { + 1 + } + } + + impl BaseTrait for Item2 { + fn test_function() -> i32 { + 2 + } + } +} + +fn main() { + test_f$0 }"#, expect![[]], ) -- cgit v1.2.3 From a631108d2dd0596b079b59efa37b1af00d7555db Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 15:02:52 +0200 Subject: Do not query item search by name eagerly --- crates/ide_completion/src/lib.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'crates/ide_completion/src') diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index d9ea7b7ea..c91c98871 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -14,7 +14,10 @@ mod completions; use completions::flyimport::position_for_import; use ide_db::{ base_db::FilePosition, - helpers::{import_assets::LocatedImport, insert_use::ImportScope}, + helpers::{ + import_assets::{LocatedImport, NameToImport}, + insert_use::ImportScope, + }, items_locator, RootDatabase, }; use text_edit::TextEdit; @@ -149,15 +152,20 @@ pub fn resolve_completion_edits( let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); - let (import_path, item_to_import) = - items_locator::with_exact_name(&ctx.sema, current_crate, imported_name) - .into_iter() - .filter_map(|candidate| { - current_module - .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) - .zip(Some(candidate)) - }) - .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; + let (import_path, item_to_import) = items_locator::locate_for_name( + &ctx.sema, + current_crate, + NameToImport::Exact(imported_name), + items_locator::AssocItemSearch::Include, + None, + ) + .into_iter() + .filter_map(|candidate| { + current_module + .find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind) + .zip(Some(candidate)) + }) + .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; let import = LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path)); -- cgit v1.2.3 From 879432452d15d4e9c373a6233a0cd15e22f20ef3 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 22:54:04 +0200 Subject: Docs --- crates/ide_completion/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ide_completion/src') diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index c91c98871..9ecd82b06 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -152,12 +152,12 @@ pub fn resolve_completion_edits( let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); - let (import_path, item_to_import) = items_locator::locate_for_name( + let (import_path, item_to_import) = items_locator::items_with_name( &ctx.sema, current_crate, NameToImport::Exact(imported_name), items_locator::AssocItemSearch::Include, - None, + Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), ) .into_iter() .filter_map(|candidate| { -- cgit v1.2.3 From 56a7d246d59d9429304b82bce2f1e71b632c5737 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Mar 2021 23:04:28 +0200 Subject: Disable unqualified assoc items completion for now --- crates/ide_completion/src/completions/flyimport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide_completion/src') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index f6c7d507f..eb2cba631 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -949,7 +949,7 @@ fn main() { } #[test] - fn local_assoc_items_are_omitted() { + fn unqualified_assoc_items_are_omitted() { check( r#" mod something { -- cgit v1.2.3