[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:44:36 PDT 2019


jvikstrom updated this revision to Diff 214346.
jvikstrom added a comment.

Fixed case where initializer was base class initializer which would cause crash.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66001/new/

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,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);
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,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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66001.214346.patch
Type: text/x-patch
Size: 2035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190809/9284850d/attachment.bin>


More information about the cfe-commits mailing list