diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-24 08:32:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-24 08:32:07 +0000 |
commit | 7b6aa7c34e5650506924decfee0a77aa9bb0a480 (patch) | |
tree | 8a8fc896efbf5f12ae55da28a370bdfe9e6ce445 /crates/ra_syntax/src/ast/make.rs | |
parent | f2c36e5a6f5892532dec9e6523dc0944453a384f (diff) | |
parent | adac4fc2f21117486356063d82d79f8c3add084a (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/make.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 9749327fa..40db570da 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -173,10 +173,21 @@ fn ast_from_text<N: AstNode>(text: &str) -> N { | |||
173 | } | 173 | } |
174 | 174 | ||
175 | pub mod tokens { | 175 | pub mod tokens { |
176 | use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T}; | 176 | use crate::{AstNode, Parse, SourceFile, SyntaxKind, SyntaxKind::*, SyntaxToken, T}; |
177 | use once_cell::sync::Lazy; | 177 | use once_cell::sync::Lazy; |
178 | 178 | ||
179 | static SOURCE_FILE: Lazy<Parse<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;")); | 179 | static SOURCE_FILE: Lazy<Parse<SourceFile>> = |
180 | Lazy::new(|| SourceFile::parse("const C: () = (1 != 1, 2 == 2)\n;")); | ||
181 | |||
182 | pub fn op(op: SyntaxKind) -> SyntaxToken { | ||
183 | SOURCE_FILE | ||
184 | .tree() | ||
185 | .syntax() | ||
186 | .descendants_with_tokens() | ||
187 | .filter_map(|it| it.into_token()) | ||
188 | .find(|it| it.kind() == op) | ||
189 | .unwrap() | ||
190 | } | ||
180 | 191 | ||
181 | pub fn comma() -> SyntaxToken { | 192 | pub fn comma() -> SyntaxToken { |
182 | SOURCE_FILE | 193 | SOURCE_FILE |