[clang-tools-extra] Follow style configuration in clangd when inserting missing includes (PR #140594)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 8 23:21:14 PDT 2025


HighCommander4 wrote:

Apologies for not having had a chance to circle back to this sooner.

I read over the discussion of the [original patch](https://github.com/llvm/llvm-project/pull/67749) that added support for the `QuotedHeaders` and `AngledHeaders` config keys, and it turns out the "resolved path vs. spelling" question does have a back-story.

@sam-mccall [commented](https://github.com/llvm/llvm-project/pull/67749#discussion_r1465335864) during that review:

> This should mention whether we're matching against the path to the header, or its spelling.

and @kleinesfilmroellchen [responded](https://github.com/llvm/llvm-project/pull/67749#discussion_r1466440861):

> We're matching against the spelling; at least in SerenityOS this is a necessary distinction: Naming a same-directory header via `"Widget.h"` will result in quotes, but naming the same header via an "absolute" path like `<LibGUI/Widget.h>` should get you an angled include.

This is what the patch ended up implementing, and documenting [in `ConfigFragment.h`](https://searchfox.org/llvm/rev/55c86c5f77437c15fd29936cc8ad48b2097660b3/clang-tools-extra/clangd/ConfigFragment.h#318-319):

```c++
    /// Matching is performed against the header text, not its absolute path
    /// within the project.
```

So, currently there is an inconsistency between the documentation and the `IncludeInserter` implementation on the one hand (uses the spelling), and the include-cleaner implementation on the other (uses the resolved path). I guess we should resolve that inconsistency, in one direction or another.

In addition to the matter of accommodating project styles, one potential challenge I see with using the resolved path is that the documentation of `include_cleaner::Header::resolvedPath()` [states](https://searchfox.org/llvm/rev/55c86c5f77437c15fd29936cc8ad48b2097660b3/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h#139-140):

>  /// For phiscal files, **either absolute path or path relative to the execution
>  /// root**. Otherwise just the spelling without surrounding quotes/brackets.

Having to write regexes that match an "either/or" seems like a bit of a headache for users.

@kadircet, thoughts on how to proceed?

https://github.com/llvm/llvm-project/pull/140594


More information about the cfe-commits mailing list