diff options
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r-- | crates/assists/src/utils.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index caabc44de..66c0cdd5f 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -9,6 +9,7 @@ use ide_db::RootDatabase; | |||
9 | use itertools::Itertools; | 9 | use itertools::Itertools; |
10 | use syntax::{ | 10 | use syntax::{ |
11 | ast::edit::AstNodeEdit, | 11 | ast::edit::AstNodeEdit, |
12 | ast::AttrsOwner, | ||
12 | ast::NameOwner, | 13 | ast::NameOwner, |
13 | ast::{self, edit, make, ArgListOwner}, | 14 | ast::{self, edit, make, ArgListOwner}, |
14 | AstNode, Direction, | 15 | AstNode, Direction, |
@@ -81,6 +82,23 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { | |||
81 | None | 82 | None |
82 | } | 83 | } |
83 | 84 | ||
85 | /// This is a method with a heuristics to support test methods annotated with custom test annotations, such as | ||
86 | /// `#[test_case(...)]`, `#[tokio::test]` and similar. | ||
87 | /// Also a regular `#[test]` annotation is supported. | ||
88 | /// | ||
89 | /// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, | ||
90 | /// but it's better than not to have the runnables for the tests at all. | ||
91 | pub fn test_related_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> { | ||
92 | fn_def.attrs().find_map(|attr| { | ||
93 | let path = attr.path()?; | ||
94 | if path.syntax().text().to_string().contains("test") { | ||
95 | Some(attr) | ||
96 | } else { | ||
97 | None | ||
98 | } | ||
99 | }) | ||
100 | } | ||
101 | |||
84 | #[derive(Copy, Clone, PartialEq)] | 102 | #[derive(Copy, Clone, PartialEq)] |
85 | pub enum DefaultMethods { | 103 | pub enum DefaultMethods { |
86 | Only, | 104 | Only, |