From 394e4744792f8e36ca1690cb23c2d3dd55556272 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:27:47 +0300 Subject: add blank lines for readability --- crates/ra_assists/src/assists/add_derive.rs | 2 ++ crates/ra_assists/src/assists/add_explicit_type.rs | 2 ++ crates/ra_assists/src/assists/add_impl.rs | 2 ++ crates/ra_assists/src/assists/add_missing_impl_members.rs | 2 ++ crates/ra_assists/src/assists/apply_demorgan.rs | 2 ++ xtask/src/codegen/gen_assists_docs.rs | 2 +- 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/ra_assists/src/assists/add_derive.rs b/crates/ra_assists/src/assists/add_derive.rs index d3ba634c4..b077acb81 100644 --- a/crates/ra_assists/src/assists/add_derive.rs +++ b/crates/ra_assists/src/assists/add_derive.rs @@ -8,7 +8,9 @@ use ra_syntax::{ use crate::{Assist, AssistCtx, AssistId}; // Assist: add_derive +// // Adds a new `#[derive()]` clause to a struct or enum. +// // ``` // struct Point { // x: u32, diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index 33b7bea7f..302b95579 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs @@ -7,7 +7,9 @@ use ra_syntax::{ use crate::{Assist, AssistCtx, AssistId}; // Assist: add_explicit_type +// // Specify type for a let binding +// // ``` // fn main() { // let x<|> = 92; diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/assists/add_impl.rs index 40bc5c464..43aeac7bd 100644 --- a/crates/ra_assists/src/assists/add_impl.rs +++ b/crates/ra_assists/src/assists/add_impl.rs @@ -9,7 +9,9 @@ use ra_syntax::{ use crate::{Assist, AssistCtx, AssistId}; // Assist: add_impl +// // Adds a new inherent impl for a type +// // ``` // struct Ctx { // data: T,<|> diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 36fa6f9ea..fe1f2e72e 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs @@ -13,7 +13,9 @@ enum AddMissingImplMembersMode { } // Assist: add_impl_missing_members +// // Adds scaffold for required impl members +// // ``` // trait T { // Type X; diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs index a072f63e7..75144cefe 100644 --- a/crates/ra_assists/src/assists/apply_demorgan.rs +++ b/crates/ra_assists/src/assists/apply_demorgan.rs @@ -5,11 +5,13 @@ use ra_syntax::SyntaxNode; 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 {} diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index e313820d1..2ca7cda63 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs @@ -51,7 +51,7 @@ fn collect_assists() -> 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(), "->"); -- cgit v1.2.3 From 3126152a84e08a80659d49d735d03628154564ed Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:37:04 +0300 Subject: document a couple of assists --- crates/ra_assists/src/assists/change_visibility.rs | 13 +++++- crates/ra_assists/src/assists/fill_match_arms.rs | 24 ++++++++++ crates/ra_assists/src/doc_tests/generated.rs | 39 +++++++++++++++++ docs/user/assists.md | 37 ++++++++++++++++ docs/user/features.md | 51 ---------------------- 5 files changed, 111 insertions(+), 53 deletions(-) diff --git a/crates/ra_assists/src/assists/change_visibility.rs b/crates/ra_assists/src/assists/change_visibility.rs index df92c6b67..88118cdf7 100644 --- a/crates/ra_assists/src/assists/change_visibility.rs +++ b/crates/ra_assists/src/assists/change_visibility.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::db::HirDatabase; use ra_syntax::{ ast::{self, NameOwner, VisibilityOwner}, @@ -13,6 +11,17 @@ use ra_syntax::{ 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) -> Option { if let Some(vis) = ctx.node_at_offset::() { return change_vis(ctx, vis); diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index e3f30b5de..13b98d033 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs @@ -7,6 +7,30 @@ use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner}; 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) -> Option { let match_expr = ctx.node_at_offset::()?; let match_arm_list = match_expr.match_arm_list()?; diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index 76d86b93d..2f36c3baa 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -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 => (), + } +} +"#####, + ) +} diff --git a/docs/user/assists.md b/docs/user/assists.md index eeb486832..7a64c80ad 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -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 => (), + } +} +``` diff --git a/docs/user/features.md b/docs/user/features.md index acf092cec..39dab710d 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -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 -- cgit v1.2.3