[clangd] Added highlighting for constructor initializers.
Summary: Constructor initializers were not being highlighted. This adds highlighting for them by using TraverseConstructorInitializer. Uses the Traverse* because there is no visit for CXXCtorInitializer.
Reviewers: hokein, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66001
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@368434 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/clangd/SemanticHighlighting.cpp b/clangd/SemanticHighlighting.cpp
index be87dcc..fac9ff7 100644
--- a/clangd/SemanticHighlighting.cpp
+++ b/clangd/SemanticHighlighting.cpp
@@ -11,6 +11,7 @@
#include "Protocol.h"
#include "SourceCode.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include <algorithm>
@@ -136,6 +137,13 @@
HighlightingTokenCollector>::TraverseNestedNameSpecifierLoc(NNSLoc);
}
+ bool TraverseConstructorInitializer(CXXCtorInitializer *CI) {
+ if (const FieldDecl *FD = CI->getMember())
+ addToken(CI->getSourceLocation(), FD);
+ return RecursiveASTVisitor<
+ HighlightingTokenCollector>::TraverseConstructorInitializer(CI);
+ }
+
private:
void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) {
if (const Type *TP = TL.getTypePtr()) {
diff --git a/clangd/unittests/SemanticHighlightingTests.cpp b/clangd/unittests/SemanticHighlightingTests.cpp
index 4405134..76a4530 100644
--- a/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clangd/unittests/SemanticHighlightingTests.cpp
@@ -285,6 +285,24 @@
};
$Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Variable[[O]]) = default;
+ )cpp",
+ R"cpp(
+ enum $Enum[[En]] {
+ $EnumConstant[[EC]],
+ };
+ class $Class[[Foo]] {};
+ class $Class[[Bar]] {
+ $Class[[Foo]] $Field[[Fo]];
+ $Enum[[En]] $Field[[E]];
+ $Primitive[[int]] $Field[[I]];
+ $Class[[Bar]] ($Class[[Foo]] $Variable[[F]],
+ $Enum[[En]] $Variable[[E]])
+ : $Field[[Fo]] ($Variable[[F]]), $Field[[E]] ($Variable[[E]]),
+ $Field[[I]] (123) {}
+ };
+ class $Class[[Bar2]] : public $Class[[Bar]] {
+ $Class[[Bar2]]() : $Class[[Bar]]($Class[[Foo]](), $EnumConstant[[EC]]) {}
+ };
)cpp"};
for (const auto &TestCase : TestCases) {
checkHighlightings(TestCase);