rust-lang / rust-lang/rust-analyzer

`extract_variable` should be able to heuristically extract multiple occurences of the same expression

Open
#10,547 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As mentioned in https://github.com/rust-analyzer/rust-analyzer/issues/7692#issuecomment-888356714_ it might be nice to have extract_variable lift out all occurences of the target expression in the current function and replace them with the new variable name.

Open question is what theres heuristics are exactly. For example this should keep in mind the places of these expressions to decide whether it would make sense to extract more than just the target, like expressions in function arguments where those parameters have the same name etc.

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

Start with the extract_variable implementation and the discussion in issue #7692, especially the linked comment. Clarify the heuristics for selecting additional occurrences and related expressions, then define tests covering repeated expressions and function-argument contexts; done means the behavior is specified and validated.

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
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.