microsoft / microsoft/vscode-cpptools

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

Open
#10,071 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

by design Feature: Code Analysis Feature: Code Formatting investigate: repro Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

    > @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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Extension/src/LanguageServer/settings.ts around line 111 and review the PATH caching and auto-detection behavior described in issue 8520. Reproduce the problem with clang-format and clang-tidy available in PATH, compare it with manually setting C_Cpp.clang_format_path, and confirm that detection works across platforms without requiring the explicit setting.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.