aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/runnables.rs35
-rw-r--r--docs/dev/style.md3
2 files changed, 35 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}
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 21330948b..aed15cee9 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -280,6 +280,9 @@ Prefer `Default` even it has to be implemented manually.
280 280
281**Rationale:** less typing in the common case, uniformity. 281**Rationale:** less typing in the common case, uniformity.
282 282
283Use `Vec::new` rather than `vec![]`. **Rationale:** uniformity, strength
284reduction.
285
283## Functions Over Objects 286## Functions Over Objects
284 287
285Avoid creating "doer" objects. 288Avoid creating "doer" objects.