[PATCH] D64754: [clangd] Added highlighting for the targets in typedefs.

Johan Vikström via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 06:23:20 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL366207: [clangd] Added highlighting for the targets in typedefs and using. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64754?vs=210053&id=210084#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64754

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -93,6 +93,12 @@
     return true;
   }
 
+  bool VisitTypedefNameDecl(TypedefNameDecl *TD) {
+    if(const auto *TSI = TD->getTypeSourceInfo())
+      addTypeLoc(TD->getLocation(), TSI->getTypeLoc());
+    return true;
+  }
+
   bool VisitTypeLoc(TypeLoc &TL) {
     // This check is for not getting two entries when there are anonymous
     // structs. It also makes us not highlight certain namespace qualifiers
@@ -101,9 +107,7 @@
     if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
       return true;
 
-    if (const Type *TP = TL.getTypePtr())
-      if (const TagDecl *TD = TP->getAsTagDecl())
-        addToken(TL.getBeginLoc(), TD);
+    addTypeLoc(TL.getBeginLoc(), TL);
     return true;
   }
 
@@ -118,6 +122,12 @@
   }
 
 private:
+  void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) {
+    if (const Type *TP = TL.getTypePtr())
+      if (const TagDecl *TD = TP->getAsTagDecl())
+        addToken(Loc, TD);
+  }
+
   void addToken(SourceLocation Loc, const NamedDecl *D) {
     if (D->getDeclName().isIdentifier() && D->getName().empty())
       // Don't add symbols that don't have any length.
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -90,7 +90,7 @@
         typename T::A* $Field[[D]];
       };
       $Namespace[[abc]]::$Class[[A]]<int> $Variable[[AA]];
-      typedef $Namespace[[abc]]::$Class[[A]]<int> AAA;
+      typedef $Namespace[[abc]]::$Class[[A]]<int> $Class[[AAA]];
       struct $Class[[B]] {
         $Class[[B]]();
         ~$Class[[B]]();
@@ -173,6 +173,19 @@
       }
       int $Variable[[B]];
       $Class[[AA]] $Variable[[A]]{$Variable[[B]]};
+    )cpp",
+    R"cpp(
+      namespace $Namespace[[a]] {
+        struct $Class[[A]] {};
+      }
+      typedef $Namespace[[a]]::$Class[[A]] $Class[[B]];
+      using $Class[[BB]] = $Namespace[[a]]::$Class[[A]];
+      enum class $Enum[[E]] {};
+      typedef $Enum[[E]] $Enum[[C]];
+      typedef $Enum[[C]] $Enum[[CC]];
+      using $Enum[[CD]] = $Enum[[CC]];
+      $Enum[[CC]] $Function[[f]]($Class[[B]]);
+      $Enum[[CD]] $Function[[f]]($Class[[BB]]);
     )cpp"};
   for (const auto &TestCase : TestCases) {
     checkHighlightings(TestCase);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64754.210084.patch
Type: text/x-patch
Size: 2668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190716/1ea99e03/attachment.bin>


More information about the llvm-commits mailing list