rust-lang / rust-lang/rust-analyzer

Make expand-selection smarter

Open
#13,217 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Suppose we have this:
(|...| delimits the selection)

let r = test(0, 2).saturating_|a|dd(3).saturating_sub(4);

This is what RA expand selection currently does:

let r = test(1, 2).|saturating_add|(3).saturating_sub(4);
let r = |test(1, 2).saturating_add|(3).saturating_sub(4);
let r = |test(1, 2).saturating_add(3)|.saturating_sub(4);
let r = |test(1, 2).saturating_add(3).saturating_sub|(4);
let r = |test(1, 2).saturating_add(3).saturating_sub(4)|;

That's not very useful.
This is what I would expect:

let r = test(1, 2).|saturating_add|(3).saturating_sub(4);
let r = test(1, 2).|saturating_add(3)|.saturating_sub(4);
let r = test(1, 2).|saturating_add(3).saturating_sub|(4);
let r = test(1, 2).|saturating_add(3).saturating_sub(4)|;
let r = test|(1, 2).saturating_add(3).saturating_sub(4)|;

// Or
let r = test(1, 2).|saturating_add|(3).saturating_sub(4);
let r = test(1, 2).|saturating_add(3)|.saturating_sub(4);
let r = test(1, 2).|saturating_add(3).saturating_sub(4)|;
let r = |test(1, 2).saturating_add(3).saturating_sub(4)|;

RA (as many TreeSitter based editors) follows strictly the grammar structure (left-associativity in the example above) which is easy to implement but often expands the selection the "wrong" way.
IntelliJ does a better job expanding the section for Kotlin, it's very smart and in the example above it goes to the right. (If I recall correctly)

As of today this kind of "blind" expand-selection is of little use to me, I wonder what other people here think.

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

Locate rust-analyzer's expand-selection entry point and any existing tests, then compare their behavior with the chained-call examples in the issue. The work is done when selection expansion follows useful expression boundaries rather than only grammar left-associativity, with tests covering the expected sequences.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
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.