aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/imp.rs26
-rw-r--r--crates/ra_analysis/src/lib.rs7
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs21
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 {
288 Some(it) => it, 288 Some(it) => it,
289 }; 289 };
290 290
291 let mut ret = vec![(position.file_id, binding.syntax().range())]; 291 let mut ret = binding
292 .name()
293 .into_iter()
294 .map(|name| (position.file_id, name.syntax().range()))
295 .collect::<Vec<_>>();
292 ret.extend( 296 ret.extend(
293 descr 297 descr
294 .scopes(&*self.db) 298 .scopes(&*self.db)
@@ -505,7 +509,25 @@ impl AnalysisImpl {
505 let infer = function.infer(&*self.db)?; 509 let infer = function.infer(&*self.db)?;
506 Ok(infer.type_of_node(node).map(|t| t.to_string())) 510 Ok(infer.type_of_node(node).map(|t| t.to_string()))
507 } 511 }
508 512 pub fn rename(
513 &self,
514 position: FilePosition,
515 new_name: &str,
516 ) -> Cancelable<Vec<SourceFileEdit>> {
517 let res = self
518 .find_all_refs(position)?
519 .iter()
520 .map(|(file_id, text_range)| SourceFileEdit {
521 file_id: *file_id,
522 edit: {
523 let mut builder = ra_text_edit::TextEditBuilder::new();
524 builder.replace(*text_range, new_name.into());
525 builder.finish()
526 },
527 })
528 .collect::<Vec<_>>();
529 Ok(res)
530 }
509 fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> { 531 fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileSymbol)>> {
510 let name = name_ref.text(); 532 let name = name_ref.text();
511 let mut query = Query::new(name.to_string()); 533 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 {
367 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { 367 pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> {
368 self.imp.type_of(frange) 368 self.imp.type_of(frange)
369 } 369 }
370 pub fn rename(
371 &self,
372 position: FilePosition,
373 new_name: &str,
374 ) -> Cancelable<Vec<SourceFileEdit>> {
375 self.imp.rename(position, new_name)
376 }
370} 377}
371 378
372pub struct LibraryData { 379pub 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<Option<
557 .into()); 557 .into());
558 } 558 }
559 559
560 let refs = world 560 let renames = world
561 .analysis() 561 .analysis()
562 .find_all_refs(FilePosition { file_id, offset })?; 562 .rename(FilePosition { file_id, offset }, &*params.new_name)?;
563 if refs.is_empty() { 563 if renames.is_empty() {
564 return Ok(None); 564 return Ok(None);
565 } 565 }
566 566
567 let mut changes = HashMap::new(); 567 let mut changes = HashMap::new();
568 for r in refs { 568 for edit in renames {
569 if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { 569 changes
570 changes 570 .entry(file_id.try_conv_with(&world)?)
571 .entry(loc.uri) 571 .or_insert_with(Vec::new)
572 .or_insert_with(Vec::new) 572 .extend(edit.edit.conv_with(&line_index));
573 .push(TextEdit {
574 range: loc.range,
575 new_text: params.new_name.clone(),
576 });
577 }
578 } 573 }
579 574
580 Ok(Some(WorkspaceEdit { 575 Ok(Some(WorkspaceEdit {