rust-lang / rust-lang/rust-analyzer
Extract into variable work incorrectly when used in binary expressions
Open
Nobody has claimed this yet.
A-assists
E-unknown
S-actionable
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Given
let foo = 1 + $02 + 3$0;
the assist produces
let var_name = 1 + 2 + 3;
let foo = var_name;
instead of the expected
let var_name = 2 + 3;
let foo = 1 + var_name;
This is most likely due to how the expression is laid out in the AST as extracting the 1 + 2 works fine.
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
Start by reproducing the extract-variable assist with the binary-expression example and inspect how the selected expression is represented in the AST. Trace the extraction logic for both 2 + 3 and 1 + 2; done means the assist extracts exactly the selected subexpression and preserves the surrounding operands.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100