mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Always render the path to be imported in the completion detail
This commit is contained in:
parent
3aa6306728
commit
18591ae5c8
4 changed files with 31 additions and 51 deletions
|
@ -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})",
|
||||
|
|
|
@ -181,7 +181,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
|
|||
ctx.config.prefer_no_std,
|
||||
ctx.config.prefer_prelude,
|
||||
)?;
|
||||
Some((path.len() > 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 {
|
||||
|
|
|
@ -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
|
||||
"#]],
|
||||
);
|
||||
|
||||
|
|
|
@ -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<ModPath>,
|
||||
}
|
||||
|
||||
impl LocatedImport {
|
||||
pub fn new(
|
||||
import_path: ModPath,
|
||||
item_to_import: ItemInNs,
|
||||
original_item: ItemInNs,
|
||||
original_path: Option<ModPath>,
|
||||
) -> 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::<()>
|
||||
|
|
Loading…
Reference in a new issue