diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -37,6 +37,10 @@ llvm::Optional kindForType(const Type *TP); llvm::Optional kindForDecl(const NamedDecl *D) { + if (auto *USD = dyn_cast(D)) { + if (auto *Target = USD->getTargetDecl()) + D = Target; + } if (auto *TD = dyn_cast(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 -kindForCandidateDecls(llvm::iterator_range Decls) { +// Given a set of candidate declarations, if the declarations all have the same +// highlighting kind, return that highlighting kind, otherwise return None. +template +llvm::Optional kindForCandidateDecls(IteratorRange Decls) { llvm::Optional 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()); diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/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);