about summary refs log tree commit diff
path: root/crates/ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-09 15:07:43 +0000
committerGitHub <noreply@github.com>2021-09-09 15:07:43 +0000
commit92ce768ea3dcfe5cda55f2a4607d4245730e0d64 (patch)
treebbc3be0bd19fda0a61f56c9b10f705657f450744 /crates/ide/src
parentf1bcf975a7f692b0d395224e4ce3e587e7cab3b5 (diff)
parent5d08ac20d9de138d69c9c86c6c6814629a1d9190 (diff)
downloadrust-92ce768ea3dcfe5cda55f2a4607d4245730e0d64.tar.gz
rust-92ce768ea3dcfe5cda55f2a4607d4245730e0d64.zip
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 <anatol.ulrich@ferrous-systems.com>
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/runnables.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index b44d95a5803..6b74ec3430d 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);