From a5cbd8d5e8aca0d0d8dde175ba13bfa995a753c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 19:08:13 +0300 Subject: check style for assist docs --- crates/ra_assists/src/assists/add_explicit_type.rs | 2 +- crates/ra_assists/src/assists/add_impl.rs | 2 +- .../src/assists/add_missing_impl_members.rs | 6 ++- crates/ra_assists/src/assists/early_return.rs | 2 + crates/ra_assists/src/assists/flip_binexpr.rs | 18 ++++++-- crates/ra_assists/src/assists/flip_comma.rs | 17 ++++++- .../src/assists/inline_local_variable.rs | 18 +++++++- crates/ra_assists/src/doc_tests/generated.rs | 52 ++++++++++++++++++++++ 8 files changed, 106 insertions(+), 11 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index 302b95579..2903c1781 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs @@ -8,7 +8,7 @@ use crate::{Assist, AssistCtx, AssistId}; // Assist: add_explicit_type // -// Specify type for a let binding +// Specify type for a let binding. // // ``` // fn main() { diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/assists/add_impl.rs index 43aeac7bd..142777b06 100644 --- a/crates/ra_assists/src/assists/add_impl.rs +++ b/crates/ra_assists/src/assists/add_impl.rs @@ -10,7 +10,7 @@ use crate::{Assist, AssistCtx, AssistId}; // Assist: add_impl // -// Adds a new inherent impl for a type +// Adds a new inherent impl for a type. // // ``` // struct Ctx { 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 fe1f2e72e..4ee4d47fa 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs @@ -14,7 +14,7 @@ enum AddMissingImplMembersMode { // Assist: add_impl_missing_members // -// Adds scaffold for required impl members +// Adds scaffold for required impl members. // // ``` // trait T { @@ -50,7 +50,9 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx) -> Opti } // Assist: add_impl_default_members -// Adds scaffold for overriding default impl members +// +// Adds scaffold for overriding default impl members. +// // ``` // trait T { // Type X; diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index b3d025340..48782db42 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs @@ -14,7 +14,9 @@ use crate::{ }; // Assist: convert_to_guarded_return +// // Replace a large conditional with a guarded return. +// // ``` // fn main() { // <|>if cond { diff --git a/crates/ra_assists/src/assists/flip_binexpr.rs b/crates/ra_assists/src/assists/flip_binexpr.rs index c51035282..3a1e5cbe1 100644 --- a/crates/ra_assists/src/assists/flip_binexpr.rs +++ b/crates/ra_assists/src/assists/flip_binexpr.rs @@ -1,11 +1,23 @@ -//! FIXME: write short doc here - use hir::db::HirDatabase; use ra_syntax::ast::{AstNode, BinExpr, BinOp}; use crate::{Assist, AssistCtx, AssistId}; -/// Flip binary expression assist. +// Assist: flip_binexpr +// +// Flips operands of a binary expression. +// +// ``` +// fn main() { +// let _ = 90 +<|> 2; +// } +// ``` +// -> +// ``` +// fn main() { +// let _ = 2 + 90; +// } +// ``` pub(crate) fn flip_binexpr(mut ctx: AssistCtx) -> Option { let expr = ctx.node_at_offset::()?; let lhs = expr.lhs()?.syntax().clone(); diff --git a/crates/ra_assists/src/assists/flip_comma.rs b/crates/ra_assists/src/assists/flip_comma.rs index e31cc5e7d..d06c5a0e1 100644 --- a/crates/ra_assists/src/assists/flip_comma.rs +++ b/crates/ra_assists/src/assists/flip_comma.rs @@ -1,10 +1,23 @@ -//! FIXME: write short doc here - use hir::db::HirDatabase; use ra_syntax::{algo::non_trivia_sibling, Direction, T}; use crate::{Assist, AssistCtx, AssistId}; +// Assist: flip_comma +// +// Flips two comma-separated items. +// +// ``` +// fn main() { +// ((1, 2),<|> (3, 4)); +// } +// ``` +// -> +// ``` +// fn main() { +// ((3, 4), (1, 2)); +// } +// ``` pub(crate) fn flip_comma(mut ctx: AssistCtx) -> Option { let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?; let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index 9bd64decc..1997781db 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode, AstToken}, @@ -9,6 +7,22 @@ use ra_syntax::{ use crate::assist_ctx::AssistBuilder; use crate::{Assist, AssistCtx, AssistId}; +// Assist: inline_local_variable +// +// Inlines local variable. +// +// ``` +// fn main() { +// let x<|> = 1 + 2; +// x * 4; +// } +// ``` +// -> +// ``` +// fn main() { +// (1 + 2) * 4; +// } +// ``` pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx) -> Option { let let_stmt = ctx.node_at_offset::()?; let bind_pat = match let_stmt.pat()? { diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index 43fa159d7..d390db33c 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -203,3 +203,55 @@ fn handle(action: Action) { "#####, ) } + +#[test] +fn doctest_flip_binexpr() { + check( + "flip_binexpr", + r#####" +fn main() { + let _ = 90 +<|> 2; +} +"#####, + r#####" +fn main() { + let _ = 2 + 90; +} +"#####, + ) +} + +#[test] +fn doctest_flip_comma() { + check( + "flip_comma", + r#####" +fn main() { + ((1, 2),<|> (3, 4)); +} +"#####, + r#####" +fn main() { + ((3, 4), (1, 2)); +} +"#####, + ) +} + +#[test] +fn doctest_inline_local_variable() { + check( + "inline_local_variable", + r#####" +fn main() { + let x<|> = 1 + 2; + x * 4; +} +"#####, + r#####" +fn main() { + (1 + 2) * 4; +} +"#####, + ) +} -- cgit v1.2.3