Unnamed repository; edit this file 'description' to name the repository.
fix: exclude macro refs in tests when excludeTests is enabled
| -rw-r--r-- | crates/ide-db/src/search.rs | 8 | ||||
| -rw-r--r-- | crates/ide/src/references.rs | 35 |
2 files changed, 40 insertions, 3 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index 1d865892a2..5cb5d4aa2b 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -1370,8 +1370,10 @@ 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) { - Some(it) => sema.to_def(&it).is_some_and(|func| func.is_test(sema.db)), - None => false, + 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..cf20224c52 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -532,6 +532,41 @@ fn test() { "#]], ); } + #[test] + fn exclude_tests_macro_refs() { + check( + r#" +fn foo$0() -> i32 { 42 } + +fn bar() { + foo(); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn t1() { + let f = foo(); + } + + #[test] + fn t2() { + dbg!(foo()); + assert_eq!(foo(), 42); + let v = vec![foo()]; + } +} +"#, + expect![[r#" + foo Function FileId(0) 0..22 3..6 + + FileId(0) 39..42 + FileId(0) 135..138 + "#]], + ); + } #[test] fn test_struct_literal_after_space() { |