Vscode-cpptools: C_Cpp.clang_format_fallbackStyle introduce new indention from previous levels

Created on 5 Apr 2019  路  8Comments  路  Source: microsoft/vscode-cpptools

  • OS and Version: Win 10 Professional, 64bit
  • VS Code Version: 1.33.0
  • C/C++ Extension Version: 0.22.1
  • Other extensions you installed (and if the issue persists after disabling them): none

Here's my settings.json:

{
    "C_Cpp.errorSquiggles": "Enabled",
    "C_Cpp.intelliSenseEngine": "Default",
    "C_Cpp.intelliSenseEngineFallback": "Disabled",
    "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}",

    "workbench.sideBar.location": "right",

    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true
    },

    "editor.formatOnPaste": true,
    "editor.formatOnType": true,

    "terminal.integrated.shell.windows": "C:/msys64/usr/bin/bash.exe", 
    "terminal.integrated.shellArgs.windows": [ "-i" ],
    "terminal.integrated.env.windows": { 
        "MSYSTEM": "MINGW64", 
        "PATH" : "/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/"
    }
}

This is the code I have:

struct Test : Module 
    {
    enum ParamIds {
        TRIGGER_PARAM,
        CYCLE_PARAM,        
        RATE_PARAM,
        RATE_FINE_PARAM,
        RISE_LENGTH_PARAM,
        NUM_PARAMS
    };
    enum InputIds 
    {
        TRIGGER_INPUT,

        TAIL_LENGTH_CV_INPUT,
        NUM_INPUTS
    };
    enum OutputIds {
        EOR_OUTPUT, 
        EOF_OUTPUT,
        EOC_OUTPUT,
        RISING_OUTPUT,          
        FALLING_OUTPUT,     
        OUT_OUTPUT,
        NUM_OUTPUTS
    };
};

I want, when paste or type (formatOnType), that { is on the same line of function, and code is well formatted (due to Google specifics).

If now, within InputIds I paste a new value in that empty space, that's the result:

struct Test : Module 
    {
    enum ParamIds {
        TRIGGER_PARAM,
        CYCLE_PARAM,        
        RATE_PARAM,
        RATE_FINE_PARAM,
        RISE_LENGTH_PARAM,
        NUM_PARAMS
    };
        enum InputIds {
            TRIGGER_INPUT,
            ASD_PARAM,
            TAIL_LENGTH_CV_INPUT,
            NUM_INPUTS
        };
        enum OutputIds {
        EOR_OUTPUT, 
        EOF_OUTPUT,
        EOC_OUTPUT,
        RISING_OUTPUT,          
        FALLING_OUTPUT,     
        OUT_OUTPUT,
        NUM_OUTPUTS
    };
};

As you can see, it adds a tab/indention and mess the whole code.
Also, the struct { keep on the new line, not on the same line.

It seems formatting fail.

Code Formatting Language Service bug more votes needed

All 8 comments

I'm not able to repro the bug. Can you describe:

  1. What is the existing code?
  2. What code do I copy/paste and where?

Is formatting not working at all for you? If so, can you check the error logs? https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/Enabling%20logging.md

Yes, formatting works.
Here's the code you can test: Test.zip

  1. open folder with VSCode
  2. go to Test.cpp
  3. find "// PASTE CODE HERE"
  4. paste whatever text you want (in my case, I simply paste ASD,)

Do you see now?

Okay, thanks, I repro the issue now.

@sean-mcmanus news about this fix? Thanks

A fix is not currently scheduled because we're busy with other higher priority features.

This might be a bug with clang-format (not sure).

I tried the repro. The file itself does not start out with the correct formatting, so clang-format is applying partial formatting. If you format the whole file first, then paste in your code, the correct behavior happens. This appears to be an issue with clang-format.

Also, you probably meant to use C_Cpp.clang_format_style instead of C_Cpp.clang_format_fallbackStyle

Was this page helpful?
0 / 5 - 0 ratings