2 ast::{self, AttrsOwner},
6 use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, Assists};
8 // Assist: toggle_ignore
10 // Adds `#[ignore]` attribute to the test.
15 // assert_eq!(2 + 2, 5);
23 // assert_eq!(2 + 2, 5);
26 pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
27 let attr: ast::Attr = ctx.find_node_at_offset()?;
28 let func = attr.syntax().parent().and_then(ast::Fn::cast)?;
29 let attr = test_related_attribute(&func)?;
31 match has_ignore_attribute(&func) {
33 AssistId("toggle_ignore", AssistKind::None),
35 attr.syntax().text_range(),
36 |builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")),
38 Some(ignore_attr) => acc.add(
39 AssistId("toggle_ignore", AssistKind::None),
40 "Re-enable this test",
41 ignore_attr.syntax().text_range(),
43 builder.delete(ignore_attr.syntax().text_range());
44 let whitespace = ignore_attr
46 .next_sibling_or_token()
47 .and_then(|x| x.into_token())
48 .and_then(ast::Whitespace::cast);
49 if let Some(whitespace) = whitespace {
50 builder.delete(whitespace.syntax().text_range());
57 fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
58 fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
63 use crate::tests::check_assist;