From 005bc49d744f6a7c2ef38a4abd3327b0804709d1 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 20 Feb 2021 23:32:21 +0200 Subject: Test and initial refactoring --- crates/ide_completion/src/completions/flyimport.rs | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index f34764b61..16384551c 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -168,15 +168,15 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option Date: Wed, 24 Feb 2021 01:20:00 +0200 Subject: Draft the qualifier import resolution --- crates/ide_completion/src/completions/flyimport.rs | 84 +++++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 16384551c..64b60bbdd 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -775,18 +775,92 @@ fn main() { } #[test] - fn unresolved_qualifiers() { + fn unresolved_qualifier() { + check_edit( + "Item", + r#" +mod foo { + pub mod bar { + pub mod baz { + pub struct Item; + } + } +} + +fn main() { + bar::baz::Ite$0 +} +"#, + r#" +use foo::bar; + +mod foo { + pub mod bar { + pub mod baz { + pub struct Item; + } + } +} + +fn main() { + bar::baz::Item +} +"#, + ); + } + + #[test] + fn unresolved_assoc_item_container() { + check_edit( + "Item", + r#" +mod foo { + pub struct Item; + + impl Item { + pub const TEST_ASSOC: usize = 3; + } +} + +fn main() { + Item::TEST_A$0; +} +"#, + r#" +use foo::Item; + +mod foo { + pub struct Item; + + impl Item { + pub const TEST_ASSOC: usize = 3; + } +} + +fn main() { + Item::TEST_ASSOC +} +"#, + ); + } + + #[test] + fn unresolved_assoc_item_container_with_path() { check_edit( "Item", r#" mod foo { pub mod bar { pub struct Item; + + impl Item { + pub const TEST_ASSOC: usize = 3; + } } } fn main() { - bar::Ite$0 + bar::Item::TEST_A$0; } "#, r#" @@ -795,11 +869,15 @@ use foo::bar; mod foo { pub mod bar { pub struct Item; + + impl Item { + pub const TEST_ASSOC: usize = 3; + } } } fn main() { - bar::Item + bar::Item::TEST_ASSOC } "#, ); -- cgit v1.2.3 From 582cee2cdf5355b681f14bbb33bd5c431c284d87 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 25 Feb 2021 01:06:31 +0200 Subject: Return more data about located imports --- crates/ide_completion/src/completions/flyimport.rs | 23 ++++++++---------- crates/ide_completion/src/item.rs | 28 ++++++++++------------ crates/ide_completion/src/lib.rs | 20 ++++++++++------ crates/ide_completion/src/render.rs | 2 +- 4 files changed, 37 insertions(+), 36 deletions(-) (limited to 'crates/ide_completion') 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) let mut all_mod_paths = import_assets .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) .into_iter() - .map(|(mod_path, item_in_ns)| { - let scope_item = match item_in_ns { + .map(|import| { + let proposed_def = match import.item_to_import() { hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), }; - (mod_path, scope_item) + (import, proposed_def) }) .filter(|(_, proposed_def)| !scope_definitions.contains(proposed_def)) .collect::>(); - all_mod_paths.sort_by_cached_key(|(mod_path, _)| { - compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) + all_mod_paths.sort_by_cached_key(|(import, _)| { + compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) }); - acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { + acc.add_all(all_mod_paths.into_iter().filter_map(|(import, definition)| { let import_for_trait_assoc_item = match definition { ScopeDef::ModuleDef(module_def) => module_def .as_assoc_item(ctx.db) @@ -118,11 +118,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) .is_some(), _ => false, }; - let import_edit = ImportEdit { - import_path, - import_scope: import_scope.clone(), - import_for_trait_assoc_item, - }; + let import_edit = + ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition) })); Some(()) @@ -186,11 +183,11 @@ fn compute_fuzzy_completion_order_key( user_input_lowercased: &str, ) -> usize { cov_mark::hit!(certain_fuzzy_order_test); - let proposed_import_name = match proposed_mod_path.segments().last() { + let import_name = match proposed_mod_path.segments().last() { Some(name) => name.to_string().to_lowercase(), None => return usize::MAX, }; - match proposed_import_name.match_indices(user_input_lowercased).next() { + match import_name.match_indices(user_input_lowercased).next() { Some((first_matching_index, _)) => first_matching_index, None => usize::MAX, } diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 9b2435c4b..0390fe226 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -2,9 +2,10 @@ use std::fmt; -use hir::{Documentation, ModPath, Mutability}; +use hir::{Documentation, Mutability}; use ide_db::{ helpers::{ + import_assets::LocatedImport, insert_use::{self, ImportScope, InsertUseConfig}, mod_path_to_ast, SnippetCap, }, @@ -272,7 +273,7 @@ impl CompletionItem { /// An extra import to add after the completion is applied. #[derive(Debug, Clone)] pub struct ImportEdit { - pub import_path: ModPath, + pub import: LocatedImport, pub import_scope: ImportScope, pub import_for_trait_assoc_item: bool, } @@ -283,8 +284,11 @@ impl ImportEdit { pub fn to_text_edit(&self, cfg: InsertUseConfig) -> Option { let _p = profile::span("ImportEdit::to_text_edit"); - let rewriter = - insert_use::insert_use(&self.import_scope, mod_path_to_ast(&self.import_path), cfg); + let rewriter = insert_use::insert_use( + &self.import_scope, + mod_path_to_ast(self.import.import_path()), + cfg, + ); let old_ast = rewriter.rewrite_root()?; let mut import_insert = TextEdit::builder(); algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); @@ -323,19 +327,13 @@ impl Builder { let mut insert_text = self.insert_text; if let Some(import_to_add) = self.import_to_add.as_ref() { + lookup = lookup.or_else(|| Some(label.clone())); + insert_text = insert_text.or_else(|| Some(label.clone())); + let display_path = import_to_add.import.display_path(); if import_to_add.import_for_trait_assoc_item { - lookup = lookup.or_else(|| Some(label.clone())); - insert_text = insert_text.or_else(|| Some(label.clone())); - label = format!("{} ({})", label, import_to_add.import_path); + label = format!("{} ({})", label, display_path); } else { - let mut import_path_without_last_segment = import_to_add.import_path.to_owned(); - let _ = import_path_without_last_segment.pop_segment(); - - if !import_path_without_last_segment.segments().is_empty() { - lookup = lookup.or_else(|| Some(label.clone())); - insert_text = insert_text.or_else(|| Some(label.clone())); - label = format!("{}::{}", import_path_without_last_segment, label); - } + label = display_path.to_string(); } } diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index b0b809791..ca2e5e706 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -13,7 +13,9 @@ mod completions; use completions::flyimport::position_for_import; use ide_db::{ - base_db::FilePosition, helpers::insert_use::ImportScope, imports_locator, RootDatabase, + base_db::FilePosition, + helpers::{import_assets::LocatedImport, insert_use::ImportScope}, + imports_locator, RootDatabase, }; use text_edit::TextEdit; @@ -148,12 +150,16 @@ pub fn resolve_completion_edits( let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); - let import_path = imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name) - .filter_map(|candidate| { - let item: hir::ItemInNs = candidate.either(Into::into, Into::into); - current_module.find_use_path_prefixed(db, item, config.insert_use.prefix_kind) - }) - .find(|mod_path| mod_path.to_string() == full_import_path)?; + let (import_path, item_to_import) = + imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name) + .filter_map(|candidate| { + let item: hir::ItemInNs = candidate.either(Into::into, Into::into); + current_module + .find_use_path_prefixed(db, item, config.insert_use.prefix_kind) + .zip(Some(item)) + }) + .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; + let import = LocatedImport::new(import_path, item_to_import, None); ImportEdit { import_path, import_scope, import_for_trait_assoc_item } .to_text_edit(config.insert_use) diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index dcfac23c5..df26e7642 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -56,7 +56,7 @@ pub(crate) fn render_resolution_with_import<'a>( ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), - _ => import_edit.import_path.segments().last()?.to_string(), + _ => import_edit.import.display_path().segments().last()?.to_string(), }; Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { item.completion_kind = CompletionKind::Magic; -- cgit v1.2.3 From d386481fac65e988fa4d13c1bc8d4ddb2bc490c6 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 25 Feb 2021 01:53:59 +0200 Subject: Fix some tests --- crates/ide_completion/src/completions/flyimport.rs | 65 ++++++++++++++++++++-- crates/ide_completion/src/render.rs | 7 ++- 2 files changed, 65 insertions(+), 7 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 8ff76688e..e33fc4b78 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -97,7 +97,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) .into_iter() .map(|import| { - let proposed_def = match import.item_to_import() { + let proposed_def = match import.item_to_display() { hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), @@ -809,7 +809,7 @@ fn main() { #[test] fn unresolved_assoc_item_container() { check_edit( - "Item", + "TEST_ASSOC", r#" mod foo { pub struct Item; @@ -820,7 +820,7 @@ mod foo { } fn main() { - Item::TEST_A$0; + Item::TEST_A$0 } "#, r#" @@ -844,7 +844,7 @@ fn main() { #[test] fn unresolved_assoc_item_container_with_path() { check_edit( - "Item", + "TEST_ASSOC", r#" mod foo { pub mod bar { @@ -857,7 +857,7 @@ mod foo { } fn main() { - bar::Item::TEST_A$0; + bar::Item::TEST_A$0 } "#, r#" @@ -876,6 +876,61 @@ mod foo { fn main() { bar::Item::TEST_ASSOC } +"#, + ); + } + + #[test] + fn unresolved_assoc_item_container_and_trait_with_path() { + check_edit( + "TEST_ASSOC", + r#" +mod foo { + pub mod bar { + pub trait SomeTrait { + const TEST_ASSOC: usize; + } + } + + pub mod baz { + use super::bar::SomeTrait; + + pub struct Item; + + impl SomeTrait for Item { + const TEST_ASSOC: usize = 3; + } + } +} + +fn main() { + baz::Item::TEST_A$0 +} +"#, + r#" +use foo::{bar::SomeTrait, baz}; + +mod foo { + pub mod bar { + pub trait SomeTrait { + const TEST_ASSOC: usize; + } + } + + pub mod baz { + use super::bar::SomeTrait; + + pub struct Item; + + impl SomeTrait for Item { + const TEST_ASSOC: usize = 3; + } + } +} + +fn main() { + baz::Item::TEST_ASSOC +} "#, ); } diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index df26e7642..4bddc3957 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -13,7 +13,10 @@ mod builder_ext; use hir::{ AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type, }; -use ide_db::{helpers::SnippetCap, RootDatabase, SymbolKind}; +use ide_db::{ + helpers::{item_name, SnippetCap}, + RootDatabase, SymbolKind, +}; use syntax::TextRange; use crate::{ @@ -56,7 +59,7 @@ pub(crate) fn render_resolution_with_import<'a>( ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), - _ => import_edit.import.display_path().segments().last()?.to_string(), + _ => item_name(ctx.db(), import_edit.import.item_to_display())?.to_string(), }; Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { item.completion_kind = CompletionKind::Magic; -- cgit v1.2.3 From 9482353fa8e1e88cb720a029b9bb6304819c7399 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 28 Feb 2021 09:57:54 +0200 Subject: Properly handle turbofishes in qualifiers --- crates/ide_completion/src/completions/flyimport.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index e33fc4b78..af49fdd26 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -669,8 +669,8 @@ fn main() { } "#, expect![[r#" - ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED + ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED "#]], ); } -- cgit v1.2.3 From 89d410cef571f5fa7631b17e2fbe52a8f8f03990 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 28 Feb 2021 10:32:15 +0200 Subject: Do not propose already imported imports --- crates/ide_completion/src/completions/flyimport.rs | 23 +++++++--------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index af49fdd26..d6adf70b1 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -48,12 +48,11 @@ //! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding //! capability enabled. -use hir::{AsAssocItem, ModPath, ScopeDef}; +use hir::{AsAssocItem, ItemInNs, ModPath, ScopeDef}; use ide_db::helpers::{ import_assets::{ImportAssets, ImportCandidate}, insert_use::ImportScope, }; -use rustc_hash::FxHashSet; use syntax::{AstNode, SyntaxNode, T}; use crate::{ @@ -92,19 +91,17 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) &ctx.sema, )?; - let scope_definitions = scope_definitions(ctx); let mut all_mod_paths = import_assets .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) .into_iter() .map(|import| { let proposed_def = match import.item_to_display() { - hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), - hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), - hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), + ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), + ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), + ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), }; (import, proposed_def) }) - .filter(|(_, proposed_def)| !scope_definitions.contains(proposed_def)) .collect::>(); all_mod_paths.sort_by_cached_key(|(import, _)| { compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) @@ -125,14 +122,6 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) Some(()) } -fn scope_definitions(ctx: &CompletionContext) -> FxHashSet { - let mut scope_definitions = FxHashSet::default(); - ctx.scope.process_all_names(&mut |_, scope_def| { - scope_definitions.insert(scope_def); - }); - scope_definitions -} - pub(crate) fn position_for_import<'a>( ctx: &'a CompletionContext, import_candidate: Option<&ImportCandidate>, @@ -150,13 +139,14 @@ pub(crate) fn position_for_import<'a>( }) } -fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option { +fn import_assets<'a>(ctx: &'a CompletionContext, fuzzy_name: String) -> Option> { let current_module = ctx.scope.module()?; if let Some(dot_receiver) = &ctx.dot_receiver { ImportAssets::for_fuzzy_method_call( current_module, ctx.sema.type_of_expr(dot_receiver)?, fuzzy_name, + ctx.scope.clone(), ) } else { let fuzzy_name_length = fuzzy_name.len(); @@ -165,6 +155,7 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option Date: Mon, 1 Mar 2021 00:05:22 +0200 Subject: Refactor the import location --- crates/ide_completion/src/completions/flyimport.rs | 65 ++-------------------- 1 file changed, 5 insertions(+), 60 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index d6adf70b1..55439d0e5 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -95,20 +95,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) .into_iter() .map(|import| { - let proposed_def = match import.item_to_display() { + let def_to_display = match import.item_to_display() { ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), }; - (import, proposed_def) + (import, def_to_display) }) .collect::>(); all_mod_paths.sort_by_cached_key(|(import, _)| { compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) }); - acc.add_all(all_mod_paths.into_iter().filter_map(|(import, definition)| { - let import_for_trait_assoc_item = match definition { + acc.add_all(all_mod_paths.into_iter().filter_map(|(import, def_to_display)| { + let import_for_trait_assoc_item = match def_to_display { ScopeDef::ModuleDef(module_def) => module_def .as_assoc_item(ctx.db) .and_then(|assoc| assoc.containing_trait(ctx.db)) @@ -117,7 +117,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) }; let import_edit = ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; - render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition) + render_resolution_with_import(RenderContext::new(ctx), import_edit, &def_to_display) })); Some(()) } @@ -867,61 +867,6 @@ mod foo { fn main() { bar::Item::TEST_ASSOC } -"#, - ); - } - - #[test] - fn unresolved_assoc_item_container_and_trait_with_path() { - check_edit( - "TEST_ASSOC", - r#" -mod foo { - pub mod bar { - pub trait SomeTrait { - const TEST_ASSOC: usize; - } - } - - pub mod baz { - use super::bar::SomeTrait; - - pub struct Item; - - impl SomeTrait for Item { - const TEST_ASSOC: usize = 3; - } - } -} - -fn main() { - baz::Item::TEST_A$0 -} -"#, - r#" -use foo::{bar::SomeTrait, baz}; - -mod foo { - pub mod bar { - pub trait SomeTrait { - const TEST_ASSOC: usize; - } - } - - pub mod baz { - use super::bar::SomeTrait; - - pub struct Item; - - impl SomeTrait for Item { - const TEST_ASSOC: usize = 3; - } - } -} - -fn main() { - baz::Item::TEST_ASSOC -} "#, ); } -- cgit v1.2.3 From e214c3a6bd7f74b42d38663b959fc4f0d113c90c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 1 Mar 2021 13:55:47 +0200 Subject: Simplify --- crates/ide_completion/src/completions/flyimport.rs | 43 +++++++++------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'crates/ide_completion') 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 @@ //! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding //! capability enabled. -use hir::{AsAssocItem, ItemInNs, ModPath, ScopeDef}; +use hir::{AsAssocItem, ModPath, ModuleDef, ScopeDef}; use ide_db::helpers::{ import_assets::{ImportAssets, ImportCandidate}, insert_use::ImportScope, @@ -91,33 +91,26 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) &ctx.sema, )?; - let mut all_mod_paths = import_assets - .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) - .into_iter() - .map(|import| { - let def_to_display = match import.item_to_display() { - ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), - ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), - ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), - }; - (import, def_to_display) - }) - .collect::>(); - all_mod_paths.sort_by_cached_key(|(import, _)| { + let mut all_imports = + import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind); + all_imports.sort_by_cached_key(|import| { compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) }); - acc.add_all(all_mod_paths.into_iter().filter_map(|(import, def_to_display)| { - let import_for_trait_assoc_item = match def_to_display { - ScopeDef::ModuleDef(module_def) => module_def - .as_assoc_item(ctx.db) - .and_then(|assoc| assoc.containing_trait(ctx.db)) - .is_some(), - _ => false, - }; - let import_edit = - ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; - render_resolution_with_import(RenderContext::new(ctx), import_edit, &def_to_display) + acc.add_all(all_imports.into_iter().filter_map(|import| { + let import_for_trait_assoc_item = import + .item_to_display() + .as_module_def_id() + .and_then(|module_def_id| { + ModuleDef::from(module_def_id).as_assoc_item(ctx.db)?.containing_trait(ctx.db) + }) + .is_some(); + let def_to_display = ScopeDef::from(import.item_to_display()); + render_resolution_with_import( + RenderContext::new(ctx), + ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }, + &def_to_display, + ) })); Some(()) } -- cgit v1.2.3 From 821e8369d994ebca39ccbf9b449c604d0c910efc Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 1 Mar 2021 14:14:24 +0200 Subject: Update the docs --- crates/ide_completion/src/completions/flyimport.rs | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index c6b83da3d..1ef6f8afb 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -21,6 +21,45 @@ //! ``` //! //! Also completes associated items, that require trait imports. +//! If any unresolved and/or partially-qualified path predeces the input, it will be taken into account: only the items with import string +//! containing this whole path will be considered and the corresponding path import will be added: +//! +//! ``` +//! mod foo { +//! pub mod bar { +//! pub struct Item; +//! +//! impl Item { +//! pub const TEST_ASSOC: usize = 3; +//! } +//! } +//! } +//! +//! fn main() { +//! bar::Item::TEST_A$0 +//! } +//! ``` +//! -> +//! ``` +//! use foo::bar; +//! +//! mod foo { +//! pub mod bar { +//! pub struct Item; +//! +//! impl Item { +//! pub const TEST_ASSOC: usize = 3; +//! } +//! } +//! } +//! +//! fn main() { +//! bar::Item::TEST_ASSOC +//! } +//! ``` +//! +//! NOTE: currently, if an assoc item comes from a trait that's not currently imported and it also has an unresolved and/or partially-qualified path, +//! no imports will be proposed. //! //! .Fuzzy search details //! -- cgit v1.2.3 From 33c83e72b9b48177a6171fd06a26676679963a4d Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 3 Mar 2021 01:26:53 +0200 Subject: Work towards better import labels --- crates/ide_completion/src/completions/flyimport.rs | 101 +++++++++++---------- crates/ide_completion/src/item.rs | 43 +++++---- crates/ide_completion/src/lib.rs | 17 ++-- crates/ide_completion/src/render.rs | 14 +-- 4 files changed, 92 insertions(+), 83 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 1ef6f8afb..c1e3f091f 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -87,11 +87,12 @@ //! Note that having this flag set to `true` does not guarantee that the feature is enabled: your client needs to have the corredponding //! capability enabled. -use hir::{AsAssocItem, ModPath, ModuleDef, ScopeDef}; +use hir::ModPath; use ide_db::helpers::{ import_assets::{ImportAssets, ImportCandidate}, insert_use::ImportScope, }; +use itertools::Itertools; use syntax::{AstNode, SyntaxNode, T}; use crate::{ @@ -130,27 +131,23 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) &ctx.sema, )?; - let mut all_imports = - import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind); - all_imports.sort_by_cached_key(|import| { - compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) - }); - - acc.add_all(all_imports.into_iter().filter_map(|import| { - let import_for_trait_assoc_item = import - .item_to_display() - .as_module_def_id() - .and_then(|module_def_id| { - ModuleDef::from(module_def_id).as_assoc_item(ctx.db)?.containing_trait(ctx.db) + acc.add_all( + import_assets + .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) + .into_iter() + .sorted_by_key(|located_import| { + compute_fuzzy_completion_order_key( + &located_import.import_path, + &user_input_lowercased, + ) }) - .is_some(); - let def_to_display = ScopeDef::from(import.item_to_display()); - render_resolution_with_import( - RenderContext::new(ctx), - ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }, - &def_to_display, - ) - })); + .filter_map(|import| { + render_resolution_with_import( + RenderContext::new(ctx), + ImportEdit { import, import_scope: import_scope.clone() }, + ) + }), + ); Some(()) } @@ -190,6 +187,7 @@ fn import_assets<'a>(ctx: &'a CompletionContext, fuzzy_name: String) -> Option, label: String, insert_text: Option, @@ -322,19 +322,22 @@ impl Builder { pub(crate) fn build(self) -> CompletionItem { let _p = profile::span("item::Builder::build"); - let mut label = self.label; - let mut lookup = self.lookup; - let mut insert_text = self.insert_text; - - if let Some(import_to_add) = self.import_to_add.as_ref() { - lookup = lookup.or_else(|| Some(label.clone())); - insert_text = insert_text.or_else(|| Some(label.clone())); - let display_path = import_to_add.import.display_path(); - if import_to_add.import_for_trait_assoc_item { - label = format!("{} ({})", label, display_path); - } else { - label = display_path.to_string(); - } + let label = self.label; + let lookup = self.lookup; + let insert_text = self.insert_text; + + if let Some(_import_to_add) = self.import_to_add.as_ref() { + todo!("todo kb") + // let import = &import_to_add.import; + // let item_to_import = import.item_to_import(); + // lookup = lookup.or_else(|| Some(label.clone())); + // insert_text = insert_text.or_else(|| Some(label.clone())); + // let display_path = import_to_add.import.display_path(); + // if import_to_add.import { + // label = format!("{} ({})", label, display_path); + // } else { + // label = display_path.to_string(); + // } } let text_edit = match self.text_edit { @@ -438,8 +441,8 @@ impl Builder { } } -impl<'a> Into for Builder { - fn into(self) -> CompletionItem { - self.build() - } -} +// impl<'a> Into for Builder { +// fn into(self) -> CompletionItem { +// self.build() +// } +// } diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index ca2e5e706..d19368de0 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -15,7 +15,7 @@ use completions::flyimport::position_for_import; use ide_db::{ base_db::FilePosition, helpers::{import_assets::LocatedImport, insert_use::ImportScope}, - imports_locator, RootDatabase, + items_locator, RootDatabase, }; use text_edit::TextEdit; @@ -141,7 +141,6 @@ pub fn resolve_completion_edits( position: FilePosition, full_import_path: &str, imported_name: String, - import_for_trait_assoc_item: bool, ) -> Option> { let ctx = CompletionContext::new(db, position, config)?; let position_for_import = position_for_import(&ctx, None)?; @@ -151,19 +150,17 @@ pub fn resolve_completion_edits( let current_crate = current_module.krate(); let (import_path, item_to_import) = - imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name) + items_locator::with_for_exact_name(&ctx.sema, current_crate, imported_name) + .into_iter() .filter_map(|candidate| { - let item: hir::ItemInNs = candidate.either(Into::into, Into::into); current_module - .find_use_path_prefixed(db, item, config.insert_use.prefix_kind) - .zip(Some(item)) + .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, item_to_import, None); + let import = LocatedImport::new(import_path, item_to_import, item_to_import); - ImportEdit { import_path, import_scope, import_for_trait_assoc_item } - .to_text_edit(config.insert_use) - .map(|edit| vec![edit]) + ImportEdit { import, import_scope }.to_text_edit(config.insert_use).map(|edit| vec![edit]) } #[cfg(test)] diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 4bddc3957..fae5685e2 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -53,18 +53,20 @@ pub(crate) fn render_resolution<'a>( pub(crate) fn render_resolution_with_import<'a>( ctx: RenderContext<'a>, import_edit: ImportEdit, - resolution: &ScopeDef, ) -> Option { + let resolution = ScopeDef::from(import_edit.import.original_item); let local_name = match resolution { ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), - _ => item_name(ctx.db(), import_edit.import.item_to_display())?.to_string(), + _ => item_name(ctx.db(), import_edit.import.original_item)?.to_string(), }; - Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { - item.completion_kind = CompletionKind::Magic; - item - }) + Render::new(ctx).render_resolution(local_name, Some(import_edit), &resolution).map( + |mut item| { + item.completion_kind = CompletionKind::Magic; + item + }, + ) } /// Interface for data and methods required for items rendering. -- cgit v1.2.3 From 24a5d3b19dfa3e076df8b7413d0cc4a547aeb7d7 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 3 Mar 2021 23:55:21 +0200 Subject: Fix the completion labels and tests --- crates/ide_completion/src/completions/flyimport.rs | 34 ++++++++++++------ crates/ide_completion/src/item.rs | 41 +++++++++++----------- crates/ide_completion/src/lib.rs | 7 ++-- 3 files changed, 48 insertions(+), 34 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index c1e3f091f..c5b3c9e27 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -144,7 +144,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) .filter_map(|import| { render_resolution_with_import( RenderContext::new(ctx), - ImportEdit { import, import_scope: import_scope.clone() }, + ImportEdit { import, scope: import_scope.clone() }, ) }), ); @@ -690,8 +690,8 @@ fn main() { } "#, expect![[r#" - fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED + fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED "#]], ); } @@ -807,7 +807,12 @@ fn main() { bar::baz::Ite$0 }"#; - check(fixture, expect![["st Item (foo::bar::baz::Item)"]]); + check( + fixture, + expect![[r#" + st foo::bar::baz::Item + "#]], + ); check_edit( "Item", @@ -825,8 +830,7 @@ fn main() { fn main() { bar::baz::Item - } - "#, + }"#, ); } @@ -845,7 +849,12 @@ fn main() { Item::TEST_A$0 }"#; - check(fixture, expect![["ct TEST_ASSOC (foo::bar::baz::Item)"]]); + check( + fixture, + expect![[r#" + ct TEST_ASSOC (foo::Item) + "#]], + ); check_edit( "TEST_ASSOC", @@ -863,8 +872,7 @@ mod foo { fn main() { Item::TEST_ASSOC -} -"#, +}"#, ); } @@ -885,7 +893,12 @@ fn main() { bar::Item::TEST_A$0 }"#; - check(fixture, expect![["ct TEST_ASSOC (foo::bar::baz::Item)"]]); + check( + fixture, + expect![[r#" + ct TEST_ASSOC (foo::bar::Item) + "#]], + ); check_edit( "TEST_ASSOC", @@ -905,8 +918,7 @@ mod foo { fn main() { bar::Item::TEST_ASSOC -} -"#, +}"#, ); } } diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index d01620500..44e4a6dfd 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -11,7 +11,7 @@ use ide_db::{ }, SymbolKind, }; -use stdx::{impl_from, never}; +use stdx::{format_to, impl_from, never}; use syntax::{algo, TextRange}; use text_edit::TextEdit; @@ -274,7 +274,7 @@ impl CompletionItem { #[derive(Debug, Clone)] pub struct ImportEdit { pub import: LocatedImport, - pub import_scope: ImportScope, + pub scope: ImportScope, } impl ImportEdit { @@ -284,7 +284,7 @@ impl ImportEdit { let _p = profile::span("ImportEdit::to_text_edit"); let rewriter = insert_use::insert_use( - &self.import_scope, + &self.scope, mod_path_to_ast(&self.import.import_path), cfg, ); @@ -302,7 +302,6 @@ impl ImportEdit { pub(crate) struct Builder { source_range: TextRange, completion_kind: CompletionKind, - // TODO kb also add a db here, to resolve the completion label? import_to_add: Option, label: String, insert_text: Option, @@ -322,22 +321,24 @@ impl Builder { pub(crate) fn build(self) -> CompletionItem { let _p = profile::span("item::Builder::build"); - let label = self.label; - let lookup = self.lookup; - let insert_text = self.insert_text; - - if let Some(_import_to_add) = self.import_to_add.as_ref() { - todo!("todo kb") - // let import = &import_to_add.import; - // let item_to_import = import.item_to_import(); - // lookup = lookup.or_else(|| Some(label.clone())); - // insert_text = insert_text.or_else(|| Some(label.clone())); - // let display_path = import_to_add.import.display_path(); - // if import_to_add.import { - // label = format!("{} ({})", label, display_path); - // } else { - // label = display_path.to_string(); - // } + let mut label = self.label; + let mut lookup = self.lookup; + let mut insert_text = self.insert_text; + + if let Some(original_path) = self + .import_to_add + .as_ref() + .and_then(|import_edit| import_edit.import.original_path.as_ref()) + { + lookup = lookup.or_else(|| Some(label.clone())); + insert_text = insert_text.or_else(|| Some(label.clone())); + + let original_path_label = original_path.to_string(); + if original_path_label.ends_with(&label) { + label = original_path_label; + } else { + format_to!(label, " ({})", original_path) + } } let text_edit = match self.text_edit { diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index d19368de0..5470914fb 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -144,7 +144,7 @@ pub fn resolve_completion_edits( ) -> Option> { let ctx = CompletionContext::new(db, position, config)?; let position_for_import = position_for_import(&ctx, None)?; - let import_scope = ImportScope::find_insert_use_container(position_for_import, &ctx.sema)?; + let scope = ImportScope::find_insert_use_container(position_for_import, &ctx.sema)?; let current_module = ctx.sema.scope(position_for_import).module()?; let current_crate = current_module.krate(); @@ -158,9 +158,10 @@ pub fn resolve_completion_edits( .zip(Some(candidate)) }) .find(|(mod_path, _)| mod_path.to_string() == full_import_path)?; - let import = LocatedImport::new(import_path, item_to_import, item_to_import); + let import = + LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path)); - ImportEdit { import, import_scope }.to_text_edit(config.insert_use).map(|edit| vec![edit]) + ImportEdit { import, scope }.to_text_edit(config.insert_use).map(|edit| vec![edit]) } #[cfg(test)] -- cgit v1.2.3 From 6ca6f101c1b3a795ff6578bae6e01cb4b818e14c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 4 Mar 2021 00:10:20 +0200 Subject: Test for fuzzy unresolved path maatch --- crates/ide_completion/src/completions/flyimport.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index c5b3c9e27..efb91fe0e 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -921,4 +921,26 @@ fn main() { }"#, ); } + + #[test] + fn fuzzy_unresolved_path() { + check( + r#" +mod foo { + pub mod bar { + pub struct Item; + + impl Item { + pub const TEST_ASSOC: usize = 3; + } + } +} + +fn main() { + let zz = "sdsd"; + bar::Ass$0 +}"#, + expect![[]], + ) + } } -- cgit v1.2.3 From 84c575a21201cdbeb391ff2cfae2fbbccaa76f8a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 5 Mar 2021 00:11:07 +0200 Subject: Restrict fuzzy qualifiers for now --- crates/ide_completion/src/completions/flyimport.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index efb91fe0e..8a11cba41 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -21,8 +21,9 @@ //! ``` //! //! Also completes associated items, that require trait imports. -//! If any unresolved and/or partially-qualified path predeces the input, it will be taken into account: only the items with import string -//! containing this whole path will be considered and the corresponding path import will be added: +//! If any unresolved and/or partially-qualified path predeces the input, it will be taken into account. +//! Currently, only the imports with their import path ending with the whole qialifier will be proposed +//! (no fuzzy matching for qualifier). //! //! ``` //! mod foo { @@ -187,7 +188,6 @@ fn import_assets<'a>(ctx: &'a CompletionContext, fuzzy_name: String) -> Option Date: Fri, 5 Mar 2021 00:29:39 +0200 Subject: Cleanup --- crates/ide_completion/src/item.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 44e4a6dfd..06f16a2c7 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -441,9 +441,3 @@ impl Builder { self } } - -// impl<'a> Into for Builder { -// fn into(self) -> CompletionItem { -// self.build() -// } -// } -- cgit v1.2.3 From db61d4ea13113cd6c4e0661075ea9b2f739be862 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 7 Mar 2021 11:58:43 +0200 Subject: Rebase leftovers --- crates/ide_completion/src/item.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 06f16a2c7..9b039e3e5 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -283,11 +283,8 @@ impl ImportEdit { pub fn to_text_edit(&self, cfg: InsertUseConfig) -> Option { let _p = profile::span("ImportEdit::to_text_edit"); - let rewriter = insert_use::insert_use( - &self.scope, - mod_path_to_ast(&self.import.import_path), - cfg, - ); + let rewriter = + insert_use::insert_use(&self.scope, mod_path_to_ast(&self.import.import_path), cfg); let old_ast = rewriter.rewrite_root()?; let mut import_insert = TextEdit::builder(); algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut import_insert); -- cgit v1.2.3 From dccbb38d2e28bfeb53f31c13de3b83e72f1a476c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 8 Mar 2021 00:25:45 +0200 Subject: Less lifetines: derive SemanticsScope in place --- crates/ide_completion/src/completions/flyimport.rs | 11 ++++++++--- crates/ide_completion/src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/ide_completion') diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 8a11cba41..391a11c91 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -169,23 +169,28 @@ pub(crate) fn position_for_import<'a>( }) } -fn import_assets<'a>(ctx: &'a CompletionContext, fuzzy_name: String) -> Option> { +fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option { let current_module = ctx.scope.module()?; if let Some(dot_receiver) = &ctx.dot_receiver { ImportAssets::for_fuzzy_method_call( current_module, ctx.sema.type_of_expr(dot_receiver)?, fuzzy_name, - ctx.scope.clone(), + dot_receiver.syntax().clone(), ) } else { let fuzzy_name_length = fuzzy_name.len(); + let approximate_node = match current_module.definition_source(ctx.db).value { + hir::ModuleSource::SourceFile(s) => s.syntax().clone(), + hir::ModuleSource::Module(m) => m.syntax().clone(), + hir::ModuleSource::BlockExpr(b) => b.syntax().clone(), + }; let assets_for_path = ImportAssets::for_fuzzy_path( current_module, ctx.path_qual.clone(), fuzzy_name, &ctx.sema, - ctx.scope.clone(), + approximate_node, )?; if matches!(assets_for_path.import_candidate(), ImportCandidate::Path(_)) diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 5470914fb..a0c8c374d 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs @@ -150,7 +150,7 @@ pub fn resolve_completion_edits( let current_crate = current_module.krate(); let (import_path, item_to_import) = - items_locator::with_for_exact_name(&ctx.sema, current_crate, imported_name) + items_locator::with_exact_name(&ctx.sema, current_crate, imported_name) .into_iter() .filter_map(|candidate| { current_module -- cgit v1.2.3