aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaojian Wu <hokein.wu@gmail.com>2019-10-28 13:42:20 +0100
committerHaojian Wu <hokein.wu@gmail.com>2019-10-29 09:49:42 +0100
commit94cd2f03032475e26767cf11eb81fefb00fc4dc0 (patch)
tree982ab11643a90cb7040f77618c9533d7226b4e81
parent3fe7f1dcf44ced0648fd0aef2b33056bbee37881 (diff)
downloadllvm-94cd2f03032475e26767cf11eb81fefb00fc4dc0.zip
llvm-94cd2f03032475e26767cf11eb81fefb00fc4dc0.tar.gz
llvm-94cd2f03032475e26767cf11eb81fefb00fc4dc0.tar.bz2
[clangd] Add missing highlights for using decls.
Reviewers: ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69506
-rw-r--r--clang-tools-extra/clangd/SemanticHighlighting.cpp19
-rw-r--r--clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp5
2 files changed, 19 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 464cbc4..62d3a16 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -37,6 +37,10 @@ bool canHighlightName(DeclarationName Name) {
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 @@ llvm::Optional<HighlightingKind> kindForType(const Type *TP) {
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 @@ public:
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
index 9d33b52..139773b 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -584,6 +584,11 @@ TEST(SemanticHighlighting, GetsCorrectTokens) {
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);