[PATCH] D70746: [clangd] Highlighting dependent types in more contexts

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 16:28:39 PST 2019


nridge updated this revision to Diff 232012.
nridge added a comment.

Address nit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70746

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


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -630,7 +630,24 @@
       R"cpp(
       template <typename... $TemplateParameter[[Elements]]>
       struct $Class[[TupleSize]] {
-        static const int $StaticField[[size]] = sizeof...($TemplateParameter[[Elements]]);
+        static const int $StaticField[[size]] =
+sizeof...($TemplateParameter[[Elements]]);
+      };
+    )cpp",
+      // More dependent types
+      R"cpp(
+      template <typename $TemplateParameter[[T]]>
+      struct $Class[[Waldo]] {
+        using $Typedef[[Location1]] = typename $TemplateParameter[[T]]
+            ::$DependentType[[Resolver]]::$DependentType[[Location]];
+        using $Typedef[[Location2]] = typename $TemplateParameter[[T]]
+            ::template $DependentType[[Resolver]]<$TemplateParameter[[T]]>
+            ::$DependentType[[Location]];
+        using $Typedef[[Location3]] = typename $TemplateParameter[[T]]
+            ::$DependentType[[Resolver]]
+            ::template $DependentType[[Location]]<$TemplateParameter[[T]]>;
+        static const int $StaticField[[Value]] = $TemplateParameter[[T]]
+            ::$DependentType[[Resolver]]::$DependentName[[Value]];
       };
     )cpp"};
   for (const auto &TestCase : TestCases) {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -258,6 +258,25 @@
     return true;
   }
 
+  bool VisitDependentTemplateSpecializationTypeLoc(
+      DependentTemplateSpecializationTypeLoc L) {
+    H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType);
+    return true;
+  }
+
+  // findExplicitReferences will walk nested-name-specifiers and
+  // find anything that can be resolved to a Decl. However, non-leaf
+  // components of nested-name-specifiers which are dependent names
+  // (kind "Identifier") cannot be resolved to a decl, so we visit
+  // them here.
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Q) {
+    if (NestedNameSpecifier *NNS = Q.getNestedNameSpecifier()) {
+      if (NNS->getKind() == NestedNameSpecifier::Identifier)
+        H.addToken(Q.getLocalBeginLoc(), HighlightingKind::DependentType);
+    }
+    return RecursiveASTVisitor::TraverseNestedNameSpecifierLoc(Q);
+  }
+
 private:
   HighlightingsBuilder &H;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70746.232012.patch
Type: text/x-patch
Size: 2646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191204/1b8f6d22/attachment.bin>


More information about the cfe-commits mailing list