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 /docs/user | |
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 'docs/user')
-rw-r--r-- | docs/user/assists.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md index 8da7578e2..6f4c30bee 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -329,6 +329,25 @@ fn main() { | |||
329 | } | 329 | } |
330 | ``` | 330 | ``` |
331 | 331 | ||
332 | ## `invert_if` | ||
333 | |||
334 | Apply invert_if | ||
335 | This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` | ||
336 | This also works with `!=`. This assist can only be applied with the cursor | ||
337 | on `if`. | ||
338 | |||
339 | ```rust | ||
340 | // BEFORE | ||
341 | fn main() { | ||
342 | if┃ !y { A } else { B } | ||
343 | } | ||
344 | |||
345 | // AFTER | ||
346 | fn main() { | ||
347 | if y { B } else { A } | ||
348 | } | ||
349 | ``` | ||
350 | |||
332 | ## `make_raw_string` | 351 | ## `make_raw_string` |
333 | 352 | ||
334 | Adds `r#` to a plain string literal. | 353 | Adds `r#` to a plain string literal. |