diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-30 20:43:58 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-30 20:43:58 +0000 |
commit | acc61cc28461b72e8a03869b0ad60c144b4b3b20 (patch) | |
tree | 72d9523c52aca48aac9dd8c5524bb044f547002b /crates/ra_analysis/src/imp.rs | |
parent | f9b58454a43274d3b1d4d0e74cdef597b75f9a97 (diff) | |
parent | 872950bc188ba104ecd1f532427dea6dc52533bd (diff) |
Merge #375
375: Move renames into ra_analysis and rename the correct range r=DJMcNab a=DJMcNab
Fixes #230. Supersedes #235.
TODO: add some tests for this
Co-authored-by: DJMcNab <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 26 |
1 files changed, 24 insertions, 2 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()); |