rust-lang / rust-lang/rust-analyzer

VSCode indents method call chains incorrectly

Open
#11,279 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When typing in this block of code,

pub fn run() {
    // ...
    loop {
        list.items
            .iter()
            .enumerate()
            .for_each(/* ... */);
        println!(/* ... */);
    }
}

I observer the following behaviour:
If I hit enter after list.items, it does not add an extra indent.
If I hit enter after the for_each, it does not remove the extra indent, so I have to press backspace

Note that I use vim mode, but using VSCode's indent lines feature will cause a similar problem as well, so I don't think it has anything to do with vim.

rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
0f8c96c92 2022-01-10 stable

rustc version: (eg. output of rustc -V)
1.57.0 (f1edd0429 2021-11-29)

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

Reproduce the behavior in VSCode using the Rust snippet, comparing Enter after list.items with Enter after for_each. Trace rust-analyzer's indentation behavior; done when chained calls gain and remove the expected indentation without requiring manual backspace.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.