Skip to content
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

"C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true not working as expected #12068

Closed
haplav opened this issue Mar 6, 2024 · 2 comments
Assignees

Comments

@haplav
Copy link

haplav commented Mar 6, 2024

Environment

  • OS and Version: macOS 13.6.4 (22G513)
  • VS Code Version: 1.87.0
  • C/C++ Extension Version: 1.19.5
  • If using SSH remote, specify OS of remote machine: local

Bug Summary and Steps to Reproduce

Bug Summary:
Setting

    "C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true

seems to be ignored.

Steps to reproduce:

  1. Add
        "editor.formatOnSave": true,
        "C_Cpp.formatting": "vcFormat",
        "C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true,
    to settings.json (user or workspace).
  2. Create a file hello.cpp with this content:
    #include <iostream>
    int main() {
        if (1) { std::cout << "hello" << std::endl;
        } else {
            std::cout << "hi" << std::endl; }
        return 0;  }
  3. Save or trigger Format Document.
  4. The document gets formatted like this:
    #include <iostream>
    int main() {
        if (1) {
            std::cout << "hello" << std::endl;
        }
        else {
            std::cout << "hi" << std::endl;
        }
        return 0;
    }

Expected behavior:
I expect the code would get formatted like this:

#include <iostream>
int main()
{
    if (1)
    {
        std::cout << "hello" << std::endl;
    }
    else
    {
        std::cout << "hi" << std::endl;
    }
    return 0;
}

Note however that if I format the code like this, this formatting is kept and NOT reformatted to the form in (4) above.

Configuration and Logs

No c_cpp_properties.json

C/C++: Log Diagnostics:
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/System/Library/Frameworks
-------- Diagnostics - 06/03/2024, 13:57:15
Version: 1.19.5
Current Configuration:
{
    "name": "Mac",
    "includePath": [
        "/private/tmp/hello/**"
    ],
    "defines": [],
    "macFrameworkPath": [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
    ],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "compilerPathInCppPropertiesJson": "/usr/bin/clang",
    "intelliSenseMode": "clang-x64",
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": false,
    "cppStandardIsExplicit": false,
    "mergeConfigurations": false,
    "compilerPathIsExplicit": false,
    "browse": {
        "path": [
            "/private/tmp/hello/**",
            "${workspaceFolder}"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.19.5.0
Translation Unit Mappings:
[ /private/tmp/hello/hello.cpp - source TU]:
Translation Unit Configurations:
[ /private/tmp/hello/hello.cpp ]:
    Process ID: 90469
    Memory Usage: 88 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include/c++/v1
        /Library/Developer/CommandLineTools/usr/lib/clang/15.0.0/include
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/usr/include
        /Library/Developer/CommandLineTools/usr/include
    Frameworks:
        /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk/System/Library/Frameworks
    Standard Version: c++17
    IntelliSense Mode: macos-clang-x64
    Other Flags:
        --clang
        --clang_version=160000
Total Memory Usage: 88 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 11969

Other Extensions

No response

Additional context

No response

@sean-mcmanus sean-mcmanus self-assigned this Mar 7, 2024
@sean-mcmanus
Copy link
Collaborator

You're using the wrong vcFormat settings. Use something like

    "C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
    "C_Cpp.vcFormat.indent.braces": false

although I think you may want to set more of the newLine.beforeOpenBrace settings to true.

The "C_Cpp.vcFormat.newLine.scopeBracesOnSeparateLines": true, setting is supposed to apply to code like

void Function()
{
    // Scope
    { int i;
    }
}

but I'm seeing a bug in which the formatting is behaving like it's always true.

@haplav
Copy link
Author

haplav commented Mar 8, 2024

Thanks. The description is a bit confusing, though, because a function scope is a scope and a control block is a scope as well.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants