Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/runnables.rs')
| -rw-r--r-- | crates/ide/src/runnables.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 42f6ec5d9c..d2350db037 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -3,7 +3,7 @@ use std::fmt; use ast::NameOwner; use cfg::CfgExpr; use either::Either; -use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics}; +use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, InFile, Semantics}; use ide_assists::utils::test_related_attribute; use ide_db::{ base_db::{FilePosition, FileRange}, @@ -232,22 +232,26 @@ fn find_related_tests( let functions = refs.iter().filter_map(|(range, _)| { let token = file.token_at_offset(range.start()).next()?; let token = sema.descend_into_macros(token); - token.ancestors().find_map(ast::Fn::cast) + token + .ancestors() + .find_map(ast::Fn::cast) + .map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f)) }); for fn_def in functions { - if let Some(runnable) = as_test_runnable(sema, &fn_def) { + // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute + let InFile { value: fn_def, .. } = &fn_def.node_with_attributes(sema.db); + if let Some(runnable) = as_test_runnable(sema, fn_def) { // direct test tests.insert(runnable); - } else if let Some(module) = parent_test_module(sema, &fn_def) { + } else if let Some(module) = parent_test_module(sema, fn_def) { // indirect test - find_related_tests_in_module(sema, &fn_def, &module, tests); + find_related_tests_in_module(sema, fn_def, &module, tests); } } } } } - fn find_related_tests_in_module( sema: &Semantics<RootDatabase>, fn_def: &ast::Fn, @@ -292,7 +296,8 @@ fn parent_test_module(sema: &Semantics<RootDatabase>, fn_def: &ast::Fn) -> Optio } pub(crate) fn runnable_fn(sema: &Semantics<RootDatabase>, def: hir::Function) -> Option<Runnable> { - let func = def.source(sema.db)?; + // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute + let func = def.source(sema.db)?.node_with_attributes(sema.db); let name_string = def.name(sema.db).to_string(); let root = def.module(sema.db).krate().root_module(sema.db); @@ -499,6 +504,8 @@ fn has_test_function_or_multiple_test_submodules( match item { hir::ModuleDef::Function(f) => { if let Some(it) = f.source(sema.db) { + // #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute + let it = it.node_with_attributes(sema.db); if test_related_attribute(&it.value).is_some() { return true; } |