aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-24 08:32:07 +0000
committerGitHub <[email protected]>2019-11-24 08:32:07 +0000
commit7b6aa7c34e5650506924decfee0a77aa9bb0a480 (patch)
tree8a8fc896efbf5f12ae55da28a370bdfe9e6ce445 /crates/ra_syntax/src/ast/edit.rs
parentf2c36e5a6f5892532dec9e6523dc0944453a384f (diff)
parentadac4fc2f21117486356063d82d79f8c3add084a (diff)
Merge #2343
2343: implement assist invert_if r=matklad a=bravomikekilo fix [issue 2219 invert if condition](https://github.com/rust-analyzer/rust-analyzer/issues/2219) I put the assist cursor range to `if` of the if expression, because both condition and body will be replaced. Is there any way to replace them without cover the cursor position? @matklad Co-authored-by: bravomikekilo <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 6f005a2d8..95bf9db14 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -13,11 +13,21 @@ use crate::{
13 make::{self, tokens}, 13 make::{self, tokens},
14 AstNode, TypeBoundsOwner, 14 AstNode, TypeBoundsOwner,
15 }, 15 },
16 AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, 16 AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, SyntaxKind,
17 SyntaxKind::{ATTR, COMMENT, WHITESPACE}, 17 SyntaxKind::{ATTR, COMMENT, WHITESPACE},
18 SyntaxNode, SyntaxToken, T, 18 SyntaxNode, SyntaxToken, T,
19}; 19};
20 20
21impl ast::BinExpr {
22 #[must_use]
23 pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> {
24 let op_node: SyntaxElement = self.op_details()?.0.into();
25 let to_insert: Option<SyntaxElement> = Some(tokens::op(op).into());
26 let replace_range = RangeInclusive::new(op_node.clone(), op_node);
27 Some(replace_children(self, replace_range, to_insert.into_iter()))
28 }
29}
30
21impl ast::FnDef { 31impl ast::FnDef {
22 #[must_use] 32 #[must_use]
23 pub fn with_body(&self, body: ast::Block) -> ast::FnDef { 33 pub fn with_body(&self, body: ast::Block) -> ast::FnDef {