Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21675 from akashchakrabortymsc-cmd/fix/exclude-tests-macro-refs
fix: exclude macro refs in tests when excludeTests is enabled
| -rw-r--r-- | crates/ide-db/src/search.rs | 2 | ||||
| -rw-r--r-- | crates/ide/src/references.rs | 24 |
2 files changed, 16 insertions, 10 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index 1d865892a2..4196a13aa3 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -1370,7 +1370,7 @@ fn is_name_ref_in_import(name_ref: &ast::NameRef) -> bool { } fn is_name_ref_in_test(sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef) -> bool { - name_ref.syntax().ancestors().any(|node| match ast::Fn::cast(node) { + sema.ancestors_with_macros(name_ref.syntax().clone()).any(|node| match ast::Fn::cast(node) { Some(it) => sema.to_def(&it).is_some_and(|func| func.is_test(sema.db)), None => false, }) diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 38ee097033..102eb91b74 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -513,26 +513,32 @@ fn test() { } #[test] - fn test_access() { + fn exclude_tests_macro_refs() { check( r#" -struct S { f$0: u32 } +macro_rules! my_macro { + ($e:expr) => { $e }; +} + +fn foo$0() -> i32 { 42 } + +fn bar() { + foo(); +} #[test] -fn test() { - let mut x = S { f: 92 }; - x.f = 92; +fn t2() { + my_macro!(foo()); } "#, expect![[r#" - f Field FileId(0) 11..17 11..12 + foo Function FileId(0) 52..74 55..58 - FileId(0) 61..62 read test - FileId(0) 76..77 write test + FileId(0) 91..94 + FileId(0) 133..136 test "#]], ); } - #[test] fn test_struct_literal_after_space() { check( |