aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/toggle_ignore.rs (renamed from crates/assists/src/handlers/ignore_test.rs)23
-rw-r--r--crates/assists/src/lib.rs4
-rw-r--r--crates/assists/src/tests/generated.rs40
3 files changed, 31 insertions, 36 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]
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs
index 17e9312db..dfe6c2729 100644
--- a/crates/assists/src/lib.rs
+++ b/crates/assists/src/lib.rs
@@ -141,7 +141,6 @@ mod handlers {
141 mod generate_function; 141 mod generate_function;
142 mod generate_impl; 142 mod generate_impl;
143 mod generate_new; 143 mod generate_new;
144 mod ignore_test;
145 mod infer_function_return_type; 144 mod infer_function_return_type;
146 mod inline_local_variable; 145 mod inline_local_variable;
147 mod introduce_named_lifetime; 146 mod introduce_named_lifetime;
@@ -164,6 +163,7 @@ mod handlers {
164 mod replace_string_with_char; 163 mod replace_string_with_char;
165 mod replace_unwrap_with_match; 164 mod replace_unwrap_with_match;
166 mod split_import; 165 mod split_import;
166 mod toggle_ignore;
167 mod unwrap_block; 167 mod unwrap_block;
168 mod wrap_return_type_in_result; 168 mod wrap_return_type_in_result;
169 169
@@ -190,7 +190,6 @@ mod handlers {
190 generate_function::generate_function, 190 generate_function::generate_function,
191 generate_impl::generate_impl, 191 generate_impl::generate_impl,
192 generate_new::generate_new, 192 generate_new::generate_new,
193 ignore_test::ignore_test,
194 infer_function_return_type::infer_function_return_type, 193 infer_function_return_type::infer_function_return_type,
195 inline_local_variable::inline_local_variable, 194 inline_local_variable::inline_local_variable,
196 introduce_named_lifetime::introduce_named_lifetime, 195 introduce_named_lifetime::introduce_named_lifetime,
@@ -215,6 +214,7 @@ mod handlers {
215 replace_qualified_name_with_use::replace_qualified_name_with_use, 214 replace_qualified_name_with_use::replace_qualified_name_with_use,
216 replace_unwrap_with_match::replace_unwrap_with_match, 215 replace_unwrap_with_match::replace_unwrap_with_match,
217 split_import::split_import, 216 split_import::split_import,
217 toggle_ignore::toggle_ignore,
218 unwrap_block::unwrap_block, 218 unwrap_block::unwrap_block,
219 wrap_return_type_in_result::wrap_return_type_in_result, 219 wrap_return_type_in_result::wrap_return_type_in_result,
220 // These are manually sorted for better priorities 220 // These are manually sorted for better priorities
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index 5a9d1a01b..8d50c8791 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -474,26 +474,6 @@ impl<T: Clone> Ctx<T> {
474} 474}
475 475
476#[test] 476#[test]
477fn doctest_ignore_test() {
478 check_doc_test(
479 "ignore_test",
480 r#####"
481<|>#[test]
482fn arithmetics {
483 assert_eq!(2 + 2, 5);
484}
485"#####,
486 r#####"
487#[test]
488#[ignore]
489fn arithmetics {
490 assert_eq!(2 + 2, 5);
491}
492"#####,
493 )
494}
495
496#[test]
497fn doctest_infer_function_return_type() { 477fn doctest_infer_function_return_type() {
498 check_doc_test( 478 check_doc_test(
499 "infer_function_return_type", 479 "infer_function_return_type",
@@ -979,6 +959,26 @@ use std::{collections::HashMap};
979} 959}
980 960
981#[test] 961#[test]
962fn doctest_toggle_ignore() {
963 check_doc_test(
964 "toggle_ignore",
965 r#####"
966<|>#[test]
967fn arithmetics {
968 assert_eq!(2 + 2, 5);
969}
970"#####,
971 r#####"
972#[test]
973#[ignore]
974fn arithmetics {
975 assert_eq!(2 + 2, 5);
976}
977"#####,
978 )
979}
980
981#[test]
982fn doctest_unwrap_block() { 982fn doctest_unwrap_block() {
983 check_doc_test( 983 check_doc_test(
984 "unwrap_block", 984 "unwrap_block",