[PATCH] D66001: [clangd] Added highlighting for constructor initializers.
Johan Vikström via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 9 03:28:34 PDT 2019
jvikstrom created this revision.
jvikstrom added reviewers: hokein, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.
Constructor initializers were not being highlighted. This adds highlighting for them by using TraverseConstructorInitializer. Uses the Traverse* because there is no visit for CXXCtorInitializer.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66001
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
@@ -285,6 +285,19 @@
};
$Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Variable[[O]]) = default;
+ )cpp",
+ R"cpp(
+ enum $Enum[[En]] {};
+ 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) {}
+ };
)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
@@ -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,12 @@
HighlightingTokenCollector>::TraverseNestedNameSpecifierLoc(NNSLoc);
}
+ bool TraverseConstructorInitializer(CXXCtorInitializer *CI) {
+ addToken(CI->getSourceLocation(), CI->getMember());
+ return RecursiveASTVisitor<
+ HighlightingTokenCollector>::TraverseConstructorInitializer(CI);
+ }
+
private:
void addTypeLoc(SourceLocation Loc, const TypeLoc &TL) {
if (const Type *TP = TL.getTypePtr()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66001.214342.patch
Type: text/x-patch
Size: 1814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190809/bca9cc15/attachment.bin>
More information about the cfe-commits
mailing list