aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r--crates/assists/src/handlers/toggle_ignore.rs (renamed from crates/assists/src/handlers/ignore_test.rs)23
1 files changed, 9 insertions, 14 deletions
diff --git a/crates/assists/src/handlers/ignore_test.rs b/crates/assists/src/handlers/toggle_ignore.rs
index 5096a0005..14b420421 100644
--- a/crates/assists/src/handlers/ignore_test.rs
+++ b/crates/assists/src/handlers/toggle_ignore.rs
@@ -5,7 +5,7 @@ use syntax::{
5 5
6use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, Assists}; 6use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind, Assists};
7 7
8// Assist: ignore_test 8// Assist: toggle_ignore
9// 9//
10// Adds `#[ignore]` attribute to the test. 10// Adds `#[ignore]` attribute to the test.
11// 11//
@@ -23,20 +23,20 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind,
23// assert_eq!(2 + 2, 5); 23// assert_eq!(2 + 2, 5);
24// } 24// }
25// ``` 25// ```
26pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 26pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
27 let attr: ast::Attr = ctx.find_node_at_offset()?; 27 let attr: ast::Attr = ctx.find_node_at_offset()?;
28 let func = attr.syntax().parent().and_then(ast::Fn::cast)?; 28 let func = attr.syntax().parent().and_then(ast::Fn::cast)?;
29 let attr = test_related_attribute(&func)?; 29 let attr = test_related_attribute(&func)?;
30 30
31 match has_ignore_attribute(&func) { 31 match has_ignore_attribute(&func) {
32 None => acc.add( 32 None => acc.add(
33 AssistId("ignore_test", AssistKind::None), 33 AssistId("toggle_ignore", AssistKind::None),
34 "Ignore this test", 34 "Ignore this test",
35 attr.syntax().text_range(), 35 attr.syntax().text_range(),
36 |builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")), 36 |builder| builder.insert(attr.syntax().text_range().end(), &format!("\n#[ignore]")),
37 ), 37 ),
38 Some(ignore_attr) => acc.add( 38 Some(ignore_attr) => acc.add(
39 AssistId("unignore_test", AssistKind::None), 39 AssistId("toggle_ignore", AssistKind::None),
40 "Re-enable this test", 40 "Re-enable this test",
41 ignore_attr.syntax().text_range(), 41 ignore_attr.syntax().text_range(),
42 |builder| { 42 |builder| {
@@ -55,24 +55,19 @@ pub(crate) fn ignore_test(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
55} 55}
56 56
57fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> { 57fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
58 fn_def.attrs().find_map(|attr| { 58 fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
59 if attr.path()?.syntax().text() == "ignore" {
60 Some(attr)
61 } else {
62 None
63 }
64 })
65} 59}
66 60
67#[cfg(test)] 61#[cfg(test)]
68mod tests { 62mod tests {
69 use super::ignore_test;
70 use crate::tests::check_assist; 63 use crate::tests::check_assist;
71 64
65 use super::*;
66
72 #[test] 67 #[test]
73 fn test_base_case() { 68 fn test_base_case() {
74 check_assist( 69 check_assist(
75 ignore_test, 70 toggle_ignore,
76 r#" 71 r#"
77 #[test<|>] 72 #[test<|>]
78 fn test() {} 73 fn test() {}
@@ -88,7 +83,7 @@ mod tests {
88 #[test] 83 #[test]
89 fn test_unignore() { 84 fn test_unignore() {
90 check_assist( 85 check_assist(
91 ignore_test, 86 toggle_ignore,
92 r#" 87 r#"
93 #[test<|>] 88 #[test<|>]
94 #[ignore] 89 #[ignore]