From c5be0b2589e5ed732ae5001122e453f0903bfdf2 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 9 Feb 2021 16:03:39 +0100 Subject: Use NameLike in FileReference directly as its not exported from ide anymore --- crates/ide/src/lib.rs | 2 +- crates/ide/src/references.rs | 8 ++------ crates/ide/src/references/rename.rs | 12 +++++------- 3 files changed, 8 insertions(+), 14 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index a245d9341..592b12925 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -94,7 +94,7 @@ pub use ide_db::{ call_info::CallInfo, label::Label, line_index::{LineCol, LineIndex}, - search::{FileReference, ReferenceAccess, SearchScope}, + search::{ReferenceAccess, SearchScope}, source_change::{FileSystemEdit, SourceChange}, symbol_index::Query, RootDatabase, diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index f96fac9c1..77c208be9 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -66,12 +66,8 @@ pub(crate) fn find_all_refs( let mut usages = def.usages(sema).set_scope(search_scope).all(); if let Some(ctor_filter) = ctor_filter { // filter for constructor-literals - usages.references.iter_mut().for_each(|(&file_id, it)| { - let root = sema.parse(file_id); - let root = root.syntax(); - it.retain(|reference| { - reference.as_name_ref(root).map_or(false, |name_ref| ctor_filter(&name_ref)) - }) + usages.references.values_mut().for_each(|it| { + it.retain(|reference| reference.name.as_name_ref().map_or(false, ctor_filter)); }); usages.references.retain(|_, it| !it.is_empty()); } diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 64992c72d..b04214291 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs @@ -164,20 +164,18 @@ fn find_definition( } fn source_edit_from_references( - sema: &Semantics, + _sema: &Semantics, file_id: FileId, references: &[FileReference], def: Definition, new_name: &str, ) -> (FileId, TextEdit) { - let root = sema.parse(file_id); let mut edit = TextEdit::builder(); for reference in references { - let (range, replacement) = match &reference.name_from_syntax(root.syntax()) { - Some(NameLike::Name(_)) => (None, format!("{}", new_name)), - Some(NameLike::NameRef(name_ref)) => source_edit_from_name_ref(name_ref, new_name, def), - Some(NameLike::Lifetime(_)) => (None, format!("{}", new_name)), - None => (None, new_name.to_owned()), + let (range, replacement) = match &reference.name { + NameLike::Name(_) => (None, format!("{}", new_name)), + NameLike::NameRef(name_ref) => source_edit_from_name_ref(name_ref, new_name, def), + NameLike::Lifetime(_) => (None, format!("{}", new_name)), }; // FIXME: Some(range) will be incorrect when we are inside macros edit.replace(range.unwrap_or(reference.range), replacement); -- cgit v1.2.3