@@ -232,22 +232,27 @@ fn find_related_tests(
232
232
let functions = refs. iter ( ) . filter_map ( |( range, _) | {
233
233
let token = file. token_at_offset ( range. start ( ) ) . next ( ) ?;
234
234
let token = sema. descend_into_macros ( token) ;
235
- token. ancestors ( ) . find_map ( ast:: Fn :: cast)
235
+ // FIXME: This is the wrong file_id
236
+ token
237
+ . ancestors ( )
238
+ . find_map ( ast:: Fn :: cast)
239
+ . map ( |f| hir:: InFile :: new ( file_id. into ( ) , f) )
236
240
} ) ;
237
241
238
242
for fn_def in functions {
239
- if let Some ( runnable) = as_test_runnable ( sema, & fn_def) {
243
+ // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
244
+ let fn_def = fn_def. node_with_attributes ( sema. db ) ;
245
+ if let Some ( runnable) = as_test_runnable ( sema, & fn_def. value ) {
240
246
// direct test
241
247
tests. insert ( runnable) ;
242
- } else if let Some ( module) = parent_test_module ( sema, & fn_def) {
248
+ } else if let Some ( module) = parent_test_module ( sema, & fn_def. value ) {
243
249
// indirect test
244
- find_related_tests_in_module ( sema, & fn_def, & module, tests) ;
250
+ find_related_tests_in_module ( sema, & fn_def. value , & module, tests) ;
245
251
}
246
252
}
247
253
}
248
254
}
249
255
}
250
-
251
256
fn find_related_tests_in_module (
252
257
sema : & Semantics < RootDatabase > ,
253
258
fn_def : & ast:: Fn ,
@@ -292,7 +297,8 @@ fn parent_test_module(sema: &Semantics<RootDatabase>, fn_def: &ast::Fn) -> Optio
292
297
}
293
298
294
299
pub ( crate ) fn runnable_fn ( sema : & Semantics < RootDatabase > , def : hir:: Function ) -> Option < Runnable > {
295
- let func = def. source ( sema. db ) ?;
300
+ // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
301
+ let func = def. source ( sema. db ) ?. node_with_attributes ( sema. db ) ;
296
302
let name_string = def. name ( sema. db ) . to_string ( ) ;
297
303
298
304
let root = def. module ( sema. db ) . krate ( ) . root_module ( sema. db ) ;
@@ -499,6 +505,8 @@ fn has_test_function_or_multiple_test_submodules(
499
505
match item {
500
506
hir:: ModuleDef :: Function ( f) => {
501
507
if let Some ( it) = f. source ( sema. db ) {
508
+ // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
509
+ let it = it. node_with_attributes ( sema. db ) ;
502
510
if test_related_attribute ( & it. value ) . is_some ( ) {
503
511
return true ;
504
512
}
0 commit comments