[clang-tools-extra] Follow style configuration in clangd when inserting missing includes (PR #140594)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon May 26 23:07:37 PDT 2025
================
@@ -141,16 +143,41 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
AST.getPreprocessor().getHeaderSearchInfo(), MainFile});
llvm::StringRef HeaderRef{Spelling};
- bool Angled = HeaderRef.starts_with("<");
+
+ bool IsAngled = false;
----------------
kadircet wrote:
we shouldn't be matching against `HeaderRef`, but instead matching against `ResolvedPath` and only when `SymbolWithMissingInclude.Providers.front().kind() == Physical`
nit:
```cpp
bool Angled = HeaderRef.starts_with("<");
if (SymbolWithMissingInclude.Providers.front().kind() == ..Physical) {
for (auto &Filter : Angled ? QuotedHeaders : AngledHeaders) {
if (Filter(ResolvedPath)) {
Angled = !Angled;
break;
}
}
}
....
std::optional<tooling::Replacement> Replacement = HeaderIncludes.insert(
HeaderRef.trim("\"<>"), Angled, tooling::IncludeDirective::Include);
```
[logic in the include inserter](https://github.com/llvm/llvm-project/blob/3033f202f6707937cd28c2473479db134993f96f/clang-tools-extra/clangd/Headers.cpp#L307) seem to have the same bug (we should match against paths, not spellings).
https://github.com/llvm/llvm-project/pull/140594
More information about the cfe-commits
mailing list