[PATCH] D85272: [clangd] Semantic highlighting for dependent template name in template argument

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 4 20:34:02 PDT 2020


nridge created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85272

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
@@ -686,6 +686,14 @@
       void $Function[[bar]]($TemplateParameter[[T]] $Parameter[[F]]) {
         $Parameter[[F]].$DependentName[[foo]]();
       }
+    )cpp",
+      // Dependent template name
+      R"cpp(
+      template <template <typename> class> struct $Class[[A]] {};
+      template <typename $TemplateParameter[[T]]>
+      using $Typedef[[W]] = $Class[[A]]<
+        $TemplateParameter[[T]]::template $DependentType[[Waldo]]
+      >;
     )cpp"};
   for (const auto &TestCase : TestCases) {
     checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -296,6 +296,17 @@
     return true;
   }
 
+  bool TraverseTemplateArgumentLoc(TemplateArgumentLoc L) {
+    switch (L.getArgument().getKind()) {
+    case TemplateArgument::Template:
+    case TemplateArgument::TemplateExpansion:
+      H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType);
+      break;
+    default:;
+    }
+    return RecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
+  }
+
   // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85272.283116.patch
Type: text/x-patch
Size: 1675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200805/5f47d4f3/attachment-0001.bin>


More information about the cfe-commits mailing list