rust-lang / rust-lang/rust-analyzer
Feature request: move constant away from a function to the top of the module.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
There should be a way to extract constant without scrolling viewport up, then down again.
Rust analyzer already prodives "extract variable" and "promote varianbe to constant" code actions. The missing step is moving the constant away from the function (maybe also replacing occurrences of the same value with it on the way).
Code:
fn second() {
let a = 555;
}
fn main() {
┃const VAR_NAME : i32 = 555;
println!("{}", VAR_NAME);
}
After "Move constant to the top":
const VAR_NAME : i32 = 555;
fn second() {
let a = 555;
}
fn main() {
┃println!("{}", VAR_NAME);
}
Note that viewport and cursor should stay in original location, not where the constant ended up.
After "Move constant to the top, also replace occurrences":
const VAR_NAME : i32 = 555;
fn second() {
let a = VAR_NAME;
}
fn main() {
┃println!("{}", VAR_NAME);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files or tests are named. Start by reading rust-analyzer’s existing “extract variable” and “promote variable to constant” code-action entry points; done should cover moving the constant to the module top, preserving the original viewport and cursor location, and determining whether occurrence replacement is included.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100