[PATCH] D83511: [clangd] Config: If.PathExclude

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 9 14:33:57 PDT 2020


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83511

Files:
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp


Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -67,6 +67,13 @@
   EXPECT_TRUE(compileAndApply());
   EXPECT_THAT(Diags.Diagnostics, IsEmpty());
 
+  // Excluded regex.
+  Frag = {};
+  Frag.If.PathMatch.emplace_back("b.*");
+  Frag.If.PathExclude.emplace_back(".*r");
+  EXPECT_FALSE(compileAndApply());
+  EXPECT_THAT(Diags.Diagnostics, IsEmpty());
+
   // Invalid regex.
   Frag = {};
   Frag.If.PathMatch.emplace_back("**]@theu");
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -50,6 +50,10 @@
       if (auto Values = scalarValues(N))
         F.PathMatch = std::move(*Values);
     });
+    Dict.handle("PathExclude", [&](Node &N) {
+      if (auto Values = scalarValues(N))
+        F.PathExclude = std::move(*Values);
+    });
     Dict.parse(N);
   }
 
Index: clang-tools-extra/clangd/ConfigFragment.h
===================================================================
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -108,6 +108,9 @@
   struct IfBlock {
     /// The file being processed must fully match a regular expression.
     std::vector<Located<std::string>> PathMatch;
+    /// The file being processed must *not* fully match a regular expression.
+    std::vector<Located<std::string>> PathExclude;
+
     /// An unrecognized key was found while parsing the condition.
     /// The condition will evaluate to false.
     bool HasUnrecognizedCondition = false;
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===================================================================
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -103,6 +103,22 @@
             });
           });
     }
+
+    auto PathExclude = std::make_unique<std::vector<llvm::Regex>>();
+    for (auto &Entry : F.PathExclude) {
+      if (auto RE = compileRegex(Entry))
+        PathExclude->push_back(std::move(*RE));
+    }
+    if (!PathExclude->empty()) {
+      Out.Conditions.push_back(
+          [PathExclude(std::move(PathExclude))](const Params &P) {
+            if (P.Path.empty())
+              return false;
+            return llvm::none_of(*PathExclude, [&](const llvm::Regex &RE) {
+              return RE.match(P.Path);
+            });
+          });
+    }
   }
 
   void compile(Fragment::CompileFlagsBlock &&F) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83511.276839.patch
Type: text/x-patch
Size: 2691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200709/3c37a602/attachment.bin>


More information about the cfe-commits mailing list