[clang-tools-extra] r370473 - [clangd] Added highlighting for structured bindings.

Johan Vikstrom via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 07:07:06 PDT 2019


Author: jvikstrom
Date: Fri Aug 30 07:07:05 2019
New Revision: 370473

URL: http://llvm.org/viewvc/llvm-project?rev=370473&view=rev
Log:
[clangd] Added highlighting for structured bindings.

Summary: Structured bindings are in a BindingDecl. The decl the declRefExpr points to are the BindingDecls. So this adds an additional if statement in the addToken function to highlight them.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66738

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=370473&r1=370472&r2=370473&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Fri Aug 30 07:07:05 2019
@@ -233,6 +233,10 @@ private:
                                                : HighlightingKind::Variable);
       return;
     }
+    if (isa<BindingDecl>(D)) {
+      addToken(Loc, HighlightingKind::Variable);
+      return;
+    }
     if (isa<FunctionDecl>(D)) {
       addToken(Loc, HighlightingKind::Function);
       return;

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=370473&r1=370472&r2=370473&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp Fri Aug 30 07:07:05 2019
@@ -436,6 +436,21 @@ TEST(SemanticHighlighting, GetsCorrectTo
         assert($Variable[[x]] != $Variable[[y]]);
         assert($Variable[[x]] != $Function[[f]]());
       }
+    )cpp",
+    R"cpp(
+      struct $Class[[S]] {
+        $Primitive[[float]] $Field[[Value]];
+        $Class[[S]] *$Field[[Next]];
+      };
+      $Class[[S]] $Variable[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
+      $Primitive[[void]] $Function[[f]]($Class[[S]] $Parameter[[P]]) {
+        $Primitive[[int]] $LocalVariable[[A]][2] = {1,2};
+        auto [$Variable[[B1]], $Variable[[B2]]] = $LocalVariable[[A]];
+        auto [$Variable[[G1]], $Variable[[G2]]] = $Variable[[Global]];
+        $Class[[auto]] [$Variable[[P1]], $Variable[[P2]]] = $Parameter[[P]];
+        // Highlights references to BindingDecls.
+        $Variable[[B1]]++;
+      }
     )cpp"};
   for (const auto &TestCase : TestCases) {
     checkHighlightings(TestCase);




More information about the cfe-commits mailing list