[clang-tools-extra] e3ec9dd - [clangd] Run semantic highligting in clangd check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 06:47:15 PDT 2022


Author: Haojian Wu
Date: 2022-10-31T14:46:36+01:00
New Revision: e3ec9dd0ba42a6022b37d8a61e20fe338b8dc51f

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

LOG: [clangd] Run semantic highligting in clangd check.

Allowing us to test this feature (context: a recent crash in
semantic highlighting.)

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

Added: 
    

Modified: 
    clang-tools-extra/clangd/tool/Check.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/tool/Check.cpp b/clang-tools-extra/clangd/tool/Check.cpp
index 1fc44fd29ce98..46752e2135639 100644
--- a/clang-tools-extra/clangd/tool/Check.cpp
+++ b/clang-tools-extra/clangd/tool/Check.cpp
@@ -34,6 +34,7 @@
 #include "ParsedAST.h"
 #include "Preamble.h"
 #include "Protocol.h"
+#include "SemanticHighlighting.h"
 #include "SourceCode.h"
 #include "XRefs.h"
 #include "index/CanonicalIncludes.h"
@@ -206,6 +207,14 @@ class Checker {
     }
   }
 
+  void buildSemanticHighlighting(llvm::Optional<Range> LineRange) {
+    log("Building semantic highlighting");
+    auto Highlights = getSemanticHighlightings(*AST);
+    for (const auto HL : Highlights)
+      if (!LineRange || LineRange->contains(HL.R))
+        vlog(" {0} {1} {2}", HL.R, HL.Kind, HL.Modifiers);
+  }
+
   // Run AST-based features at each token in the file.
   void testLocationFeatures(llvm::Optional<Range> LineRange,
                             const bool EnableCodeCompletion) {
@@ -302,6 +311,7 @@ bool check(llvm::StringRef File, llvm::Optional<Range> LineRange,
       !C.buildAST())
     return false;
   C.buildInlayHints(LineRange);
+  C.buildSemanticHighlighting(LineRange);
   C.testLocationFeatures(LineRange, EnableCodeCompletion);
 
   log("All checks completed, {0} errors", C.ErrCount);


        


More information about the cfe-commits mailing list