vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Update to clang-format and clang-tidy 15

Open sean-mcmanus opened this issue 2 years ago • 2 comments

I know 15 has some clang-tidy bug fixes. It's supposed to be released in a week or so.

UPDATE: This is delayed due to new build failures in some of our cross compiling builds.

sean-mcmanus avatar Aug 30 '22 21:08 sean-mcmanus

Auto detection of clang-format in PATH seems to be broken after I upgrade llvm to v15?

taoran-git avatar Sep 20 '22 09:09 taoran-git

@taoran-git Doing a Reload Window should fix it -- the path is cached. See https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/LanguageServer/settings.ts#L111 . If that doesn't fix it, can you file a new issue on the bug?

sean-mcmanus avatar Sep 20 '22 15:09 sean-mcmanus

How do i specify to use C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin/clang-format.exe instead of c:\Users\blah\.vscode\extensions\ms-vscode.cpptools-1.13.2-win32-x64/bin/../LLVM/bin/clang-format.exe?

I get an error

Formatting failed:
c:\Users\blah\.vscode\extensions\ms-vscode.cpptools-1.13.2-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file -fallback-style=LLVM -assume-filename=C:\Users\blah\blah\src\client\src\Main.cpp

The .clang-format file is in C:\Users\blah\blah\

Is clang-format being called from the correct directory?

cjwijtmans avatar Oct 13 '22 17:10 cjwijtmans

@cjwijtmans Set C_Cpp.clang_format_path -- does that fix your issue?

sean-mcmanus avatar Oct 13 '22 17:10 sean-mcmanus

That is strange i tried finding that setting in the json file by just typing "clang" but it had no results. It is finding the new clang-format but still getting an error and it is not specifying as to why. Is it not finding the file or is there something wrong with my file. 🤔

cjwijtmans avatar Oct 13 '22 17:10 cjwijtmans

Yeah, we don't output informative format error logging.

Have you tried running the command from the command line?

Usually, the failure is caused by some error in the .clang-format config file.

sean-mcmanus avatar Oct 14 '22 18:10 sean-mcmanus

@taoran-git Doing a Reload Window should fix it -- the path is cached. See https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/LanguageServer/settings.ts#L111 . If that doesn't fix it, can you file a new issue on the bug?

Thank you for your reply. My issue persists and is pretty much the same as https://github.com/microsoft/vscode-cpptools/issues/8520. I now suspect that auto-detection of clang-format was broken even before updating llvm to 15. Things worked fine only because the extension-bundled clang-format WAS up-to-date with the .clang-format file. After adding some clang-format-15-exclusive options to my .clang-format file, the extension-bundled formatter stop working. This is indeed expected though.

What really goes wrong is that the extension never invokes the clang-format in my $PATH. To reassure, echo $PATH gives me /usr/local/opt/llvm/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin:/usr/local/opt/llvm/bin:/opt/local/bin:/opt/local/sbin

Manually setting C_Cpp.clang_format_path fixes the problem. But a cross platform solution would be really appreciated.

taoran-git avatar Oct 25 '22 07:10 taoran-git

This is available with 1.13.3 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.13.3

@taoran-git I filed https://github.com/microsoft/vscode-cpptools/issues/10071 to track the PATH issue.

sean-mcmanus avatar Oct 26 '22 22:10 sean-mcmanus

"AlignCompound" doesn't align correctly, don't know it that's an issue with the extension itself. From https://clang.llvm.org/docs/ClangFormatStyleOptions.html:

bool AlignCompound Only for AlignConsecutiveAssignments. Whether compound assignments like += are aligned along with =.

true:
a   &= 2;
bbb  = 2;

false:
a &= 2;
bbb = 2;

Pre-Release v1.13.3, AlignCompound: true:

a   &= 2;
bbb = 2;

ghost avatar Nov 10 '22 08:11 ghost

@TheStrupf It appears to be bug https://github.com/llvm/llvm-project/issues/58029 , i.e. the bug repros when calling clang-format directly.

sean-mcmanus avatar Nov 10 '22 23:11 sean-mcmanus