Skip to content

VSCode indents method call chains incorrectly #11279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xsrvmy opened this issue Jan 14, 2022 · 2 comments
Open

VSCode indents method call chains incorrectly #11279

xsrvmy opened this issue Jan 14, 2022 · 2 comments
Labels
A-ide general IDE features C-bug Category: bug

Comments

@xsrvmy
Copy link

xsrvmy commented Jan 14, 2022

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)
0f8c96c 2022-01-10 stable

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

@Veykril Veykril added A-ide general IDE features C-bug Category: bug labels Jan 14, 2022
@Veykril
Copy link
Member

Veykril commented Jan 14, 2022

@DropDemBits
Copy link
Contributor

#13975 fixes the case of enter after for_each, but the enter after list.items case is still present. While typing a . after does adjust the indent, it would still be nice to have that indent there in the first place.

Would need to add a new onEnter rule in here, with the hard part being trying to figure out the right regex to use that minimizes the false positives

let onEnterRules: vscode.OnEnterRule[] = [
{
// Carry indentation from the previous line
// if it's only whitespace
beforeText: /^\s+$/,
action: { indentAction: vscode.IndentAction.None },
},
{
// After the end of a function/field chain,
// with the semicolon on the same line
beforeText: /^\s+\..*;/,
action: { indentAction: vscode.IndentAction.Outdent },
},
{
// After the end of a function/field chain,
// with semicolon detached from the rest
beforeText: /^\s+;/,
previousLineText: /^\s+\..*/,
action: { indentAction: vscode.IndentAction.Outdent },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants