rust-lang / rust-lang/rust-analyzer

Filter "Go To Definition/References" results where variable/field is mutated

Open
#16,365 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

A workflow I very frequently find myself doing is hunting down all references to a variable or field where a mutation occurs. I'm not interested in all usages of the variable/field, only where it gets updated/written to. Right now, I have to sort through lots of spam from the places the variable/field gets read.

I often resort to tricks like visually parsing the items in the peek window for which side of the = it shows up on. Anything with an = on the left of the variable/field is a mutation. But this trick misses cases where a the variable is assigned by mutable reference to another variable which is then later updated, or where the value is updated by a function call like .pop(). These cases can be really subtle and easy to miss.

Conversely, I am also sometimes interested in the reverse: only places where a variable/field is read but not written to.

I could see two ways to make this happen that would be useful. One approach would be decorating every peek result with something (ideally a color? or maybe an emoji prefix?) to indicate if it's read or written to. I don't know how much control VS Code provides extension authors over the peek window results. Another, if VS Code provides the capability, would be adding more context menu entries called something like "Go to Read-Only References" and "Go to Mutated References" alongside these:

image

This feature would be a huge time saver during refactoring and general code exploration.

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 by examining the existing Go To Definition/References commands and the VS Code peek window or extension API to determine whether read/write metadata or separate filtered commands are supported. Define how mutations, reads, mutable-reference updates, and method calls should be classified before identifying the affected rust-analyzer and editor integration points; done means the chosen workflow reliably filters or labels results.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.