mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 19:17:12 +00:00
Cleanup Name string rendering
This commit is contained in:
parent
c78cc2baa9
commit
76585539f5
38 changed files with 145 additions and 249 deletions
|
|
@ -794,7 +794,7 @@ impl NameRefClass {
|
|||
hir::AssocItem::TypeAlias(it) => Some(it),
|
||||
_ => None,
|
||||
})
|
||||
.find(|alias| alias.name(sema.db).eq_ident(name_ref.text().as_str()))
|
||||
.find(|alias| alias.name(sema.db).as_str() == name_ref.text().trim_start_matches("r#"))
|
||||
{
|
||||
// No substitution, this can only occur in type position.
|
||||
return Some(NameRefClass::Definition(Definition::TypeAlias(ty), None));
|
||||
|
|
|
|||
|
|
@ -214,14 +214,15 @@ impl FamousDefs<'_, '_> {
|
|||
for segment in path {
|
||||
module = module.children(db).find_map(|child| {
|
||||
let name = child.name(db)?;
|
||||
if name.eq_ident(segment) {
|
||||
if name.as_str() == segment {
|
||||
Some(child)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
}
|
||||
let def = module.scope(db, None).into_iter().find(|(name, _def)| name.eq_ident(trait_))?.1;
|
||||
let def =
|
||||
module.scope(db, None).into_iter().find(|(name, _def)| name.as_str() == trait_)?.1;
|
||||
Some(def)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -263,13 +263,12 @@ 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().display(sema.db)),
|
||||
format!("../{new_name}"),
|
||||
)),
|
||||
(true, _, Some(mod_name)) => {
|
||||
Some((format!("../{}", mod_name.as_str()), format!("../{new_name}")))
|
||||
}
|
||||
// The anchor is on the same level as target dir
|
||||
(false, true, Some(mod_name)) => {
|
||||
Some((mod_name.unescaped().display(sema.db).to_string(), new_name.to_owned()))
|
||||
Some((mod_name.as_str().to_owned(), new_name.to_owned()))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ impl<'a> FindUsages<'a> {
|
|||
let _p = tracing::info_span!("collect_possible_aliases").entered();
|
||||
|
||||
let db = sema.db;
|
||||
let container_name = container.name(db).unescaped().display(db).to_smolstr();
|
||||
let container_name = container.name(db).as_str().to_smolstr();
|
||||
let search_scope = Definition::from(container).search_scope(db);
|
||||
let mut seen = FxHashSet::default();
|
||||
let mut completed = FxHashSet::default();
|
||||
|
|
@ -925,12 +925,8 @@ impl<'a> FindUsages<'a> {
|
|||
.or_else(|| ty.as_builtin().map(|builtin| builtin.name()))
|
||||
})
|
||||
};
|
||||
// We need to unescape the name in case it is written without "r#" in earlier
|
||||
// editions of Rust where it isn't a keyword.
|
||||
self.def
|
||||
.name(sema.db)
|
||||
.or_else(self_kw_refs)
|
||||
.map(|it| it.unescaped().display(sema.db).to_smolstr())
|
||||
// We need to search without the `r#`, hence `as_str` access.
|
||||
self.def.name(sema.db).or_else(self_kw_refs).map(|it| it.as_str().to_smolstr())
|
||||
}
|
||||
};
|
||||
let name = match &name {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl TryEnum {
|
|||
_ => return None,
|
||||
};
|
||||
TryEnum::ALL.iter().find_map(|&var| {
|
||||
if enum_.name(sema.db).eq_ident(var.type_name()) {
|
||||
if enum_.name(sema.db).as_str() == var.type_name() {
|
||||
return Some(var);
|
||||
}
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue