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

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 01:54:36 PDT 2019


hokein updated this revision to Diff 226851.
hokein marked 2 inline comments as done.
hokein added a comment.

address remaining nits.


Repository:
  rG LLVM Github Monorepo

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

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
@@ -37,6 +37,10 @@
 
 llvm::Optional<HighlightingKind> kindForType(const Type *TP);
 llvm::Optional<HighlightingKind> kindForDecl(const NamedDecl *D) {
+  if (auto *USD = dyn_cast<UsingShadowDecl>(D)) {
+    if (auto *Target = USD->getTargetDecl())
+      D = Target;
+  }
   if (auto *TD = dyn_cast<TemplateDecl>(D)) {
     if (auto *Templated = TD->getTemplatedDecl())
       D = Templated;
@@ -99,11 +103,10 @@
     return kindForDecl(TD);
   return llvm::None;
 }
-// Given a set of candidate declarations for an unresolved name,
-// if the declarations all have the same highlighting kind, return
-// that highlighting kind, otherwise return None.
-llvm::Optional<HighlightingKind>
-kindForCandidateDecls(llvm::iterator_range<UnresolvedSetIterator> Decls) {
+// Given a set of candidate declarations, if the declarations all have the same
+// highlighting kind, return that highlighting kind, otherwise return None.
+template <typename IteratorRange>
+llvm::Optional<HighlightingKind> kindForCandidateDecls(IteratorRange Decls) {
   llvm::Optional<HighlightingKind> Result;
   for (NamedDecl *Decl : Decls) {
     auto Kind = kindForDecl(Decl);
@@ -196,6 +199,12 @@
     return true;
   }
 
+  bool VisitUsingDecl(UsingDecl *UD) {
+    if (auto K = kindForCandidateDecls(UD->shadows()))
+      addToken(UD->getLocation(), *K);
+    return true;
+  }
+
   bool VisitDeclRefExpr(DeclRefExpr *Ref) {
     if (canHighlightName(Ref->getNameInfo().getName()))
       addToken(Ref->getLocation(), Ref->getDecl());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69506.226851.patch
Type: text/x-patch
Size: 2391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191029/b46cc14c/attachment-0001.bin>


More information about the cfe-commits mailing list