// Assist: add_explicit_type
//
-// Specify type for a let binding
+// Specify type for a let binding.
//
// ```
// fn main() {
// Assist: add_impl
//
-// Adds a new inherent impl for a type
+// Adds a new inherent impl for a type.
//
// ```
// struct Ctx<T: Clone> {
// Assist: add_impl_missing_members
//
-// Adds scaffold for required impl members
+// Adds scaffold for required impl members.
//
// ```
// trait T {
}
// Assist: add_impl_default_members
-// Adds scaffold for overriding default impl members
+//
+// Adds scaffold for overriding default impl members.
+//
// ```
// trait T {
// Type X;
};
// Assist: convert_to_guarded_return
+//
// Replace a large conditional with a guarded return.
+//
// ```
// fn main() {
// <|>if cond {
-//! 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<impl HirDatabase>) -> Option<Assist> {
let expr = ctx.node_at_offset::<BinExpr>()?;
let lhs = expr.lhs()?.syntax().clone();
-//! 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<impl HirDatabase>) -> Option<Assist> {
let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?;
let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?;
-//! FIXME: write short doc here
-
use hir::db::HirDatabase;
use ra_syntax::{
ast::{self, AstNode, AstToken},
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<impl HirDatabase>) -> Option<Assist> {
let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?;
let bind_pat = match let_stmt.pat()? {
"#####,
)
}
+
+#[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;
+}
+"#####,
+ )
+}
## `add_explicit_type`
-Specify type for a let binding
+Specify type for a let binding.
```rust
// BEFORE
## `add_impl`
-Adds a new inherent impl for a type
+Adds a new inherent impl for a type.
```rust
// BEFORE
## `add_impl_default_members`
-Adds scaffold for overriding default impl members
+Adds scaffold for overriding default impl members.
```rust
// BEFORE
## `add_impl_missing_members`
-Adds scaffold for required impl members
+Adds scaffold for required impl members.
```rust
// BEFORE
}
}
```
+
+## `flip_binexpr`
+
+Flips operands of a binary expression.
+
+```rust
+// BEFORE
+fn main() {
+ let _ = 90 +<|> 2;
+}
+
+// AFTER
+fn main() {
+ let _ = 2 + 90;
+}
+```
+
+## `flip_comma`
+
+Flips two comma-separated items.
+
+```rust
+// BEFORE
+fn main() {
+ ((1, 2),<|> (3, 4));
+}
+
+// AFTER
+fn main() {
+ ((3, 4), (1, 2));
+}
+```
+
+## `inline_local_variable`
+
+Inlines local variable.
+
+```rust
+// BEFORE
+fn main() {
+ let x<|> = 1 + 2;
+ x * 4;
+}
+
+// AFTER
+fn main() {
+ (1 + 2) * 4;
+}
+```
);
let doc = take_until(lines.by_ref(), "```").trim().to_string();
+ assert!(
+ doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."),
+ "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
+ id, doc,
+ );
+
let before = take_until(lines.by_ref(), "```");
assert_eq!(lines.next().unwrap().as_str(), "->");