diff options
Diffstat (limited to 'crates/ra_ide_api/src/references/rename.rs')
-rw-r--r-- | crates/ra_ide_api/src/references/rename.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index ee6e73e1b..a8783d7a0 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | use hir::ModuleSource; | 3 | use hir::ModuleSource; |
4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 4 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; | 5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; |
6 | use ra_text_edit::TextEdit; | ||
6 | use relative_path::{RelativePath, RelativePathBuf}; | 7 | use relative_path::{RelativePath, RelativePathBuf}; |
7 | 8 | ||
8 | use crate::{ | 9 | use crate::{ |
@@ -43,14 +44,7 @@ fn source_edit_from_file_id_range( | |||
43 | range: TextRange, | 44 | range: TextRange, |
44 | new_name: &str, | 45 | new_name: &str, |
45 | ) -> SourceFileEdit { | 46 | ) -> SourceFileEdit { |
46 | SourceFileEdit { | 47 | SourceFileEdit { file_id, edit: TextEdit::replace(range, new_name.into()) } |
47 | file_id, | ||
48 | edit: { | ||
49 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
50 | builder.replace(range, new_name.into()); | ||
51 | builder.finish() | ||
52 | }, | ||
53 | } | ||
54 | } | 48 | } |
55 | 49 | ||
56 | fn rename_mod( | 50 | fn rename_mod( |
@@ -94,11 +88,7 @@ fn rename_mod( | |||
94 | 88 | ||
95 | let edit = SourceFileEdit { | 89 | let edit = SourceFileEdit { |
96 | file_id: position.file_id, | 90 | file_id: position.file_id, |
97 | edit: { | 91 | edit: TextEdit::replace(ast_name.syntax().text_range(), new_name.into()), |
98 | let mut builder = ra_text_edit::TextEditBuilder::default(); | ||
99 | builder.replace(ast_name.syntax().text_range(), new_name.into()); | ||
100 | builder.finish() | ||
101 | }, | ||
102 | }; | 92 | }; |
103 | source_file_edits.push(edit); | 93 | source_file_edits.push(edit); |
104 | 94 | ||
@@ -126,12 +116,14 @@ fn rename_reference( | |||
126 | 116 | ||
127 | #[cfg(test)] | 117 | #[cfg(test)] |
128 | mod tests { | 118 | mod tests { |
119 | use insta::assert_debug_snapshot; | ||
120 | use ra_text_edit::TextEditBuilder; | ||
121 | use test_utils::assert_eq_text; | ||
122 | |||
129 | use crate::{ | 123 | use crate::{ |
130 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, | 124 | mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, |
131 | ReferenceSearchResult, | 125 | ReferenceSearchResult, |
132 | }; | 126 | }; |
133 | use insta::assert_debug_snapshot; | ||
134 | use test_utils::assert_eq_text; | ||
135 | 127 | ||
136 | #[test] | 128 | #[test] |
137 | fn test_find_all_refs_for_local() { | 129 | fn test_find_all_refs_for_local() { |
@@ -452,7 +444,7 @@ mod tests { | |||
452 | fn test_rename(text: &str, new_name: &str, expected: &str) { | 444 | fn test_rename(text: &str, new_name: &str, expected: &str) { |
453 | let (analysis, position) = single_file_with_position(text); | 445 | let (analysis, position) = single_file_with_position(text); |
454 | let source_change = analysis.rename(position, new_name).unwrap(); | 446 | let source_change = analysis.rename(position, new_name).unwrap(); |
455 | let mut text_edit_builder = ra_text_edit::TextEditBuilder::default(); | 447 | let mut text_edit_builder = TextEditBuilder::default(); |
456 | let mut file_id: Option<FileId> = None; | 448 | let mut file_id: Option<FileId> = None; |
457 | if let Some(change) = source_change { | 449 | if let Some(change) = source_change { |
458 | for edit in change.info.source_file_edits { | 450 | for edit in change.info.source_file_edits { |