[clang-tools-extra] 86f1313 - [clangd] Config: If.PathExclude

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 05:31:14 PDT 2020


Author: Sam McCall
Date: 2020-07-10T14:31:02+02:00
New Revision: 86f1313424fb578b0fd6c950d3ce7cb241f326ea

URL: https://github.com/llvm/llvm-project/commit/86f1313424fb578b0fd6c950d3ce7cb241f326ea
DIFF: https://github.com/llvm/llvm-project/commit/86f1313424fb578b0fd6c950d3ce7cb241f326ea.diff

LOG: [clangd] Config: If.PathExclude

Reviewers: hokein

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83511

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 63c1681ceb0b..04c0df88bbf7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -103,6 +103,22 @@ struct FragmentCompiler {
             });
           });
     }
+
+    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) {

diff  --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h
index be5bd5edc188..42f9ec2edc72 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -108,6 +108,9 @@ struct Fragment {
   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;

diff  --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp
index 0674c6030903..ef6003b02439 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -50,6 +50,10 @@ class Parser {
       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);
   }
 

diff  --git a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
index 17db87afecfd..825d6878727d 100644
--- a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -67,6 +67,13 @@ TEST_F(ConfigCompileTests, Condition) {
   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");


        


More information about the cfe-commits mailing list