microsoft / vscode-cpptools

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

Auto detection of clang-format and clang-tidy in the PATH isn't working? #10071

Open sean-mcmanus opened 2 years ago

sean-mcmanus commented 2 years ago
    > @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.

Originally posted by @taoran-git in https://github.com/microsoft/vscode-cpptools/issues/9816#issuecomment-1290088933

ghost commented 8 months ago

same here

Colengms commented 8 months ago

It's unclear to me if there is an issue here. The C/C++ Extension does appear to use clang-format/clang-tidy in path IF that is a more recent version than bundled with the extension. Trying this out, it does appear to work as intended. Reloading the window is currently required in order to perform the version check again. To use an older version of clang-format or clang-tidy, a specific path can be specified in C_Cpp.clang_format_path.

ghost commented 8 months ago

It's unclear to me if there is an issue here. The C/C++ Extension does appear to use clang-format/clang-tidy in path IF that is a more recent version than bundled with the extension. Trying this out, it does appear to work as intended. Reloading the window is currently required in order to perform the version check again. To use an older version of clang-format or clang-tidy, a specific path can be specified in C_Cpp.clang_format_path.

sadly the problem happens when there is a newer version in path my .clang-format has some options that are only supported by versions newer than the one bundled with extension, and sadly it doesn't work, but with another extension that detects clang-format from path it does, and I did try setting clang_format_path manually (btw I'm on Linux)