microsoft / microsoft/vscode-cpptools

Wrong or unchanged indentation when initializing structs.

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

Nobody has claimed this yet.

bug Feature: Code Formatting Language Service Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Bug type: Language Service

With VSCode 1.56 (April 2021) & cpptools 1.4.1

There are problems with the indentations of struct initializers.

  • When initializing a variable, the indentation is unchanged.
  • When returning, the indentation is changed but wrong.
    • The first line is correct.
    • The rest is double-indented.
typedef struct thing {
    int a;
    int b;
} thing;

thing get_thing() {

    /* In these situations: indentation is unchanged */
    thing a = {
            10, // wrong indentation not corrected
    10 // wrong indentation not corrected
    };
    thing t = {
                .a = 10, // wrong indentation not corrected
    .b = 10 // wrong indentation not corrected
    };
    t = (thing){
        .a = 10, // had to manually indent those ones
        .b = 10 // indentation is unchanged by formatter
    };

    /* In these situations: indentation is worng */
    return (thing) {
        .a = 10, // good
            .b = 10 // wrong indentation formatted
    };
}

Configuration:

"C_Cpp.formatting": "vcFormat"
"C_Cpp.vcFormat.indent.caseLabels": true

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 issue using the embedded C struct-initializer example with C_Cpp.formatting set to vcFormat and the listed indentation setting. Trace the vcFormat handling for variable initialization and return expressions, then verify that the resulting indentation matches the example's expected layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.