microsoft / microsoft/vscode-cpptools
C_Cpp.vcFormat.space.withinSquareBrackets bug on first line
Open
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:
- Set
"C_Cpp.vcFormat.space.withinSquareBrackets": true,insettings.json. - Create a new C file
- Put in this code:
int array[] = {
[0] = 0,
[1] = 1,
[2] = 2,
};
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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