hokein updated this revision to Diff 226673.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments.


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
@@ -48,6 +48,9 @@
     // And fallback to a generic kind if this fails.
     return HighlightingKind::Typedef;
   }
+  if (auto *USD = dyn_cast<UsingShadowDecl>(D))
+    return kindForDecl(USD->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).
@@ -99,11 +102,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 +198,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());


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,9 @@
     // And fallback to a generic kind if this fails.
     return HighlightingKind::Typedef;
   }
+  if (auto *USD = dyn_cast<UsingShadowDecl>(D))
+    return kindForDecl(USD->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).
@@ -99,11 +102,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 +198,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());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to