rust-lang / rust-lang/rust-analyzer

Complete statement command for Rust Analyzer

Open
#14,765 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-ide C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

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

  • If current line is a well-formed statement, e.g let a = 2 then move cursor to the end of line and add a semicolon.
  • If the line is in the middle of a function name, e.g fn func_name then transform it to
fn func_name(){

}

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:
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.)

  • Any other cases, move cursor to the end of line. (or add more smarter behaviors, basically we try to complete the statement if it make senses)

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named in the issue. Start by locating the existing editor-command handling for Rust Analyzer, then compare the requested function, struct, enum, trait, conditional, loop, and statement cases with the current behavior; done means the command handles the listed transformations and cursor placement.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.