[clang-tools-extra] r366045 - [clangd] Added highlighting to enum constants.

Johan Vikstrom via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 00:41:12 PDT 2019


Author: jvikstrom
Date: Mon Jul 15 00:41:12 2019
New Revision: 366045

URL: http://llvm.org/viewvc/llvm-project?rev=366045&view=rev
Log:
[clangd] Added highlighting to enum constants.

Summary: VSCode does not have a scope for enum constants. So they were placed under "constant.other.enum" as that seems to be the most correct scope for enum constants. However, this makes theia color them blue (the same color it uses for keywords).

Reviewers: hokein, sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
    clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
    clang-tools-extra/trunk/clangd/SemanticHighlighting.h
    clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
    clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=366045&r1=366044&r2=366045&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Mon Jul 15 00:41:12 2019
@@ -119,6 +119,10 @@ private:
       addToken(Loc, HighlightingKind::Enum);
       return;
     }
+    if (isa<EnumConstantDecl>(D)) {
+      addToken(Loc, HighlightingKind::EnumConstant);
+      return;
+    }
     if (isa<VarDecl>(D)) {
       addToken(Loc, HighlightingKind::Variable);
       return;
@@ -249,6 +253,8 @@ llvm::StringRef toTextMateScope(Highligh
     return "entity.name.type.class.cpp";
   case HighlightingKind::Enum:
     return "entity.name.type.enum.cpp";
+  case HighlightingKind::EnumConstant:
+    return "variable.other.enummember.cpp";
   case HighlightingKind::Namespace:
     return "entity.name.namespace.cpp";
   case HighlightingKind::NumKinds:

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=366045&r1=366044&r2=366045&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Mon Jul 15 00:41:12 2019
@@ -28,6 +28,7 @@ enum class HighlightingKind {
   Function,
   Class,
   Enum,
+  EnumConstant,
   Namespace,
 
   NumKinds,

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=366045&r1=366044&r2=366045&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Mon Jul 15 00:41:12 2019
@@ -17,6 +17,9 @@
 # CHECK-NEXT:            "entity.name.type.enum.cpp"
 # CHECK-NEXT:          ],
 # CHECK-NEXT:          [
+# CHECK-NEXT:            "variable.other.enummember.cpp"
+# CHECK-NEXT:          ],
+# CHECK-NEXT:          [
 # CHECK-NEXT:            "entity.name.namespace.cpp"
 # CHECK-NEXT:          ]
 # CHECK-NEXT:        ]

Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=366045&r1=366044&r2=366045&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Mon Jul 15 00:41:12 2019
@@ -37,7 +37,8 @@ void checkHighlightings(llvm::StringRef
       {HighlightingKind::Function, "Function"},
       {HighlightingKind::Class, "Class"},
       {HighlightingKind::Enum, "Enum"},
-      {HighlightingKind::Namespace, "Namespace"}};
+      {HighlightingKind::Namespace, "Namespace"},
+      {HighlightingKind::EnumConstant, "EnumConstant"}};
   std::vector<HighlightingToken> ExpectedTokens;
   for (const auto &KindString : KindToString) {
     std::vector<HighlightingToken> Toks = makeHighlightingTokens(
@@ -103,12 +104,19 @@ TEST(SemanticHighlighting, GetsCorrectTo
       }
     )cpp",
     R"cpp(
-      enum class $Enum[[E]] {};
-      enum $Enum[[EE]] {};
+      enum class $Enum[[E]] {
+        $EnumConstant[[A]],
+        $EnumConstant[[B]],
+      };
+      enum $Enum[[EE]] {
+        $EnumConstant[[Hi]],
+      };
       struct $Class[[A]] {
         $Enum[[E]] EEE;
         $Enum[[EE]] EEEE;
       };
+      int $Variable[[I]] = $EnumConstant[[Hi]];
+      $Enum[[E]] $Variable[[L]] = $Enum[[E]]::$EnumConstant[[B]];
     )cpp",
     R"cpp(
       namespace $Namespace[[abc]] {
@@ -118,7 +126,7 @@ TEST(SemanticHighlighting, GetsCorrectTo
           namespace $Namespace[[cde]] {
             struct $Class[[A]] {
               enum class $Enum[[B]] {
-                Hi,
+                $EnumConstant[[Hi]],
               };
             };
           }
@@ -129,7 +137,7 @@ TEST(SemanticHighlighting, GetsCorrectTo
             $Namespace[[abc]]::$Namespace[[bcd]]::$Namespace[[cde]];
       $Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[AA]];
       $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]] $Variable[[AAA]] =
-            $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::Hi;
+            $Namespace[[vwz]]::$Class[[A]]::$Enum[[B]]::$EnumConstant[[Hi]];
       ::$Namespace[[vwz]]::$Class[[A]] $Variable[[B]];
       ::$Namespace[[abc]]::$Namespace[[bcd]]::$Class[[A]] $Variable[[BB]];
     )cpp"};




More information about the cfe-commits mailing list