microsoft / vscode-cpptools

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

vcFormat incorrectly formatting templated operator() call #11159

Open aandrejevas opened 1 year ago

aandrejevas commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Settings:

"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.default.cStandard": "c17",
"C_Cpp.default.intelliSenseMode": "windows-gcc-x64",
"C_Cpp.default.compilerPath": "C:\msys64\ucrt64\bin\g++.exe",
"C_Cpp.autoAddFileAssociations": false,
"C_Cpp.suggestSnippets": false,
"C_Cpp.formatting": "vcFormat",
"C_Cpp.vcFormat.wrap.preserveBlocks": "allOneLineScopes",
"C_Cpp.vcFormat.indent.gotoLabels": "oneLeft",
"C_Cpp.vcFormat.indent.caseLabels": true,
"C_Cpp.vcFormat.newLine.closeBraceSameLine.emptyFunction": true,
"C_Cpp.vcFormat.newLine.closeBraceSameLine.emptyType": true,
"C_Cpp.vcFormat.indent.multiLineRelativeTo": "statementBegin",
"C_Cpp.vcFormat.newLine.beforeElse": false,
"C_Cpp.vcFormat.newLine.beforeCatch": false,
"C_Cpp.vcFormat.space.withinInitializerListBraces": false,
"C_Cpp.vcFormat.indent.preserveWithinParentheses": true,
"C_Cpp.vcFormat.space.pointerReferenceAlignment": "right",
"C_Cpp.vcpkg.enabled": false,
"C_Cpp.default.defines": [],
"C_Cpp.simplifyStructuredComments": false,
"C_Cpp.errorSquiggles": "disabled",
"C_Cpp.codeAnalysis.runAutomatically": false,
"C_Cpp.dimInactiveRegions": false,
"C_Cpp.intelliSenseEngine": "Tag Parser",
"C_Cpp.vcFormat.indent.lambdaBracesWhenParameter": false

Code before formatting (expected behavior):

#include <functional>

int main() {
    std::less<void> comparator;
    comparator.operator()<int, int>(5, 5);
}

Code after formatting:

#include <functional>

int main() {
    std::less<void> comparator;
    comparator.operator() < int, int > (5, 5);
}

Configuration and Logs

loggingLevel: Debug
loggingLevel has changed to: Debug
LSP: cpptools/textEditorSelectionChange
LSP: textDocument/didOpen: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
LSP: cpptools/activeDocumentChange: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
Checking for syntax errors: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
LSP: cpptools/getCodeActions: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 634)
LSP: cpptools/getDocumentSymbols: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 635)
Queueing IntelliSense update for files in translation unit of: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getSemanticTokens: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 636)
LSP: cpptools/getInlayHints: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 637)
Database safe to open.
Error squiggle count: 0
Update IntelliSense time (sec): 0.438
LSP: textDocument/willSaveWaitUntil: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 638)
willSaveWaitUntil: 0ms
LSP: cpptools/formatDocument: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 639)
Formatting document: file:///C%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
Formatting Engine: vcFormat
LSP: textDocument/didChange: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
LSP: textDocument/didSave: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
  tag parsing file: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
LSP: cpptools/fileChanged: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp
LSP: cpptools/getDocumentSymbols: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 640)
LSP: cpptools/getSemanticTokens: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 641)
LSP: cpptools/getInlayHints: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 642)
idle loop: reparsing the active document
Checking for syntax errors: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
Queueing IntelliSense update for files in translation unit of: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
sending 4 changes to server
Error squiggle count: 0
Update IntelliSense time (sec): 0.277
Checking for syntax errors: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
Queueing IntelliSense update for files in translation unit of: C:\Users\Aleksandras\Desktop\projects\QAP_BA\src\format.cpp
Error squiggle count: 0
Update IntelliSense time (sec): 0.256
LSP: cpptools/getSemanticTokens: file:///c%3A/Users/Aleksandras/Desktop/projects/QAP_BA/src/format.cpp (id: 643)

Other Extensions

No response

Additional context

No response

michelleangela commented 1 year ago

@aandrejevas The vcFormat setting "C_Cpp.vcFormat.space.aroundBinaryOperator" which has a default value of insert is incorrectly formatting comparator.operator()<int, int>(5, 5);. This is similar to the issue at https://github.com/microsoft/vscode-cpptools/issues/11112#issuecomment-1608267127.

The vcFormat code base is shared with Visual Studio. I've created an internal bug (1846065) against Visual Studio for this issue.