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/ide/src/fn_references.rs | 5 +++-- crates/ide/src/runnables.rs | 19 +++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/fn_references.rs b/crates/ide/src/fn_references.rs index 459f201ed..5cbbe306e 100644 --- a/crates/ide/src/fn_references.rs +++ b/crates/ide/src/fn_references.rs @@ -1,11 +1,12 @@ //! This module implements a methods and free functions search in the specified file. //! We have to skip tests, so cannot reuse file_structure module. +use assists::utils::test_related_attribute; use hir::Semantics; use ide_db::RootDatabase; use syntax::{ast, ast::NameOwner, AstNode, SyntaxNode}; -use crate::{runnables::has_test_related_attribute, FileId, FileRange}; +use crate::{FileId, FileRange}; pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec { let sema = Semantics::new(db); @@ -15,7 +16,7 @@ pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec Option { ast::Fn::cast(item).and_then(|fn_def| { - if has_test_related_attribute(&fn_def) { + if test_related_attribute(&fn_def).is_some() { None } else { fn_def.name().map(|name| FileRange { file_id, range: name.syntax().text_range() }) diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 2bd0e86e5..e15411777 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -1,5 +1,6 @@ use std::fmt; +use assists::utils::test_related_attribute; use cfg::CfgExpr; use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; use ide_db::RootDatabase; @@ -156,7 +157,7 @@ fn runnable_fn( None => TestId::Name(name_string), }; - if has_test_related_attribute(&fn_def) { + if test_related_attribute(&fn_def).is_some() { let attr = TestAttr::from_fn(&fn_def); RunnableKind::Test { test_id, attr } } else if fn_def.has_atom_attr("bench") { @@ -235,20 +236,6 @@ impl TestAttr { } } -/// 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(crate) fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { - fn_def - .attrs() - .filter_map(|attr| attr.path()) - .map(|path| path.syntax().to_string().to_lowercase()) - .any(|attribute_text| attribute_text.contains("test")) -} - const RUSTDOC_FENCE: &str = "```"; const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = &["", "rust", "should_panic", "edition2015", "edition2018"]; @@ -307,7 +294,7 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { for item in item_list.items() { match item { ast::Item::Fn(f) => { - if has_test_related_attribute(&f) { + if test_related_attribute(&f).is_some() { return true; } } -- cgit v1.2.3