Skip to content

C_Cpp.clang_format_style=file works incorrectly #196

@alexfh

Description

@alexfh
  • VSCode Version: Code 1.4.0 (6276dcb0ae497766056b4c09ea75be1d76a8b679, 2016-08-04T16:49:32.489Z)
  • C/C++ for Visual Studio Code extension version: 0.9.0
  • OS Version: Linux x64 3.13.0-92-generic

The extension doesn't seem to apply C_Cpp.clang_format_style=file correctly. My settings.json contents:

{
    "C_Cpp.clang_format_style": "file",
    "C_Cpp.clang_format_fallbackStyle": "Visual Studio"
}

But files seem to be formatted using the "Visual Studio" style.

Steps to Reproduce:

  1. Install vscode and the C/C++ extension.

  2. In terminal:

    $ mkdir /tmp/vscode-clang-format
    $ echo "BasedOnStyle: LLVM" > /tmp/vscode-clang-format/.clang-format
    $ echo "void f() { int a; int b; }" > /tmp/vscode-clang-format/file.cpp
    $ clang-format -style=file /tmp/vscode-clang-format/file.cpp 
    void f() {
      int a;
      int b;
    }
    $ code /tmp/vscode-clang-format/
    
  3. Open /tmp/vscode-clang-format/file.cpp

  4. Change workspace settings (settings.json) to:

    {
        "C_Cpp.clang_format_style": "file",
        "C_Cpp.clang_format_fallbackStyle": "Visual Studio"
    }
    
  5. Press Ctrl-Shift-I. Observe that an incorrect style is applied to the file.

  6. Save the file

  7. The resulting formatting is:

    $ cat /tmp/vscode-clang-format/file.cpp 
    void f()
    {
        int a;
        int b;
    }
    

Looks like the arguments supplied to clang-format in my case are:

  -style={ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 2, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0 } -fallback-style=LLVM -sort-includes=0

Instead, -style=file along with the proper -assume-filename=... should be used.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions