[PATCH] D69506: [clangd] Add missing highlights for using decls.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 05:43:35 PDT 2019


hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added subscribers: usaxena95, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69506

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
@@ -584,6 +584,11 @@
           return $TemplateParameter[[T]]::$DependentName[[Field]];
         }
       };
+    )cpp",
+      // Highlighting the using decl as the underlying using shadow decl.
+      R"cpp(
+      void $Function[[foo]]();
+      using ::$Function[[foo]];
     )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
@@ -48,6 +48,17 @@
     // And fallback to a generic kind if this fails.
     return HighlightingKind::Typedef;
   }
+  if (auto *UD = dyn_cast<UsingDecl>(D)) {
+    if (UD->shadow_size() == 0)
+      return llvm::None; // Should we add a new highlighting kind?
+    // Highlight the using decl as one of the underlying shadow decls.
+    UsingShadowDecl *Selected = *UD->shadow_begin();
+    llvm::for_each(UD->shadows(), [&Selected](UsingShadowDecl *D) {
+      if (D->getLocation() < Selected->getLocation())
+        Selected = D;
+    });
+    return kindForDecl(Selected->getTargetDecl());
+  }
   // We highlight class decls, constructor decls and destructor decls as
   // `Class` type. The destructor decls are handled in `VisitTagTypeLoc` (we
   // will visit a TypeLoc where the underlying Type is a CXXRecordDecl).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69506.226645.patch
Type: text/x-patch
Size: 1706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191028/94491b51/attachment.bin>


More information about the cfe-commits mailing list