]> git.lizzy.rs Git - rust.git/commitdiff
Merge #2075
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Sat, 26 Oct 2019 14:38:20 +0000 (14:38 +0000)
committerGitHub <noreply@github.com>
Sat, 26 Oct 2019 14:38:20 +0000 (14:38 +0000)
2075: document a couple of assists r=matklad a=matklad

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
crates/ra_assists/src/assists/add_derive.rs
crates/ra_assists/src/assists/add_explicit_type.rs
crates/ra_assists/src/assists/add_impl.rs
crates/ra_assists/src/assists/add_missing_impl_members.rs
crates/ra_assists/src/assists/apply_demorgan.rs
crates/ra_assists/src/assists/change_visibility.rs
crates/ra_assists/src/assists/fill_match_arms.rs
crates/ra_assists/src/doc_tests/generated.rs
docs/user/assists.md
docs/user/features.md
xtask/src/codegen/gen_assists_docs.rs

index d3ba634c401821f13e6c17872ea94c35189c69f7..b077acb8142ab970b94c59c9502404a4a880b979 100644 (file)
@@ -8,7 +8,9 @@
 use crate::{Assist, AssistCtx, AssistId};
 
 // Assist: add_derive
+//
 // Adds a new `#[derive()]` clause to a struct or enum.
+//
 // ```
 // struct Point {
 //     x: u32,
index 33b7bea7f2b11e289aa910bcb983febfc015943c..302b9557908360e4e7e616bb9ae0a80db025b791 100644 (file)
@@ -7,7 +7,9 @@
 use crate::{Assist, AssistCtx, AssistId};
 
 // Assist: add_explicit_type
+//
 // Specify type for a let binding
+//
 // ```
 // fn main() {
 //     let x<|> = 92;
index 40bc5c4641d80443874fbfc1d2da8142ba03c4db..43aeac7bd6e7239367d89d1bf2b667aa0f470f15 100644 (file)
@@ -9,7 +9,9 @@
 use crate::{Assist, AssistCtx, AssistId};
 
 // Assist: add_impl
+//
 // Adds a new inherent impl for a type
+//
 // ```
 // struct Ctx<T: Clone> {
 //      data: T,<|>
index 36fa6f9ea7a56290ca16fe04309b9000ff6191ae..fe1f2e72e7f563e6c630e8c48cfe8b523d8a43cf 100644 (file)
@@ -13,7 +13,9 @@ enum AddMissingImplMembersMode {
 }
 
 // Assist: add_impl_missing_members
+//
 // Adds scaffold for required impl members
+//
 // ```
 // trait T {
 //     Type X;
index a072f63e7a8a9d98d1a8e280c17015c0c5369e4e..75144cefe2e0d196556be226bdc7dc30d4fb15c7 100644 (file)
@@ -5,11 +5,13 @@
 use crate::{Assist, AssistCtx, AssistId};
 
 // Assist: apply_demorgan
+//
 // Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
 // This transforms expressions of the form `!l || !r` into `!(l && r)`.
 // This also works with `&&`. This assist can only be applied with the cursor
 // on either `||` or `&&`, with both operands being a negation of some kind.
 // This means something of the form `!x` or `x != y`.
+//
 // ```
 // fn main() {
 //     if x != 4 ||<|> !y {}
