Fix associated items not being appended to paths in import_assets

This commit is contained in:
Lukas Wirth 2021-03-18 21:36:52 +01:00
parent 816bc73895
commit 34464ede3f
2 changed files with 40 additions and 3 deletions

View file

@ -208,8 +208,10 @@ fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
format!("Qualify as `{}`", import.import_path)
}
}
ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path),
ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path),
ImportCandidate::TraitAssocItem(_) => {
format!("Qualify with `{}`", import.import_path)
}
ImportCandidate::TraitMethod(_) => format!("Qualify with `{}`", import.import_path),
}
}
@ -543,6 +545,37 @@ fn main() {
);
}
#[test]
fn associated_struct_const_unqualified() {
check_assist(
qualify_path,
r"
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
const TEST_CONST: u8 = 42;
}
}
fn main() {
TEST_CONST$0
}
",
r"
mod test_mod {
pub struct TestStruct {}
impl TestStruct {
const TEST_CONST: u8 = 42;
}
}
fn main() {
test_mod::TestStruct::TEST_CONST
}
",
);
}
#[test]
fn associated_trait_function() {
check_assist(

View file

@ -304,7 +304,11 @@ fn path_applicable_imports(
return items_with_candidate_name
.into_iter()
.filter_map(|item| {
Some(LocatedImport::new(mod_path(item)?, item, item, mod_path(item)))
let mut mod_path = mod_path(item)?;
if let Some(assoc_item) = item_as_assoc(db, item) {
mod_path.push_segment(assoc_item.name(db)?);
}
Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
})
.collect();
}