From 9a30707281d3a978741a549196b71a27284f7240 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 17 Nov 2020 14:22:04 +0100 Subject: Add **Ignore Test** assist --- crates/assists/src/utils.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/assists/src/utils.rs') diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 7bd338e99..d1a0a99b1 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -9,6 +9,7 @@ use ide_db::RootDatabase; use itertools::Itertools; use syntax::{ ast::edit::AstNodeEdit, + ast::AttrsOwner, ast::NameOwner, ast::{self, edit, make, ArgListOwner}, AstNode, Direction, @@ -82,6 +83,23 @@ pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option { None } +/// This is a method with a heuristics to support test methods annotated with custom test annotations, such as +/// `#[test_case(...)]`, `#[tokio::test]` and similar. +/// Also a regular `#[test]` annotation is supported. +/// +/// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, +/// but it's better than not to have the runnables for the tests at all. +pub fn test_related_attribute(fn_def: &ast::Fn) -> Option { + fn_def.attrs().find_map(|attr| { + let path = attr.path()?; + if path.syntax().text().to_string().contains("test") { + Some(attr) + } else { + None + } + }) +} + #[derive(Copy, Clone, PartialEq)] pub enum DefaultMethods { Only, -- cgit v1.2.3