diff options
Diffstat (limited to 'clang-tools-extra/clangd/ConfigCompile.cpp')
-rw-r--r-- | clang-tools-extra/clangd/ConfigCompile.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index fb76929..aa2561e 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -482,6 +482,55 @@ struct FragmentCompiler { FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end()); }); } + auto QuotedFilter = compileHeaderRegexes(F.QuotedHeaders); + if (QuotedFilter.has_value()) { + Out.Apply.push_back( + [QuotedFilter = *QuotedFilter](const Params &, Config &C) { + C.Style.QuotedHeaders.emplace_back(QuotedFilter); + }); + } + auto AngledFilter = compileHeaderRegexes(F.AngledHeaders); + if (AngledFilter.has_value()) { + Out.Apply.push_back( + [AngledFilter = *AngledFilter](const Params &, Config &C) { + C.Style.AngledHeaders.emplace_back(AngledFilter); + }); + } + } + + auto compileHeaderRegexes(llvm::ArrayRef<Located<std::string>> HeaderPatterns) + -> std::optional<std::function<bool(llvm::StringRef)>> { + // 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 : HeaderPatterns) { + // 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 std::nullopt; + auto Filter = [Filters](llvm::StringRef Path) { + for (auto &Regex : *Filters) + if (Regex.match(Path)) + return true; + return false; + }; + return Filter; } void appendTidyCheckSpec(std::string &CurSpec, |