internal: Replace Display impl for Name

This commit is contained in:
Lukas Wirth 2023-05-24 18:04:29 +02:00
parent 2f840c2236
commit c7ef6c25b7
108 changed files with 1045 additions and 656 deletions

View file

@ -362,12 +362,12 @@ fn import_for_item(
let original_item_candidate = item_for_path_search(db, original_item)?;
let import_path_candidate = mod_path(original_item_candidate)?;
let import_path_string = import_path_candidate.to_string();
let import_path_string = import_path_candidate.display(db).to_string();
let expected_import_end = if item_as_assoc(db, original_item).is_some() {
unresolved_qualifier.to_string()
} else {
format!("{unresolved_qualifier}::{}", item_name(db, original_item)?)
format!("{unresolved_qualifier}::{}", item_name(db, original_item)?.display(db))
};
if !import_path_string.contains(unresolved_first_segment)
|| !import_path_string.ends_with(&expected_import_end)

View file

@ -202,12 +202,13 @@ fn rename_mod(
// - Module has submodules defined in separate files
let dir_paths = match (is_mod_rs, has_detached_child, module.name(sema.db)) {
// Go up one level since the anchor is inside the dir we're trying to rename
(true, _, Some(mod_name)) => {
Some((format!("../{}", mod_name.unescaped()), format!("../{new_name}")))
}
(true, _, Some(mod_name)) => Some((
format!("../{}", mod_name.unescaped().display(sema.db)),
format!("../{new_name}"),
)),
// The anchor is on the same level as target dir
(false, true, Some(mod_name)) => {
Some((mod_name.unescaped().to_string(), new_name.to_owned()))
Some((mod_name.unescaped().display(sema.db).to_string(), new_name.to_owned()))
}
_ => None,
};

View file

@ -38,15 +38,15 @@ pub fn get_missing_assoc_items(
for item in imp.items(sema.db) {
match item {
hir::AssocItem::Function(it) => {
impl_fns_consts.insert(it.name(sema.db).to_string());
impl_fns_consts.insert(it.name(sema.db).display(sema.db).to_string());
}
hir::AssocItem::Const(it) => {
if let Some(name) = it.name(sema.db) {
impl_fns_consts.insert(name.to_string());
impl_fns_consts.insert(name.display(sema.db).to_string());
}
}
hir::AssocItem::TypeAlias(it) => {
impl_type.insert(it.name(sema.db).to_string());
impl_type.insert(it.name(sema.db).display(sema.db).to_string());
}
}
}
@ -57,12 +57,14 @@ pub fn get_missing_assoc_items(
.into_iter()
.filter(|i| match i {
hir::AssocItem::Function(f) => {
!impl_fns_consts.contains(&f.name(sema.db).to_string())
!impl_fns_consts.contains(&f.name(sema.db).display(sema.db).to_string())
}
hir::AssocItem::TypeAlias(t) => {
!impl_type.contains(&t.name(sema.db).display(sema.db).to_string())
}
hir::AssocItem::TypeAlias(t) => !impl_type.contains(&t.name(sema.db).to_string()),
hir::AssocItem::Const(c) => c
.name(sema.db)
.map(|n| !impl_fns_consts.contains(&n.to_string()))
.map(|n| !impl_fns_consts.contains(&n.display(sema.db).to_string()))
.unwrap_or_default(),
})
.collect()
@ -137,7 +139,7 @@ mod tests {
sema.find_node_at_offset_with_descend(file.syntax(), position.offset).unwrap();
let trait_ = crate::traits::resolve_target_trait(&sema, &impl_block);
let actual = match trait_ {
Some(trait_) => trait_.name(&db).to_string(),
Some(trait_) => trait_.name(&db).display(&db).to_string(),
None => String::new(),
};
expect.assert_eq(&actual);
@ -152,7 +154,7 @@ mod tests {
let items = crate::traits::get_missing_assoc_items(&sema, &impl_block);
let actual = items
.into_iter()
.map(|item| item.name(&db).unwrap().to_string())
.map(|item| item.name(&db).unwrap().display(&db).to_string())
.collect::<Vec<_>>()
.join("\n");
expect.assert_eq(&actual);