aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/marks.rs2
-rw-r--r--crates/ra_ide/src/references/rename.rs13
2 files changed, 10 insertions, 5 deletions
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs
index bea30fe2a..51ca4dde3 100644
--- a/crates/ra_ide/src/marks.rs
+++ b/crates/ra_ide/src/marks.rs
@@ -11,4 +11,6 @@ test_utils::marks!(
11 self_fulfilling_completion 11 self_fulfilling_completion
12 test_struct_field_completion_in_func_call 12 test_struct_field_completion_in_func_call
13 test_struct_field_completion_in_record_lit 13 test_struct_field_completion_in_record_lit
14 test_rename_struct_field_for_shorthand
15 test_rename_local_for_field_shorthand
14); 16);
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs
index fd17bc9f2..916edaef2 100644
--- a/crates/ra_ide/src/references/rename.rs
+++ b/crates/ra_ide/src/references/rename.rs
@@ -7,14 +7,13 @@ use ra_syntax::{
7 algo::find_node_at_offset, ast, lex_single_valid_syntax_kind, AstNode, SyntaxKind, SyntaxNode, 7 algo::find_node_at_offset, ast, lex_single_valid_syntax_kind, AstNode, SyntaxKind, SyntaxNode,
8}; 8};
9use ra_text_edit::TextEdit; 9use ra_text_edit::TextEdit;
10use test_utils::tested_by;
10 11
11use crate::{ 12use crate::{
12 FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, SourceChange, 13 references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind,
13 SourceFileEdit, TextRange, 14 SourceChange, SourceFileEdit, TextRange,
14}; 15};
15 16
16use super::find_all_refs;
17
18pub(crate) fn rename( 17pub(crate) fn rename(
19 db: &RootDatabase, 18 db: &RootDatabase,
20 position: FilePosition, 19 position: FilePosition,
@@ -52,11 +51,13 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil
52 let file_id = reference.file_range.file_id; 51 let file_id = reference.file_range.file_id;
53 let range = match reference.kind { 52 let range = match reference.kind {
54 ReferenceKind::FieldShorthandForField => { 53 ReferenceKind::FieldShorthandForField => {
54 tested_by!(test_rename_struct_field_for_shorthand);
55 replacement_text.push_str(new_name); 55 replacement_text.push_str(new_name);
56 replacement_text.push_str(": "); 56 replacement_text.push_str(": ");
57 TextRange::new(reference.file_range.range.start(), reference.file_range.range.start()) 57 TextRange::new(reference.file_range.range.start(), reference.file_range.range.start())
58 } 58 }
59 ReferenceKind::FieldShorthandForLocal => { 59 ReferenceKind::FieldShorthandForLocal => {
60 tested_by!(test_rename_local_for_field_shorthand);
60 replacement_text.push_str(": "); 61 replacement_text.push_str(": ");
61 replacement_text.push_str(new_name); 62 replacement_text.push_str(new_name);
62 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end()) 63 TextRange::new(reference.file_range.range.end(), reference.file_range.range.end())
@@ -147,7 +148,7 @@ fn rename_reference(
147mod tests { 148mod tests {
148 use insta::assert_debug_snapshot; 149 use insta::assert_debug_snapshot;
149 use ra_text_edit::TextEditBuilder; 150 use ra_text_edit::TextEditBuilder;
150 use test_utils::assert_eq_text; 151 use test_utils::{assert_eq_text, covers};
151 152
152 use crate::{ 153 use crate::{
153 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, 154 mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId,
@@ -379,6 +380,7 @@ mod tests {
379 380
380 #[test] 381 #[test]
381 fn test_rename_struct_field_for_shorthand() { 382 fn test_rename_struct_field_for_shorthand() {
383 covers!(test_rename_struct_field_for_shorthand);
382 test_rename( 384 test_rename(
383 r#" 385 r#"
384 struct Foo { 386 struct Foo {
@@ -408,6 +410,7 @@ mod tests {
408 410
409 #[test] 411 #[test]
410 fn test_rename_local_for_field_shorthand() { 412 fn test_rename_local_for_field_shorthand() {
413 covers!(test_rename_local_for_field_shorthand);
411 test_rename( 414 test_rename(
412 r#" 415 r#"
413 struct Foo { 416 struct Foo {