index df92c6b67c994941e4c7a63d34e2a7c15b2ed8d4..88118cdf7c04b161dd3e39526c8ae742cdbb8d2e 100644 (file)
@@ -1,5 +1,3 @@
-//! FIXME: write short doc here
-
 use hir::db::HirDatabase;
 use ra_syntax::{
     ast::{self, NameOwner, VisibilityOwner},
 
 use crate::{Assist, AssistCtx, AssistId};
 
+// Assist: change_visibility
+//
+// Adds or changes existing visibility specifier.
+//
+// ```
+// fn<|> frobnicate() {}
+// ```
+// ->
+// ```
+// pub(crate) fn frobnicate() {}
+// ```
 pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
     if let Some(vis) = ctx.node_at_offset::<ast::Visibility>() {
         return change_vis(ctx, vis);
index e3f30b5defceca317a1f1f9a82c56702b2b08406..13b98d033359ca89dfa886a9e29c50a98340cf45 100644 (file)
@@ -7,6 +7,30 @@
 
 use crate::{Assist, AssistCtx, AssistId};
 
+// Assist: fill_match_arms
+//
+// Adds missing clauses to a `match` expression.
+//
+// ```
+// enum Action { Move { distance: u32 }, Stop }
+//
+// fn handle(action: Action) {
+//     match action {
+//         <|>
+//     }
+// }
+// ```
+// ->
+// ```
+// enum Action { Move { distance: u32 }, Stop }
+//
+// fn handle(action: Action) {
+//     match action {
+//         Action::Move{ distance } => (),
+//         Action::Stop => (),
+//     }
+// }
+// ```
 pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
     let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?;
     let match_arm_list = match_expr.match_arm_list()?;
index 76d86b93dadfeba1ed70e66b766e1f4253a14f04..2f36c3baa31ee3e15849ad4df69596d245ff81ae 100644 (file)
@@ -141,6 +141,19 @@ fn main() {
     )
 }
 
+#[test]
+fn doctest_change_visibility() {
+    check(
+        "change_visibility",
+        r#####"
+fn<|> frobnicate() {}
+"#####,
+        r#####"
+pub(crate) fn frobnicate() {}
+"#####,
+    )
+}
+
 #[test]
 fn doctest_convert_to_guarded_return() {
     check(
@@ -164,3 +177,29 @@ fn main() {
 "#####,
     )
 }
+
+#[test]
+fn doctest_fill_match_arms() {
+    check(
+        "fill_match_arms",
+        r#####"
+enum Action { Move { distance: u32 }, Stop }
+
+fn handle(action: Action) {
+    match action {
+        <|>
+    }
+}
+"#####,
+        r#####"
+enum Action { Move { distance: u32 }, Stop }
+
+fn handle(action: Action) {
+    match action {
+        Action::Move{ distance } => (),
+        Action::Stop => (),
+    }
+}
+"#####,
+    )
+}
index eeb48683217844dc58be2f4fe48ad3d058bff0e4..7a64c80ad599d1474884c21c9ca71b9b0b60a166 100644 (file)
@@ -137,6 +137,18 @@ fn main() {
 }
 ```
 
+## `change_visibility`
+
+Adds or changes existing visibility specifier.
+
+```rust
+// BEFORE
+fn<|> frobnicate() {}
+
+// AFTER
+pub(crate) fn frobnicate() {}
+```
+
 ## `convert_to_guarded_return`
 
 Replace a large conditional with a guarded return.
@@ -159,3 +171,28 @@ fn main() {
     bar();
 }
 ```
+
+## `fill_match_arms`
+
+Adds missing clauses to a `match` expression.
+
+```rust
+// BEFORE
+enum Action { Move { distance: u32 }, Stop }
+
+fn handle(action: Action) {
+    match action {
+        <|>
+    }
+}
+
+// AFTER
+enum Action { Move { distance: u32 }, Stop }
+
+fn handle(action: Action) {
+    match action {
+        Action::Move{ distance } => (),
+        Action::Stop => (),
+    }
+}
+```
index acf092cec1bb26e41b2e92d6a0811fc4a5c7a1e5..39dab710dd26e17372de2e7ae0addf4521bb759d 100644 (file)
@@ -118,57 +118,6 @@ impl Debug<|> for Foo {
 }
 ```
 
-- Change Visibility
-
-```rust
-// before:
-<|>fn foo() {}
-
-// after:
-<|>pub(crate) fn foo() {}
-
-// after:
-<|>pub fn foo() {}
-```
-
-- Fill match arms
-
-```rust
-// before:
-enum A {
-    As,
-    Bs,
-    Cs(String),
-    Ds(String, String),
-    Es{x: usize, y: usize}
-}
-
-fn main() {
-    let a = A::As;
-    match a<|> {}
-}
-
-// after:
-enum A {
-    As,
-    Bs,
-    Cs(String),
-    Ds(String, String),
-    Es{x: usize, y: usize}
-}
-
-fn main() {
-    let a = A::As;
-    match <|>a {
-        A::As => (),
-        A::Bs => (),
-        A::Cs(_) => (),
-        A::Ds(_, _) => (),
-        A::Es{x, y} => (),
-    }
-}
-```
-
 - Fill struct fields
 
 ```rust
index e313820d18a5a0bc57f3b4ad702e51534a2dfa9f..2ca7cda63dbe421337c15b70aa703afbff9b5068 100644 (file)
@@ -51,7 +51,7 @@ fn collect_file(acc: &mut Vec<Assist>, path: &Path) -> Result<()> {
                 id
             );
 
-            let doc = take_until(lines.by_ref(), "```");
+            let doc = take_until(lines.by_ref(), "```").trim().to_string();
             let before = take_until(lines.by_ref(), "```");
 
             assert_eq!(lines.next().unwrap().as_str(), "->");