llvm / llvm/llvm-project

Log clang-tidy checks which are enabled in clang-tidy config but clangd will not run

Open
#190,526 9 comments 0 reactions 0 assignees View on GitHub
clang-tidy clangd enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`main.cpp`:
```cpp
#include

int main() {
bool a = false;
if (a) {
std::cout << "X\n";
std::cout << "X2\n";
} else
std::cout << "Y\n";

std::cout << "Z" << std::endl;

return 0;
}
```
`.clang-tidy`:
```yml
---
Checks: >
readability-inconsistent-ifelse-braces,
performance-avoid-endl,
...
```
When I run `clang-tidy main.cpp` I get 2 warnings as expected.
But when I run `clangd --clang-tidy --check=main.cpp` there is no warnings and nothing about reading `.clang-tidy` either:
```
I[16:38:00.818] clangd version 22.1.2
I[16:38:00.818] Features: linux
I[16:38:00.818] PID: 65472
I[16:38:00.818] Working directory: [...]/clangd-issue
I[16:38:00.818] argv[0]: clangd
I[16:38:00.818] argv[1]: --clang-tidy
I[16:38:00.818] argv[2]: --check=main.cpp
I[16:38:00.818] Entering check mode (no LSP server)
I[16:38:00.818] Testing on source file [...]/clangd-issue/main.cpp
I[16:38:00.818] Loading compilation database...
I[16:38:00.819] Failed to find compilation database for [...]/clangd-issue/main.cpp
I[16:38:00.819] Generic fallback command is: [[...]/clangd-issue] /usr/bin/clang -resource-dir=/usr/lib/clang/22 -- [...]/clangd-issue/main.cpp
I[16:38:00.819] Parsing command...
I[16:38:00.820] internal (cc1) args are: -cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=[...]/clangd-issue -fcoverage-compilation-dir=[...]/clangd-issue -resource-dir /usr/lib/clang/22 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/x86_64-pc-linux-gnu -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/backward -internal-isystem /usr/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fmessage-length=185 -stack-protector 2 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ [...]/clangd-issue/main.cpp
I[16:38:00.820] Building preamble...
I[16:38:01.195] Built preamble of size 3982124 for file [...]/clangd-issue/main.cpp version null in 0.37 seconds
I[16:38:01.195] Indexing headers...
I[16:38:01.296] Building AST...
I[16:38:01.306] Indexing AST...
I[16:38:01.307] Building inlay hints
I[16:38:01.307] Building semantic highlighting
I[16:38:01.307] Testing features at each token (may be slow in large files)
I[16:38:01.326] All checks completed, 0 errors
```
I deleted my `~/.config/clangd/config.yaml` if it matters.
From https://clangd.llvm.org/features:
> clangd respects your project’s .clang-tidy file which controls the checks to run. Not all checks work within clangd.

What does that mean? How do I know which checks don't work within clangd? Are those 2 checks above supposed to work? Since there is no any mentions of checks from my `.clang-tidy` in my clangd output I suppose this is a bug inside clangd.

I also found [this post](https://discourse.llvm.org/t/enabling-clang-tidy-checks-in-clangd/4906) about a similar problem and they came to the conclusion that `.clang-tidy` should be recognized by clangd.

Contributor guide

Open the contributing guide

Research direction

Reproduce the report with main.cpp and .clang-tidy using both clang-tidy main.cpp and clangd --clang-tidy --check=main.cpp. Start by tracing clangd's clang-tidy configuration loading and check filtering, including the fallback compilation command shown in the report. Done means the supported checks are diagnosed by clangd or the unsupported checks and their limitations are clearly identified and covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.