https://github.com/Harald-R created https://github.com/llvm/llvm-project/pull/148371
Following the discussions from https://github.com/llvm/llvm-project/pull/140594, this PR updates the logic in `IncludeInserter` to also use the resolved paths instead of the spellings when filtering headers. >From b3fafea5cd8ed720f70ddfcb713fd27ea87bd811 Mon Sep 17 00:00:00 2001 From: Harald-R <rotuna.raz...@gmail.com> Date: Sat, 12 Jul 2025 16:32:04 +0300 Subject: [PATCH] Use resolved path when filtering in IncludeInserter --- clang-tools-extra/clangd/ConfigFragment.h | 4 ++-- clang-tools-extra/clangd/Headers.cpp | 4 ++-- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp | 4 ++-- .../include-cleaner/include/clang-include-cleaner/Types.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h index 9e00dbc9dc90a..c5488c2378a1e 100644 --- a/clang-tools-extra/clangd/ConfigFragment.h +++ b/clang-tools-extra/clangd/ConfigFragment.h @@ -315,7 +315,7 @@ struct Fragment { /// AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and /// AngledHeaders), system headers use <> and non-system headers use "". /// These can match any suffix of the header file in question. - /// Matching is performed against the header text, not its absolute path + /// Matching is performed against the absolute path of the header /// within the project. std::vector<Located<std::string>> QuotedHeaders; /// List of regexes for headers that should always be included with a @@ -323,7 +323,7 @@ struct Fragment { /// AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and /// AngledHeaders), system headers use <> and non-system headers use "". /// These can match any suffix of the header file in question. - /// Matching is performed against the header text, not its absolute path + /// Matching is performed against the absolute path of the header /// within the project. std::vector<Located<std::string>> AngledHeaders; }; diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index 87fd261b906e6..e2f25334d26d2 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -306,14 +306,14 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader, return std::nullopt; bool IsAngled = false; for (auto &Filter : AngledHeaders) { - if (Filter(Suggested)) { + if (Filter(InsertedHeader.File)) { IsAngled = true; break; } } bool IsQuoted = false; for (auto &Filter : QuotedHeaders) { - if (Filter(Suggested)) { + if (Filter(InsertedHeader.File)) { IsQuoted = true; break; } diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp index b7c64c7a06745..3c107504e6253 100644 --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -938,7 +938,7 @@ TEST(CompletionTest, IncludeInsertionRespectsQuotedAngledConfig) { { Config C; C.Style.AngledHeaders.push_back( - [](auto header) { return header == "bar.h"; }); + [](auto header) { return header.contains("bar.h"); }); WithContextValue WithCfg(Config::Key, std::move(C)); Results = completions(TU, Test.point(), {Sym}); EXPECT_THAT(Results.Completions, @@ -947,7 +947,7 @@ TEST(CompletionTest, IncludeInsertionRespectsQuotedAngledConfig) { { Config C; C.Style.QuotedHeaders.push_back( - [](auto header) { return header == "bar.h"; }); + [](auto header) { return header.contains("bar.h"); }); WithContextValue WithCfg(Config::Key, std::move(C)); Results = completions(TU, Test.point(), {Sym}); EXPECT_THAT(Results.Completions, diff --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h index 2888e25226755..057b92c147047 100644 --- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h +++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h @@ -136,7 +136,7 @@ struct Header { } StringRef verbatim() const { return std::get<Verbatim>(Storage); } - /// For phiscal files, either absolute path or path relative to the execution + /// For physical files, either absolute path or path relative to the execution /// root. Otherwise just the spelling without surrounding quotes/brackets. llvm::StringRef resolvedPath() const; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits