Skip to content

Commit 18591ae

Browse files
committed
Always render the path to be imported in the completion detail
1 parent 3aa6306 commit 18591ae

File tree

4 files changed

+31
-51
lines changed

4 files changed

+31
-51
lines changed

crates/ide-completion/src/item.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,11 @@ impl Builder {
458458
}
459459
if let [import_edit] = &*self.imports_to_add {
460460
// snippets can have multiple imports, but normal completions only have up to one
461-
if let Some(original_path) = import_edit.original_path.as_ref() {
462-
label_detail.replace(SmolStr::from(format!(
463-
"{} (use {})",
464-
label_detail.as_deref().unwrap_or_default(),
465-
original_path.display(db)
466-
)));
467-
}
461+
label_detail.replace(SmolStr::from(format!(
462+
"{} (use {})",
463+
label_detail.as_deref().unwrap_or_default(),
464+
import_edit.import_path.display(db)
465+
)));
468466
} else if let Some(trait_name) = self.trait_name {
469467
label_detail.replace(SmolStr::from(format!(
470468
"{} (as {trait_name})",

crates/ide-completion/src/snippet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
181181
ctx.config.prefer_no_std,
182182
ctx.config.prefer_prelude,
183183
)?;
184-
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
184+
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item)))
185185
};
186186
let mut res = Vec::with_capacity(requires.len());
187187
for import in requires {

crates/ide-completion/src/tests/flyimport.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ fn main() {
597597
}
598598
"#,
599599
expect![[r#"
600-
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
601600
fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
601+
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
602602
"#]],
603603
);
604604
}
@@ -717,27 +717,27 @@ fn main() {
717717
check(
718718
fixture,
719719
expect![[r#"
720-
st Item (use foo::bar::baz::Item) Item
720+
st Item (use foo::bar) Item
721721
"#]],
722722
);
723723

724724
check_edit(
725725
"Item",
726726
fixture,
727727
r#"
728-
use foo::bar;
728+
use foo::bar;
729729
730-
mod foo {
731-
pub mod bar {
732-
pub mod baz {
733-
pub struct Item;
734-
}
735-
}
730+
mod foo {
731+
pub mod bar {
732+
pub mod baz {
733+
pub struct Item;
736734
}
735+
}
736+
}
737737
738-
fn main() {
739-
bar::baz::Item
740-
}"#,
738+
fn main() {
739+
bar::baz::Item
740+
}"#,
741741
);
742742
}
743743

@@ -803,7 +803,7 @@ fn main() {
803803
check(
804804
fixture,
805805
expect![[r#"
806-
ct TEST_ASSOC (use foo::bar::Item) usize
806+
ct TEST_ASSOC (use foo::bar) usize
807807
"#]],
808808
);
809809

crates/ide-db/src/imports/import_assets.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,11 @@ pub struct LocatedImport {
195195
/// the original item is the associated constant, but the import has to be a trait that
196196
/// defines this constant.
197197
pub original_item: ItemInNs,
198-
/// A path of the original item.
199-
pub original_path: Option<ModPath>,
200198
}
201199

202200
impl LocatedImport {
203-
pub fn new(
204-
import_path: ModPath,
205-
item_to_import: ItemInNs,
206-
original_item: ItemInNs,
207-
original_path: Option<ModPath>,
208-
) -> Self {
209-
Self { import_path, item_to_import, original_item, original_path }
201+
pub fn new(import_path: ModPath, item_to_import: ItemInNs, original_item: ItemInNs) -> Self {
202+
Self { import_path, item_to_import, original_item }
210203
}
211204
}
212205

@@ -351,7 +344,7 @@ fn path_applicable_imports(
351344
)
352345
.filter_map(|item| {
353346
let mod_path = mod_path(item)?;
354-
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
347+
Some(LocatedImport::new(mod_path, item, item))
355348
})
356349
.collect()
357350
}
@@ -416,24 +409,15 @@ fn import_for_item(
416409
// especially in case of lazy completion edit resolutions.
417410
return None;
418411
}
419-
(false, Some(trait_to_import)) => LocatedImport::new(
420-
mod_path(trait_to_import)?,
421-
trait_to_import,
422-
original_item,
423-
mod_path(original_item),
424-
),
425-
(true, None) => LocatedImport::new(
426-
import_path_candidate,
427-
original_item_candidate,
428-
original_item,
429-
mod_path(original_item),
430-
),
431-
(false, None) => LocatedImport::new(
432-
mod_path(segment_import)?,
433-
segment_import,
434-
original_item,
435-
mod_path(original_item),
436-
),
412+
(false, Some(trait_to_import)) => {
413+
LocatedImport::new(mod_path(trait_to_import)?, trait_to_import, original_item)
414+
}
415+
(true, None) => {
416+
LocatedImport::new(import_path_candidate, original_item_candidate, original_item)
417+
}
418+
(false, None) => {
419+
LocatedImport::new(mod_path(segment_import)?, segment_import, original_item)
420+
}
437421
})
438422
}
439423

@@ -550,7 +534,6 @@ fn trait_applicable_items(
550534
mod_path(trait_item)?,
551535
trait_item,
552536
original_item,
553-
mod_path(original_item),
554537
));
555538
}
556539
None::<()>
@@ -573,7 +556,6 @@ fn trait_applicable_items(
573556
mod_path(trait_item)?,
574557
trait_item,
575558
original_item,
576-
mod_path(original_item),
577559
));
578560
}
579561
None::<()>

0 commit comments

Comments
 (0)