diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 794a109f3..1fca6de1f 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -48,17 +48,26 @@ fn find_name_and_module_at_offset( | |||
48 | } | 48 | } |
49 | 49 | ||
50 | fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFileEdit { | 50 | fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFileEdit { |
51 | let mut replacement_text = String::from(new_name); | 51 | let mut replacement_text = String::new(); |
52 | let file_id = reference.file_range.file_id; | 52 | let file_id = reference.file_range.file_id; |
53 | let range = match reference.kind { | 53 | let range = match reference.kind { |
54 | ReferenceKind::StructFieldShorthand => { | 54 | ReferenceKind::StructFieldShorthandForField => { |
55 | replacement_text.push_str(new_name); | ||
55 | replacement_text.push_str(": "); | 56 | replacement_text.push_str(": "); |
56 | TextRange::from_to( | 57 | TextRange::from_to( |
57 | reference.file_range.range.start(), | 58 | reference.file_range.range.start(), |
58 | reference.file_range.range.start(), | 59 | reference.file_range.range.start(), |
59 | ) | 60 | ) |
60 | } | 61 | } |
61 | _ => reference.file_range.range, | 62 | ReferenceKind::StructFieldShorthandForLocal => { |
63 | replacement_text.push_str(": "); | ||
64 | replacement_text.push_str(new_name); | ||
65 | TextRange::from_to(reference.file_range.range.end(), reference.file_range.range.end()) | ||
66 | } | ||
67 | _ => { | ||
68 | replacement_text.push_str(new_name); | ||
69 | reference.file_range.range | ||
70 | } | ||
62 | }; | 71 | }; |
63 | SourceFileEdit { file_id, edit: TextEdit::replace(range, replacement_text) } | 72 | SourceFileEdit { file_id, edit: TextEdit::replace(range, replacement_text) } |
64 | } | 73 | } |
@@ -286,7 +295,7 @@ mod tests { | |||
286 | } | 295 | } |
287 | 296 | ||
288 | #[test] | 297 | #[test] |
289 | fn test_rename_for_struct_field() { | 298 | fn test_rename_struct_field() { |
290 | test_rename( | 299 | test_rename( |
291 | r#" | 300 | r#" |
292 | struct Foo { | 301 | struct Foo { |
@@ -315,7 +324,7 @@ mod tests { | |||
315 | } | 324 | } |
316 | 325 | ||
317 | #[test] | 326 | #[test] |
318 | fn test_rename_for_struct_field_shorthand() { | 327 | fn test_rename_struct_field_for_shorthand() { |
319 | test_rename( | 328 | test_rename( |
320 | r#" | 329 | r#" |
321 | struct Foo { | 330 | struct Foo { |
@@ -344,6 +353,35 @@ mod tests { | |||
344 | } | 353 | } |
345 | 354 | ||
346 | #[test] | 355 | #[test] |
356 | fn test_rename_local_for_field_shorthand() { | ||
357 | test_rename( | ||
358 | r#" | ||
359 | struct Foo { | ||
360 | i: i32, | ||
361 | } | ||
362 | |||
363 | impl Foo { | ||
364 | fn new(i<|>: i32) -> Self { | ||
365 | Self { i } | ||
366 | } | ||
367 | } | ||
368 | "#, | ||
369 | "j", | ||
370 | r#" | ||
371 | struct Foo { | ||
372 | i: i32, | ||
373 | } | ||
374 | |||
375 | impl Foo { | ||
376 | fn new(j: i32) -> Self { | ||
377 | Self { i: j } | ||
378 | } | ||
379 | } | ||
380 | "#, | ||
381 | ); | ||
382 | } | ||
383 | |||
384 | #[test] | ||
347 | fn test_rename_mod() { | 385 | fn test_rename_mod() { |
348 | let (analysis, position) = analysis_and_position( | 386 | let (analysis, position) = analysis_and_position( |
349 | " | 387 | " |