[clang-tools-extra] r368434 - [clangd] Added highlighting for constructor initializers.
Johan Vikstrom via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 9 05:19:10 PDT 2019
Author: jvikstrom
Date: Fri Aug 9 05:19:10 2019
New Revision: 368434
URL: http://llvm.org/viewvc/llvm-project?rev=368434&view=rev
Log:
[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
Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=368434&r1=368433&r2=368434&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Fri Aug 9 05:19:10 2019
@@ -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 @@ public:
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()) {
Modified: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp?rev=368434&r1=368433&r2=368434&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Fri Aug 9 05:19:10 2019
@@ -285,6 +285,24 @@ TEST(SemanticHighlighting, GetsCorrectTo
};
$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);
More information about the cfe-commits
mailing list