aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/references
diff options
context:
space:
mode:
authorLaurenČ›iu Nicola <[email protected]>2021-03-08 20:19:44 +0000
committerLaurenČ›iu Nicola <[email protected]>2021-03-08 20:19:44 +0000
commitfc9eed4836dfc88fe2893c81b015ab440cea2ba6 (patch)
tree3905029a42c8bb6c5d363753b34cd6b5dd43f4d5 /crates/ide/src/references
parentc5189a22ccf4c28e309e4189defbb88b83bb2aea (diff)
Use upstream cov-mark
Diffstat (limited to 'crates/ide/src/references')
-rw-r--r--crates/ide/src/references/rename.rs58
1 files changed, 30 insertions, 28 deletions
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 1919639a3..05c73de88 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -14,7 +14,7 @@ use syntax::{
14 ast::{self, NameOwner}, 14 ast::{self, NameOwner},
15 lex_single_syntax_kind, AstNode, SyntaxKind, SyntaxNode, T, 15 lex_single_syntax_kind, AstNode, SyntaxKind, SyntaxNode, T,
16}; 16};
17use test_utils::mark; 17
18use text_edit::TextEdit; 18use text_edit::TextEdit;
19 19
20use crate::{display::TryToNav, FilePosition, FileSystemEdit, RangeInfo, SourceChange, TextRange}; 20use crate::{display::TryToNav, FilePosition, FileSystemEdit, RangeInfo, SourceChange, TextRange};
@@ -226,34 +226,36 @@ fn rename_reference(
226 | (IdentifierKind::Ident, _) 226 | (IdentifierKind::Ident, _)
227 if def_is_lbl_or_lt => 227 if def_is_lbl_or_lt =>
228 { 228 {
229 mark::hit!(rename_not_a_lifetime_ident_ref); 229 cov_mark::hit!(rename_not_a_lifetime_ident_ref);
230 bail!("Invalid name `{}`: not a lifetime identifier", new_name) 230 bail!("Invalid name `{}`: not a lifetime identifier", new_name)
231 } 231 }
232 (IdentifierKind::Lifetime, _) if def_is_lbl_or_lt => mark::hit!(rename_lifetime), 232 (IdentifierKind::Lifetime, _) if def_is_lbl_or_lt => cov_mark::hit!(rename_lifetime),
233 (IdentifierKind::Lifetime, _) => { 233 (IdentifierKind::Lifetime, _) => {
234 mark::hit!(rename_not_an_ident_ref); 234 cov_mark::hit!(rename_not_an_ident_ref);
235 bail!("Invalid name `{}`: not an identifier", new_name) 235 bail!("Invalid name `{}`: not an identifier", new_name)
236 } 236 }
237 (IdentifierKind::ToSelf, Definition::Local(local)) if local.is_self(sema.db) => { 237 (IdentifierKind::ToSelf, Definition::Local(local)) if local.is_self(sema.db) => {
238 // no-op 238 // no-op
239 mark::hit!(rename_self_to_self); 239 cov_mark::hit!(rename_self_to_self);
240 return Ok(SourceChange::default()); 240 return Ok(SourceChange::default());
241 } 241 }
242 (ident_kind, Definition::Local(local)) if local.is_self(sema.db) => { 242 (ident_kind, Definition::Local(local)) if local.is_self(sema.db) => {
243 mark::hit!(rename_self_to_param); 243 cov_mark::hit!(rename_self_to_param);
244 return rename_self_to_param(sema, local, new_name, ident_kind); 244 return rename_self_to_param(sema, local, new_name, ident_kind);
245 } 245 }
246 (IdentifierKind::ToSelf, Definition::Local(local)) => { 246 (IdentifierKind::ToSelf, Definition::Local(local)) => {
247 mark::hit!(rename_to_self); 247 cov_mark::hit!(rename_to_self);
248 return rename_to_self(sema, local); 248 return rename_to_self(sema, local);
249 } 249 }
250 (IdentifierKind::ToSelf, _) => bail!("Invalid name `{}`: not an identifier", new_name), 250 (IdentifierKind::ToSelf, _) => bail!("Invalid name `{}`: not an identifier", new_name),
251 (IdentifierKind::Ident, _) | (IdentifierKind::Underscore, _) => mark::hit!(rename_ident), 251 (IdentifierKind::Ident, _) | (IdentifierKind::Underscore, _) => {
252 cov_mark::hit!(rename_ident)
253 }
252 } 254 }
253 255
254 let usages = def.usages(sema).all(); 256 let usages = def.usages(sema).all();
255 if !usages.is_empty() && ident_kind == IdentifierKind::Underscore { 257 if !usages.is_empty() && ident_kind == IdentifierKind::Underscore {
256 mark::hit!(rename_underscore_multiple); 258 cov_mark::hit!(rename_underscore_multiple);
257 bail!("Cannot rename reference to `_` as it is being referenced multiple times"); 259 bail!("Cannot rename reference to `_` as it is being referenced multiple times");
258 } 260 }
259 let mut source_change = SourceChange::default(); 261 let mut source_change = SourceChange::default();
@@ -444,7 +446,7 @@ fn source_edit_from_name_ref(
444 (Some(field_name), Some(init)) => { 446 (Some(field_name), Some(init)) => {
445 if field_name == *name_ref { 447 if field_name == *name_ref {
446 if init.text() == new_name { 448 if init.text() == new_name {
447 mark::hit!(test_rename_field_put_init_shorthand); 449 cov_mark::hit!(test_rename_field_put_init_shorthand);
448 // same names, we can use a shorthand here instead. 450 // same names, we can use a shorthand here instead.
449 // we do not want to erase attributes hence this range start 451 // we do not want to erase attributes hence this range start
450 let s = field_name.syntax().text_range().start(); 452 let s = field_name.syntax().text_range().start();
@@ -453,7 +455,7 @@ fn source_edit_from_name_ref(
453 } 455 }
454 } else if init == *name_ref { 456 } else if init == *name_ref {
455 if field_name.text() == new_name { 457 if field_name.text() == new_name {
456 mark::hit!(test_rename_local_put_init_shorthand); 458 cov_mark::hit!(test_rename_local_put_init_shorthand);
457 // same names, we can use a shorthand here instead. 459 // same names, we can use a shorthand here instead.
458 // we do not want to erase attributes hence this range start 460 // we do not want to erase attributes hence this range start
459 let s = field_name.syntax().text_range().start(); 461 let s = field_name.syntax().text_range().start();
@@ -467,12 +469,12 @@ fn source_edit_from_name_ref(
467 // FIXME: instead of splitting the shorthand, recursively trigger a rename of the 469 // FIXME: instead of splitting the shorthand, recursively trigger a rename of the
468 // other name https://github.com/rust-analyzer/rust-analyzer/issues/6547 470 // other name https://github.com/rust-analyzer/rust-analyzer/issues/6547
469 (None, Some(_)) if matches!(def, Definition::Field(_)) => { 471 (None, Some(_)) if matches!(def, Definition::Field(_)) => {
470 mark::hit!(test_rename_field_in_field_shorthand); 472 cov_mark::hit!(test_rename_field_in_field_shorthand);
471 let s = name_ref.syntax().text_range().start(); 473 let s = name_ref.syntax().text_range().start();
472 Some((TextRange::empty(s), format!("{}: ", new_name))) 474 Some((TextRange::empty(s), format!("{}: ", new_name)))
473 } 475 }
474 (None, Some(_)) if matches!(def, Definition::Local(_)) => { 476 (None, Some(_)) if matches!(def, Definition::Local(_)) => {
475 mark::hit!(test_rename_local_in_field_shorthand); 477 cov_mark::hit!(test_rename_local_in_field_shorthand);
476 let s = name_ref.syntax().text_range().end(); 478 let s = name_ref.syntax().text_range().end();
477 Some((TextRange::empty(s), format!(": {}", new_name))) 479 Some((TextRange::empty(s), format!(": {}", new_name)))
478 } 480 }
@@ -486,7 +488,7 @@ fn source_edit_from_name_ref(
486 (Some(field_name), Some(ast::Pat::IdentPat(pat))) if field_name == *name_ref => { 488 (Some(field_name), Some(ast::Pat::IdentPat(pat))) if field_name == *name_ref => {
487 // field name is being renamed 489 // field name is being renamed
488 if pat.name().map_or(false, |it| it.text() == new_name) { 490 if pat.name().map_or(false, |it| it.text() == new_name) {
489 mark::hit!(test_rename_field_put_init_shorthand_pat); 491 cov_mark::hit!(test_rename_field_put_init_shorthand_pat);
490 // same names, we can use a shorthand here instead/ 492 // same names, we can use a shorthand here instead/
491 // we do not want to erase attributes hence this range start 493 // we do not want to erase attributes hence this range start
492 let s = field_name.syntax().text_range().start(); 494 let s = field_name.syntax().text_range().start();
@@ -538,7 +540,7 @@ fn source_edit_from_def(
538mod tests { 540mod tests {
539 use expect_test::{expect, Expect}; 541 use expect_test::{expect, Expect};
540 use stdx::trim_indent; 542 use stdx::trim_indent;
541 use test_utils::{assert_eq_text, mark}; 543 use test_utils::assert_eq_text;
542 use text_edit::TextEdit; 544 use text_edit::TextEdit;
543 545
544 use crate::{fixture, FileId}; 546 use crate::{fixture, FileId};
@@ -627,7 +629,7 @@ mod tests {
627 629
628 #[test] 630 #[test]
629 fn test_rename_to_invalid_identifier_lifetime() { 631 fn test_rename_to_invalid_identifier_lifetime() {
630 mark::check!(rename_not_an_ident_ref); 632 cov_mark::check!(rename_not_an_ident_ref);
631 check( 633 check(
632 "'foo", 634 "'foo",
633 r#"fn main() { let i$0 = 1; }"#, 635 r#"fn main() { let i$0 = 1; }"#,
@@ -637,7 +639,7 @@ mod tests {
637 639
638 #[test] 640 #[test]
639 fn test_rename_to_invalid_identifier_lifetime2() { 641 fn test_rename_to_invalid_identifier_lifetime2() {
640 mark::check!(rename_not_a_lifetime_ident_ref); 642 cov_mark::check!(rename_not_a_lifetime_ident_ref);
641 check( 643 check(
642 "foo", 644 "foo",
643 r#"fn main<'a>(_: &'a$0 ()) {}"#, 645 r#"fn main<'a>(_: &'a$0 ()) {}"#,
@@ -647,7 +649,7 @@ mod tests {
647 649
648 #[test] 650 #[test]
649 fn test_rename_to_underscore_invalid() { 651 fn test_rename_to_underscore_invalid() {
650 mark::check!(rename_underscore_multiple); 652 cov_mark::check!(rename_underscore_multiple);
651 check( 653 check(
652 "_", 654 "_",
653 r#"fn main(foo$0: ()) {foo;}"#, 655 r#"fn main(foo$0: ()) {foo;}"#,
@@ -666,7 +668,7 @@ mod tests {
666 668
667 #[test] 669 #[test]
668 fn test_rename_for_local() { 670 fn test_rename_for_local() {
669 mark::check!(rename_ident); 671 cov_mark::check!(rename_ident);
670 check( 672 check(
671 "k", 673 "k",
672 r#" 674 r#"
@@ -829,7 +831,7 @@ impl Foo {
829 831
830 #[test] 832 #[test]
831 fn test_rename_field_in_field_shorthand() { 833 fn test_rename_field_in_field_shorthand() {
832 mark::check!(test_rename_field_in_field_shorthand); 834 cov_mark::check!(test_rename_field_in_field_shorthand);
833 check( 835 check(
834 "j", 836 "j",
835 r#" 837 r#"
@@ -855,7 +857,7 @@ impl Foo {
855 857
856 #[test] 858 #[test]
857 fn test_rename_local_in_field_shorthand() { 859 fn test_rename_local_in_field_shorthand() {
858 mark::check!(test_rename_local_in_field_shorthand); 860 cov_mark::check!(test_rename_local_in_field_shorthand);
859 check( 861 check(
860 "j", 862 "j",
861 r#" 863 r#"
@@ -1261,7 +1263,7 @@ fn foo(f: foo::Foo) {
1261 1263
1262 #[test] 1264 #[test]
1263 fn test_parameter_to_self() { 1265 fn test_parameter_to_self() {
1264 mark::check!(rename_to_self); 1266 cov_mark::check!(rename_to_self);
1265 check( 1267 check(
1266 "self", 1268 "self",
1267 r#" 1269 r#"
@@ -1401,7 +1403,7 @@ impl Foo {
1401 1403
1402 #[test] 1404 #[test]
1403 fn test_owned_self_to_parameter() { 1405 fn test_owned_self_to_parameter() {
1404 mark::check!(rename_self_to_param); 1406 cov_mark::check!(rename_self_to_param);
1405 check( 1407 check(
1406 "foo", 1408 "foo",
1407 r#" 1409 r#"
@@ -1454,7 +1456,7 @@ impl Foo {
1454 1456
1455 #[test] 1457 #[test]
1456 fn test_rename_field_put_init_shorthand() { 1458 fn test_rename_field_put_init_shorthand() {
1457 mark::check!(test_rename_field_put_init_shorthand); 1459 cov_mark::check!(test_rename_field_put_init_shorthand);
1458 check( 1460 check(
1459 "bar", 1461 "bar",
1460 r#" 1462 r#"
@@ -1476,7 +1478,7 @@ fn foo(bar: i32) -> Foo {
1476 1478
1477 #[test] 1479 #[test]
1478 fn test_rename_local_put_init_shorthand() { 1480 fn test_rename_local_put_init_shorthand() {
1479 mark::check!(test_rename_local_put_init_shorthand); 1481 cov_mark::check!(test_rename_local_put_init_shorthand);
1480 check( 1482 check(
1481 "i", 1483 "i",
1482 r#" 1484 r#"
@@ -1498,7 +1500,7 @@ fn foo(i: i32) -> Foo {
1498 1500
1499 #[test] 1501 #[test]
1500 fn test_struct_field_pat_into_shorthand() { 1502 fn test_struct_field_pat_into_shorthand() {
1501 mark::check!(test_rename_field_put_init_shorthand_pat); 1503 cov_mark::check!(test_rename_field_put_init_shorthand_pat);
1502 check( 1504 check(
1503 "baz", 1505 "baz",
1504 r#" 1506 r#"
@@ -1610,7 +1612,7 @@ fn foo(foo: Foo) {
1610 1612
1611 #[test] 1613 #[test]
1612 fn test_rename_lifetimes() { 1614 fn test_rename_lifetimes() {
1613 mark::check!(rename_lifetime); 1615 cov_mark::check!(rename_lifetime);
1614 check( 1616 check(
1615 "'yeeee", 1617 "'yeeee",
1616 r#" 1618 r#"
@@ -1698,7 +1700,7 @@ fn foo<'a>() -> &'a () {
1698 1700
1699 #[test] 1701 #[test]
1700 fn test_self_to_self() { 1702 fn test_self_to_self() {
1701 mark::check!(rename_self_to_self); 1703 cov_mark::check!(rename_self_to_self);
1702 check( 1704 check(
1703 "self", 1705 "self",
1704 r#" 1706 r#"