microsoft / microsoft/vscode-cpptools

Abnormal Indentation for do-while without brace

Open
#12,972 1 comment 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

Environment
  • OS and Version: Microsoft Windows 10 Professional Edition 10945.5131 (Latest)
  • VS Code Version: 1.95.3 (system setup) (Latest)
  • C/C++ Extension Version: v1.22.11 (Latest)
Bug Summary and Steps to Reproduce

Bug Summary:
Indentation for do-while without brace is wrong.

Steps to reproduce:
Enable vcFormat to format the code, then just write a do-while like:

if (...)
	do
		cout << "Hello World!";
while (...);

Expected behavior:

if (...)
	do
		cout << "Hello World!";
	while (...);
Configuration and Logs
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\TDM-GCC-64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}
Other Extensions

Only this extension has been enabled.

Additional context

The key issue is that the compiler does not compile like it looks like.

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

Start by reproducing the example with vcFormat enabled in the C/C++ extension on Windows, comparing the actual indentation with the expected output. The work is done when an unbraced do-while nested under an if is formatted with the while statement indented inside the if body.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript, vscode
Domain
developer-experience, 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.