From c402b007a3272efada7924fce4eecf698b98968b Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Sun, 30 Dec 2018 18:14:55 +0000 Subject: Move renames into ra_analysis --- crates/ra_analysis/src/imp.rs | 26 ++++++++++++++++++++++++-- crates/ra_analysis/src/lib.rs | 7 +++++++ crates/ra_lsp_server/src/main_loop/handlers.rs | 21 ++++++++------------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index bff2e00c9..5ed374c79 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -288,7 +288,11 @@ impl AnalysisImpl { Some(it) => it, }; - let mut ret = vec![(position.file_id, binding.syntax().range())]; + let mut ret = binding + .name() + .into_iter() + .map(|name| (position.file_id, name.syntax().range())) + .collect::>(); ret.extend( descr .scopes(&*self.db) @@ -505,7 +509,25 @@ impl AnalysisImpl { let infer = function.infer(&*self.db)?; Ok(infer.type_of_node(node).map(|t| t.to_string())) } - + pub fn rename( + &self, + position: FilePosition, + new_name: &str, + ) -> Cancelable> { + let res = self + .find_all_refs(position)? + .iter() + .map(|(file_id, text_range)| SourceFileEdit { + file_id: *file_id, + edit: { + let mut builder = ra_text_edit::TextEditBuilder::new(); + builder.replace(*text_range, new_name.into()); + builder.finish() + }, + }) + .collect::>(); + Ok(res) + } fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable> { let name = name_ref.text(); let mut query = Query::new(name.to_string()); diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9f5e9f358..e56168510 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -367,6 +367,13 @@ impl Analysis { pub fn type_of(&self, frange: FileRange) -> Cancelable> { self.imp.type_of(frange) } + pub fn rename( + &self, + position: FilePosition, + new_name: &str, + ) -> Cancelable> { + self.imp.rename(position, new_name) + } } pub struct LibraryData { diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a2c12a4c1..3b7a14a5c 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -557,24 +557,19 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result