[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 30 20:43:33 PDT 2023


================
@@ -483,6 +483,72 @@ struct FragmentCompiler {
             FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end());
       });
     }
+
+// TODO: Share this code with Diagnostics.Includes.IgnoreHeader
+#ifdef CLANGD_PATH_CASE_INSENSITIVE
+    static llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
+#else
+    static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
+#endif
+    {
+      auto Filters = std::make_shared<std::vector<llvm::Regex>>();
+      for (auto &HeaderPattern : F.AngledHeaders) {
+        // Anchor on the right.
+        std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
+        llvm::Regex CompiledRegex(AnchoredPattern, Flags);
+        std::string RegexError;
+        if (!CompiledRegex.isValid(RegexError)) {
+          diag(Warning,
+               llvm::formatv("Invalid regular expression '{0}': {1}",
+                             *HeaderPattern, RegexError)
+                   .str(),
+               HeaderPattern.Range);
+          continue;
+        }
+        Filters->push_back(std::move(CompiledRegex));
+      }
+      if (Filters->empty())
+        return;
----------------
zyn0217 wrote:

I think this is why you're seeing the puzzling behavior: You've bailed out of parsing the `QuotedHeaders` block if don't see any `AngledHeaders` field. Perhaps extract these two blocks into separate functions?

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


More information about the cfe-commits mailing list