aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-01-20 11:30:50 +0000
committerAleksey Kladov <[email protected]>2021-01-20 11:30:50 +0000
commit724059569b4c775ee4723640e0eaabe0da7cdeaf (patch)
treef770da961fcdc3e17d8c8e622cbc4e34c5ef91e2 /crates
parent3429b32ad119756985e1a7bfa5e9e53042671f8b (diff)
Don't show runnable suggestions for other files
It't be actually great to have these once we have run anything dialog, but for run the thing at point it makes sense to show a limited set.
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/runnables.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index 8976f1080..13582e61f 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -9,6 +9,7 @@ use syntax::{
9 ast::{self, AstNode, AttrsOwner}, 9 ast::{self, AstNode, AttrsOwner},
10 match_ast, SyntaxNode, 10 match_ast, SyntaxNode,
11}; 11};
12use test_utils::mark;
12 13
13use crate::{ 14use crate::{
14 display::{ToNav, TryToNav}, 15 display::{ToNav, TryToNav},
@@ -96,7 +97,7 @@ impl Runnable {
96pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> { 97pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
97 let sema = Semantics::new(db); 98 let sema = Semantics::new(db);
98 let module = match sema.to_module_def(file_id) { 99 let module = match sema.to_module_def(file_id) {
99 None => return vec![], 100 None => return Vec::new(),
100 Some(it) => it, 101 Some(it) => it,
101 }; 102 };
102 103
@@ -128,8 +129,14 @@ fn runnables_mod(sema: &Semantics<RootDatabase>, module: hir::Module) -> Vec<Run
128 )); 129 ));
129 130
130 res.extend(module.declarations(sema.db).into_iter().flat_map(|def| match def { 131 res.extend(module.declarations(sema.db).into_iter().flat_map(|def| match def {
131 hir::ModuleDef::Module(it) => runnables_mod(sema, it), 132 hir::ModuleDef::Module(submodule) => match submodule.definition_source(sema.db).value {
132 _ => vec![], 133 hir::ModuleSource::SourceFile(_) => {
134 mark::hit!(dont_recurse_in_outline_submodules);
135 Vec::new()
136 }
137 hir::ModuleSource::Module(_) => runnables_mod(sema, submodule),
138 },
139 _ => Vec::new(),
133 })); 140 }));
134 141
135 res 142 res
@@ -326,6 +333,7 @@ fn has_test_function_or_multiple_test_submodules(
326#[cfg(test)] 333#[cfg(test)]
327mod tests { 334mod tests {
328 use expect_test::{expect, Expect}; 335 use expect_test::{expect, Expect};
336 use test_utils::mark;
329 337
330 use crate::fixture; 338 use crate::fixture;
331 339
@@ -1050,4 +1058,25 @@ mod tests {
1050 "#]], 1058 "#]],
1051 ); 1059 );
1052 } 1060 }
1061
1062 #[test]
1063 fn dont_recurse_in_outline_submodules() {
1064 mark::check!(dont_recurse_in_outline_submodules);
1065 check(
1066 r#"
1067//- /lib.rs
1068$0
1069mod m;
1070//- /m.rs
1071mod tests {
1072 #[test]
1073 fn t() {}
1074}
1075"#,
1076 &[],
1077 expect![[r#"
1078 []
1079 "#]],
1080 );
1081 }
1053} 1082}