From 724059569b4c775ee4723640e0eaabe0da7cdeaf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Jan 2021 14:30:50 +0300 Subject: [PATCH] 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. --- crates/ide/src/runnables.rs | 35 ++++++++++++++++++++++++++++++++--- docs/dev/style.md | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 8976f1080f5..13582e61f6c 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -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 { 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, module: hir::Module) -> Vec 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#" + [] + "#]], + ); + } } diff --git a/docs/dev/style.md b/docs/dev/style.md index 21330948ba5..aed15cee932 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -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. -- 2.44.0