This revision was automatically updated to reflect the committed changes.
Closed by commit rG86f1313424fb: [clangd] Config: If.PathExclude (authored by 
sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D83511?vs=276839&id=277000#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83511/new/

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()) << "Included but also excluded";
+  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) {


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()) << "Included but also excluded";
+  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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to