]> git.lizzy.rs Git - rust.git/commitdiff
Don't show runnable suggestions for other files
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jan 2021 11:30:50 +0000 (14:30 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jan 2021 11:30:50 +0000 (14:30 +0300)
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.

crates/ide/src/runnables.rs
docs/dev/style.md

index 8976f1080f58588d880c47ea20ec101f03d04784..13582e61f6cb8e24db25712dc552e8936b959370 100644 (file)
@@ -9,6 +9,7 @@
     ast::{self, AstNode, AttrsOwner},
     match_ast, SyntaxNode,
 };
+use test_utils::mark;
 
 use crate::{
     display::{ToNav, TryToNav},
@@ -96,7 +97,7 @@ pub fn action(&self) -> &'static RunnableAction {
 pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
     let sema = Semantics::new(db);
     let module = match sema.to_module_def(file_id) {
-        None => return vec![],
+        None => return Vec::new(),
         Some(it) => it,
     };
 
@@ -128,8 +129,14 @@ fn runnables_mod(sema: &Semantics<RootDatabase>, module: hir::Module) -> Vec<Run
     ));
 
     res.extend(module.declarations(sema.db).into_iter().flat_map(|def| match def {
-        hir::ModuleDef::Module(it) => runnables_mod(sema, it),
-        _ => vec![],
+        hir::ModuleDef::Module(submodule) => match submodule.definition_source(sema.db).value {
+            hir::ModuleSource::SourceFile(_) => {
+                mark::hit!(dont_recurse_in_outline_submodules);
+                Vec::new()
+            }
+            hir::ModuleSource::Module(_) => runnables_mod(sema, submodule),
+        },
+        _ => Vec::new(),
     }));
 
     res
@@ -326,6 +333,7 @@ fn has_test_function_or_multiple_test_submodules(
 #[cfg(test)]
 mod tests {
     use expect_test::{expect, Expect};
+    use test_utils::mark;
 
     use crate::fixture;
 
@@ -1050,4 +1058,25 @@ mod tests {
             "#]],
         );
     }
+
+    #[test]
+    fn dont_recurse_in_outline_submodules() {
+        mark::check!(dont_recurse_in_outline_submodules);
+        check(
+            r#"
+//- /lib.rs
+$0
+mod m;
+//- /m.rs
+mod tests {
+    #[test]
+    fn t() {}
+}
+"#,
+            &[],
+            expect![[r#"
+                []
+            "#]],
+        );
+    }
 }
index 21330948ba5a38ca17834d7cbc994de18d73dee7..aed15cee932f946f741a202c2cf9665149a0c0a8 100644 (file)
@@ -280,6 +280,9 @@ Prefer `Default` even it has to be implemented manually.
 
 **Rationale:** less typing in the common case, uniformity.
 
+Use `Vec::new` rather than `vec![]`. **Rationale:** uniformity, strength
+reduction.
+
 ## Functions Over Objects
 
 Avoid creating "doer" objects.