rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.18k stars 1.59k forks source link

Complete statement command for Rust Analyzer #14765

Open gnut-neygun opened 1 year ago

gnut-neygun commented 1 year ago

IntelliJ Rust has a very useful command called "complete statement". How it works:

}

and move cursor to inside function body. Same for struct, enum, trait
- If we are in the middle of a well formed if clause, i.e: `if x > 2`, then transform it to:
```rust
if x > 2 {

}

and move cursor inside the curly brackets. Same for while, for, match, loop (this one is not in IntelliJ Rust but in Typescript and Kotlin on IntelliJ platform.)

It would be nice if Rust Analyzer can also have that. I normally bind this command to Shift + Enter key. That way I can end statements with one key combination. It's really convenient.

Veykril commented 1 year ago

I guess we could re-use the fixup machinery for this?

flodiebold commented 1 year ago

We could try, but I think they are likely to differ since they serve very different purposes.

alibektas commented 1 year ago

If I am given some instructions, I'd be happy to do it.