microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Weird behaviour with vcFormat and lambdas #9800

Open cerww opened 2 years ago

cerww commented 2 years ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: with these settings "C_Cpp.formatting": "vcFormat" "C_Cpp.vcFormat.indent.lambdaBracesWhenParameter": true "C_Cpp.vcFormat.indent.multiLineRelativeTo": "innermostParenthesis" every other setting is default also when C_Cpp.vcFormat.indent.multiLineRelativeTo is set to both it's other parameters

Expected behavior

No response

Code sample and Logs

template<typename... Ts>
void a_function(Ts...){

}

template<typename T>
T another_function(T t){
    return t;
}

int main(){
    //before formatting
    a_function(
        another_function([]() {
            return 1;
        }),
        another_function([]() {
            return 2;
        }),
        another_function([]() {
            return 3;
        }),
        another_function([]() {
            return 3;
        }),
        another_function([]() {
            return 3;
        }),
        another_function([]() {
            return 3;
        })
    );
    //after formatting
    a_function(
        another_function([]() {
            return 1;
            }),
        another_function([]() {
                return 2;
            }),
                another_function([]() {
                return 3;
                    }),
                another_function([]() {
                        return 3;
                    }),
                        another_function([]() {
                        return 3;
                            }),
                        another_function([]() {
                                return 3;
                            })
                                );

}

Screenshots

image

Additional context

No response

michelleangela commented 2 years ago

@cerww Thank you for reporting this issue. The VS Code C++ extension shares the vcFormat implementation with Visual Studio (VS) and this reproduces in VS. I opened a bug against VS internally.

GURKE commented 1 year ago

Is there an update or a link to the "internally bug report"?

I have more strange behaviours to present:

  1. Using Lambda-Functions:
    function_call([]() {
    char x;
    char z;
    char z;
    });

Expected:

function_call([]() {
    char x;
    char z;
    char z;
});
  1. Using Macro-Functions:
    #define Macroname(a) if (a) {return;}
    ...
    Macroname()
    char x;

Expected:

#define Macroname(a) if (a) {return;}
...
Macroname()
char x;
sean-mcmanus commented 1 year ago

@GURKE The internal bug is 1600301. It's not fixed yet. UPDATE: It looks like a fix is planned "soon", maybe for 1.15.0.

Your new issue 1 is already fixed with our pending 1.14.0: https://github.com/microsoft/vscode-cpptools/issues/10326 .

Your new issue 2 I moved to https://github.com/microsoft/vscode-cpptools/issues/10327 (I filed an issue on VS at https://github.com/microsoft/vscode-cpptools/issues/10327 ).