fix: remove useless loop

This commit is contained in:
roife 2024-03-15 19:54:58 +08:00
parent 5b2809f329
commit de716058c9

View File

@ -314,20 +314,18 @@ impl Module {
) { ) {
let mod_name = self.name; let mod_name = self.name;
let out_of_sel = |node: &SyntaxNode| !self.text_range.contains_range(node.text_range()); let out_of_sel = |node: &SyntaxNode| !self.text_range.contains_range(node.text_range());
for (file_id, refs) in node_def.usages(&ctx.sema).all() { for (file_id, refs) in node_def.usages(&ctx.sema).all() {
let source_file = ctx.sema.parse(file_id); let source_file = ctx.sema.parse(file_id);
let usages = refs.into_iter().filter_map(|FileReference { range, name, .. }| { let usages = refs.into_iter().filter_map(|FileReference { range, name, .. }| {
let path: ast::Path = find_node_at_range(source_file.syntax(), range)?; // handle normal usages
let name_ref = find_node_at_range::<ast::NameRef>(source_file.syntax(), range)?;
let name = name.syntax().to_string(); let name = name.syntax().to_string();
for desc in path.syntax().descendants() { if out_of_sel(name_ref.syntax()) {
if desc.to_string() == name && out_of_sel(&desc) {
if let Some(name_ref) = ast::NameRef::cast(desc) {
let new_ref = format!("{mod_name}::{name_ref}"); let new_ref = format!("{mod_name}::{name_ref}");
return Some((name_ref.syntax().text_range(), new_ref)); return Some((name_ref.syntax().text_range(), new_ref));
} }
}
}
None None
}); });