Skip to content

Commit 92ce768

Browse files
bors[bot]Anatol Ulrich
andauthored
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]>
2 parents f1bcf97 + 5d08ac2 commit 92ce768

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crates/ide/src/runnables.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,20 @@ fn find_related_tests(
229229
for (file_id, refs) in refs.into_iter().flat_map(|refs| refs.references) {
230230
let file = sema.parse(file_id);
231231
let file = file.syntax();
232-
let functions = refs.iter().filter_map(|(range, _)| {
233-
let token = file.token_at_offset(range.start()).next()?;
234-
let token = sema.descend_into_macros(token);
235-
token
236-
.ancestors()
237-
.find_map(ast::Fn::cast)
238-
.map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f))
232+
233+
// create flattened vec of tokens
234+
let tokens = refs.iter().flat_map(|(range, _)| {
235+
match file.token_at_offset(range.start()).next() {
236+
Some(token) => sema.descend_into_macros_many(token),
237+
None => Default::default(),
238+
}
239239
});
240240

241+
// find first suitable ancestor
242+
let functions = tokens
243+
.filter_map(|token| token.ancestors().find_map(ast::Fn::cast))
244+
.map(|f| hir::InFile::new(sema.hir_file_for(f.syntax()), f));
245+
241246
for fn_def in functions {
242247
// #[test/bench] expands to just the item causing us to lose the attribute, so recover them by going out of the attribute
243248
let InFile { value: fn_def, .. } = &fn_def.node_with_attributes(sema.db);

0 commit comments

Comments
 (0)