diff options
author | Kevin DeLorey <[email protected]> | 2020-02-09 16:25:47 +0000 |
---|---|---|
committer | Kevin DeLorey <[email protected]> | 2020-02-09 16:37:43 +0000 |
commit | a957c473fdb79880c39b73dc9e0c923093cf16ac (patch) | |
tree | f998b548f530ce604651e0e6af314ed2ec74b3b5 /crates/ra_ide/src/runnables.rs | |
parent | 22caf982b99c54058e2e9200aeea0e61cada284a (diff) | |
parent | 1b9b13b4b4a75b5531c3f046ce6bf72d681f2732 (diff) |
Merge branch 'master' into kdelorey/complete-trait-impl
Diffstat (limited to 'crates/ra_ide/src/runnables.rs')
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 7533692f6..b6b0c70f9 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -3,12 +3,13 @@ | |||
3 | use hir::InFile; | 3 | use hir::InFile; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | use ra_db::SourceDatabase; | 5 | use ra_db::SourceDatabase; |
6 | use ra_ide_db::RootDatabase; | ||
6 | use ra_syntax::{ | 7 | use ra_syntax::{ |
7 | ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, | 8 | ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, |
8 | match_ast, SyntaxNode, TextRange, | 9 | match_ast, SyntaxNode, TextRange, |
9 | }; | 10 | }; |
10 | 11 | ||
11 | use crate::{db::RootDatabase, FileId}; | 12 | use crate::FileId; |
12 | 13 | ||
13 | #[derive(Debug)] | 14 | #[derive(Debug)] |
14 | pub struct Runnable { | 15 | pub struct Runnable { |
@@ -43,7 +44,7 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | |||
43 | let name = fn_def.name()?.text().clone(); | 44 | let name = fn_def.name()?.text().clone(); |
44 | let kind = if name == "main" { | 45 | let kind = if name == "main" { |
45 | RunnableKind::Bin | 46 | RunnableKind::Bin |
46 | } else if fn_def.has_atom_attr("test") { | 47 | } else if has_test_related_attribute(&fn_def) { |
47 | RunnableKind::Test { name: name.to_string() } | 48 | RunnableKind::Test { name: name.to_string() } |
48 | } else if fn_def.has_atom_attr("bench") { | 49 | } else if fn_def.has_atom_attr("bench") { |
49 | RunnableKind::Bench { name: name.to_string() } | 50 | RunnableKind::Bench { name: name.to_string() } |
@@ -53,6 +54,20 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> { | |||
53 | Some(Runnable { range: fn_def.syntax().text_range(), kind }) | 54 | Some(Runnable { range: fn_def.syntax().text_range(), kind }) |
54 | } | 55 | } |
55 | 56 | ||
57 | /// This is a method with a heuristics to support test methods annotated with custom test annotations, such as | ||
58 | /// `#[test_case(...)]`, `#[tokio::test]` and similar. | ||
59 | /// Also a regular `#[test]` annotation is supported. | ||
60 | /// | ||
61 | /// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, | ||
62 | /// but it's better than not to have the runnables for the tests at all. | ||
63 | fn has_test_related_attribute(fn_def: &ast::FnDef) -> bool { | ||
64 | fn_def | ||
65 | .attrs() | ||
66 | .filter_map(|attr| attr.path()) | ||
67 | .map(|path| path.syntax().to_string().to_lowercase()) | ||
68 | .any(|attribute_text| attribute_text.contains("test")) | ||
69 | } | ||
70 | |||
56 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { | 71 | fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { |
57 | let has_test_function = module | 72 | let has_test_function = module |
58 | .item_list()? | 73 | .item_list()? |