Unnamed repository; edit this file 'description' to name the repository.
Merge #10188
10188: fix: add multi-token mapping support to runnables r=jonas-schievink a=lnicola
Closes #10184
changelog fix (first contribution) add multi-token mapping support to runnables
Co-authored-by: Anatol Ulrich <[email protected]>
| -rw-r--r-- | crates/ide/src/runnables.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index b44d95a580..6b74ec3430 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -229,15 +229,20 @@ fn find_related_tests( for (file_id, refs) in refs.into_iter().flat_map(|refs| refs.references) { let file = sema.parse(file_id); let file = file.syntax(); - 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) - .map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f)) + + // create flattened vec of tokens + let tokens = refs.iter().flat_map(|(range, _)| { + match file.token_at_offset(range.start()).next() { + Some(token) => sema.descend_into_macros_many(token), + None => Default::default(), + } }); + // find first suitable ancestor + let functions = tokens + .filter_map(|token| token.ancestors().find_map(ast::Fn::cast)) + .map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f)); + for fn_def in functions { // #[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); |