[clangd] Run semantic highligting in clangd check.
authorHaojian Wu <hokein.wu@gmail.com>
Mon, 31 Oct 2022 09:04:27 +0000 (10:04 +0100)
committerHaojian Wu <hokein.wu@gmail.com>
Mon, 31 Oct 2022 13:46:36 +0000 (14:46 +0100)
Allowing us to test this feature (context: a recent crash in
semantic highlighting.)

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

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

index 1fc44fd29ce988e4af6feb69ad59cc37e31d6043..46752e2135639f75bb876ed36596b5801c701259 100644 (file)
@@ -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 @@ public:
     }
   }
 
+  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);