Skip to content

Commit d8e0e96

Browse files
Merge pull request #21675 from akashchakrabortymsc-cmd/fix/exclude-tests-macro-refs
fix: exclude macro refs in tests when excludeTests is enabled
2 parents fa4ef83 + fc01350 commit d8e0e96

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

crates/ide-db/src/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ fn is_name_ref_in_import(name_ref: &ast::NameRef) -> bool {
13701370
}
13711371

13721372
fn is_name_ref_in_test(sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef) -> bool {
1373-
name_ref.syntax().ancestors().any(|node| match ast::Fn::cast(node) {
1373+
sema.ancestors_with_macros(name_ref.syntax().clone()).any(|node| match ast::Fn::cast(node) {
13741374
Some(it) => sema.to_def(&it).is_some_and(|func| func.is_test(sema.db)),
13751375
None => false,
13761376
})

crates/ide/src/references.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,26 +513,32 @@ fn test() {
513513
}
514514

515515
#[test]
516-
fn test_access() {
516+
fn exclude_tests_macro_refs() {
517517
check(
518518
r#"
519-
struct S { f$0: u32 }
519+
macro_rules! my_macro {
520+
($e:expr) => { $e };
521+
}
522+
523+
fn foo$0() -> i32 { 42 }
524+
525+
fn bar() {
526+
foo();
527+
}
520528
521529
#[test]
522-
fn test() {
523-
let mut x = S { f: 92 };
524-
x.f = 92;
530+
fn t2() {
531+
my_macro!(foo());
525532
}
526533
"#,
527534
expect![[r#"
528-
f Field FileId(0) 11..17 11..12
535+
foo Function FileId(0) 52..74 55..58
529536
530-
FileId(0) 61..62 read test
531-
FileId(0) 76..77 write test
537+
FileId(0) 91..94
538+
FileId(0) 133..136 test
532539
"#]],
533540
);
534541
}
535-
536542
#[test]
537543
fn test_struct_literal_after_space() {
538544
check(

0 commit comments

Comments
 (0)