diff --git a/crates/ide-completion/src/item.rs b/crates/ide-completion/src/item.rs index b982322a73..de41a5bd70 100644 --- a/crates/ide-completion/src/item.rs +++ b/crates/ide-completion/src/item.rs @@ -458,13 +458,11 @@ impl Builder { } if let [import_edit] = &*self.imports_to_add { // snippets can have multiple imports, but normal completions only have up to one - if let Some(original_path) = import_edit.original_path.as_ref() { - label_detail.replace(SmolStr::from(format!( - "{} (use {})", - label_detail.as_deref().unwrap_or_default(), - original_path.display(db) - ))); - } + label_detail.replace(SmolStr::from(format!( + "{} (use {})", + label_detail.as_deref().unwrap_or_default(), + import_edit.import_path.display(db) + ))); } else if let Some(trait_name) = self.trait_name { label_detail.replace(SmolStr::from(format!( "{} (as {trait_name})", diff --git a/crates/ide-completion/src/snippet.rs b/crates/ide-completion/src/snippet.rs index 50618296ee..e667e2e016 100644 --- a/crates/ide-completion/src/snippet.rs +++ b/crates/ide-completion/src/snippet.rs @@ -181,7 +181,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option 1).then(|| LocatedImport::new(path.clone(), item, item, None))) + Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item))) }; let mut res = Vec::with_capacity(requires.len()); for import in requires { diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index 9a4a94a245..c58374f2e8 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -597,8 +597,8 @@ fn main() { } "#, expect![[r#" - ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED + ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED "#]], ); } @@ -717,7 +717,7 @@ fn main() { check( fixture, expect![[r#" - st Item (use foo::bar::baz::Item) Item + st Item (use foo::bar) Item "#]], ); @@ -725,19 +725,19 @@ fn main() { "Item", fixture, r#" - use foo::bar; +use foo::bar; - mod foo { - pub mod bar { - pub mod baz { - pub struct Item; - } - } +mod foo { + pub mod bar { + pub mod baz { + pub struct Item; } + } +} - fn main() { - bar::baz::Item - }"#, +fn main() { + bar::baz::Item +}"#, ); } @@ -803,7 +803,7 @@ fn main() { check( fixture, expect![[r#" - ct TEST_ASSOC (use foo::bar::Item) usize + ct TEST_ASSOC (use foo::bar) usize "#]], ); diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs index 04263d15d0..e92af12980 100644 --- a/crates/ide-db/src/imports/import_assets.rs +++ b/crates/ide-db/src/imports/import_assets.rs @@ -195,18 +195,11 @@ pub struct LocatedImport { /// the original item is the associated constant, but the import has to be a trait that /// defines this constant. pub original_item: ItemInNs, - /// A path of the original item. - pub original_path: Option, } impl LocatedImport { - pub fn new( - import_path: ModPath, - item_to_import: ItemInNs, - original_item: ItemInNs, - original_path: Option, - ) -> Self { - Self { import_path, item_to_import, original_item, original_path } + pub fn new(import_path: ModPath, item_to_import: ItemInNs, original_item: ItemInNs) -> Self { + Self { import_path, item_to_import, original_item } } } @@ -351,7 +344,7 @@ fn path_applicable_imports( ) .filter_map(|item| { let mod_path = mod_path(item)?; - Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path))) + Some(LocatedImport::new(mod_path, item, item)) }) .collect() } @@ -416,24 +409,15 @@ fn import_for_item( // especially in case of lazy completion edit resolutions. return None; } - (false, Some(trait_to_import)) => LocatedImport::new( - mod_path(trait_to_import)?, - trait_to_import, - original_item, - mod_path(original_item), - ), - (true, None) => LocatedImport::new( - import_path_candidate, - original_item_candidate, - original_item, - mod_path(original_item), - ), - (false, None) => LocatedImport::new( - mod_path(segment_import)?, - segment_import, - original_item, - mod_path(original_item), - ), + (false, Some(trait_to_import)) => { + LocatedImport::new(mod_path(trait_to_import)?, trait_to_import, original_item) + } + (true, None) => { + LocatedImport::new(import_path_candidate, original_item_candidate, original_item) + } + (false, None) => { + LocatedImport::new(mod_path(segment_import)?, segment_import, original_item) + } }) } @@ -550,7 +534,6 @@ fn trait_applicable_items( mod_path(trait_item)?, trait_item, original_item, - mod_path(original_item), )); } None::<()> @@ -573,7 +556,6 @@ fn trait_applicable_items( mod_path(trait_item)?, trait_item, original_item, - mod_path(original_item), )); } None::<()>