microsoft / microsoft/vscode-cpptools

C_Cpp.vcFormat.space.withinSquareBrackets bug on first line

Open
#10,583 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Environment
  • OS and Version: Mac OS Ventura 13.2.1
  • VS Code Version: 1.75.1
  • C/C++ Extension Version: 1.14.3
  • If using SSH remote, specify OS of remote machine: N/A
Bug Summary and Steps to Reproduce

Bug Summary:

C_Cpp.vcFormat.space.withinSquareBrackets setting doesn't insert a space within the square brackets for the first designated initializer for an array.

Steps to reproduce:

  1. Set "C_Cpp.vcFormat.space.withinSquareBrackets": true, in settings.json.
  2. Create a new C file
  3. Put in this code:
int array[] = {
    [0] = 0,
    [1] = 1,
    [2] = 2,
};
  1. Format with C/C++.

Code should be formatted to

int array[] = {
    [ 0 ] = 0,
    [ 1 ] = 1,
    [ 2 ] = 2,
};

Instead, the file is formatted to

int array[] = {
    [0] = 0,
    [ 1 ] = 1,
    [ 2 ] = 2,
};
Configuration and Logs
    "C_Cpp.vcFormat.indent.caseLabels": true,
    "C_Cpp.vcFormat.indent.preserveWithinParentheses": false,
    "C_Cpp.vcFormat.indent.multiLineRelativeTo": "outermostParenthesis",
    "C_Cpp.vcFormat.wrap.preserveBlocks": "never",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.namespace": "sameLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.type": "sameLine",
    "C_Cpp.vcFormat.newLine.beforeWhileInDoWhile": true,
    "C_Cpp.vcFormat.newLine.closeBraceSameLine.emptyFunction": true,
    "C_Cpp.vcFormat.newLine.closeBraceSameLine.emptyType": true,
    "C_Cpp.vcFormat.space.aroundAssignmentOperator": "ignore",
    "C_Cpp.vcFormat.space.beforeBlockOpenBrace": true,
    "C_Cpp.vcFormat.space.beforeInitializerListOpenBrace": true,
    "C_Cpp.vcFormat.space.afterCastCloseParenthesis": true,
    "C_Cpp.vcFormat.space.betweenEmptyParameterListParentheses": false,
    "C_Cpp.vcFormat.space.betweenEmptyBraces": true,
    "C_Cpp.vcFormat.space.betweenEmptySquareBrackets": false,
    "C_Cpp.vcFormat.space.pointerReferenceAlignment": "left",
    "C_Cpp.vcFormat.space.withinCastParentheses": true,
    "C_Cpp.vcFormat.space.withinControlFlowStatementParentheses": true,
    "C_Cpp.vcFormat.space.withinExpressionParentheses": true,
    "C_Cpp.vcFormat.space.withinLambdaBrackets": true,
    "C_Cpp.vcFormat.space.withinParameterListParentheses": true,
    "C_Cpp.vcFormat.space.withinSquareBrackets": true,
    "C_Cpp.vcFormat.space.withinInitializerListBraces": true,
    "C_Cpp.vcFormat.space.removeAroundMemberOperators": false,
    "C_Cpp.formatting": "vcFormat",
Other Extensions

N/A

Additional context

No response

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 in VS Code with C_Cpp.vcFormat.space.withinSquareBrackets enabled and the designated-initializer example from the report. Trace the C/C++ formatting path used by the extension; done means the first array initializer receives spaces inside its brackets, matching the later initializers.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.