diff --git a/crates/assists/src/handlers/ignore_test.rs b/crates/assists/src/handlers/toggle_ignore.rs similarity index 81% rename from crates/assists/src/handlers/ignore_test.rs rename to crates/assists/src/handlers/toggle_ignore.rs index 5096a00058..14b420421e 100644 --- a/crates/assists/src/handlers/ignore_test.rs +++ b/crates/assists/src/handlers/toggle_ignore.rs @@ -5,7 +5,7 @@ use syntax::{ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, Assists}; -// Assist: ignore_test +// Assist: toggle_ignore // // Adds `#[ignore]` attribute to the test. // @@ -23,20 +23,20 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, // assert_eq!(2 + 2, 5); // } // ``` -pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { +pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let attr: ast::Attr = ctx.find_node_at_offset()?; let func = attr.syntax().parent().and_then(ast::Fn::cast)?; let attr = test_related_attribute(&func)?; match has_ignore_attribute(&func) { None => acc.add( - AssistId("ignore_test", AssistKind::None), + AssistId("toggle_ignore", AssistKind::None), "Ignore this test", attr.syntax().text_range(), |builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")), ), Some(ignore_attr) => acc.add( - AssistId("unignore_test", AssistKind::None), + AssistId("toggle_ignore", AssistKind::None), "Re-enable this test", ignore_attr.syntax().text_range(), |builder| { @@ -55,24 +55,19 @@ pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } fn has_ignore_attribute(fn_def: &ast::Fn) -> Option { - fn_def.attrs().find_map(|attr| { - if attr.path()?.syntax().text() == "ignore" { - Some(attr) - } else { - None - } - }) + fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true)) } #[cfg(test)] mod tests { - use super::ignore_test; use crate::tests::check_assist; + use super::*; + #[test] fn test_base_case() { check_assist( - ignore_test, + toggle_ignore, r#" #[test<|>] fn test() {} @@ -88,7 +83,7 @@ mod tests { #[test] fn test_unignore() { check_assist( - ignore_test, + toggle_ignore, r#" #[test<|>] #[ignore] diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index 17e9312db2..dfe6c27295 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs @@ -141,7 +141,6 @@ mod handlers { mod generate_function; mod generate_impl; mod generate_new; - mod ignore_test; mod infer_function_return_type; mod inline_local_variable; mod introduce_named_lifetime; @@ -164,6 +163,7 @@ mod handlers { mod replace_string_with_char; mod replace_unwrap_with_match; mod split_import; + mod toggle_ignore; mod unwrap_block; mod wrap_return_type_in_result; @@ -190,7 +190,6 @@ mod handlers { generate_function::generate_function, generate_impl::generate_impl, generate_new::generate_new, - ignore_test::ignore_test, infer_function_return_type::infer_function_return_type, inline_local_variable::inline_local_variable, introduce_named_lifetime::introduce_named_lifetime, @@ -215,6 +214,7 @@ mod handlers { replace_qualified_name_with_use::replace_qualified_name_with_use, replace_unwrap_with_match::replace_unwrap_with_match, split_import::split_import, + toggle_ignore::toggle_ignore, unwrap_block::unwrap_block, wrap_return_type_in_result::wrap_return_type_in_result, // These are manually sorted for better priorities diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 5a9d1a01b7..8d50c8791a 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs @@ -473,26 +473,6 @@ impl Ctx { ) } -#[test] -fn doctest_ignore_test() { - check_doc_test( - "ignore_test", - r#####" -<|>#[test] -fn arithmetics { - assert_eq!(2 + 2, 5); -} -"#####, - r#####" -#[test] -#[ignore] -fn arithmetics { - assert_eq!(2 + 2, 5); -} -"#####, - ) -} - #[test] fn doctest_infer_function_return_type() { check_doc_test( @@ -978,6 +958,26 @@ use std::{collections::HashMap}; ) } +#[test] +fn doctest_toggle_ignore() { + check_doc_test( + "toggle_ignore", + r#####" +<|>#[test] +fn arithmetics { + assert_eq!(2 + 2, 5); +} +"#####, + r#####" +#[test] +#[ignore] +fn arithmetics { + assert_eq!(2 + 2, 5); +} +"#####, + ) +} + #[test] fn doctest_unwrap_block() { check_doc_test(