[PATCH] D85500: [clangd] Highlight structured bindings at local scope as LocalVariable

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 00:22:52 PDT 2020


nridge updated this revision to Diff 283827.
nridge added a comment.

Fix clang-tidy warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85500

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
@@ -515,13 +515,14 @@
         $Class[[S]] *$Field[[Next]];
       };
       $Class[[S]] $Variable[[Global]][2] = {$Class[[S]](), $Class[[S]]()};
+      auto [$Variable[[G1]], $Variable[[G2]]] = $Variable[[Global]];
       void $Function[[f]]($Class[[S]] $Parameter[[P]]) {
         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]];
+        auto [$LocalVariable[[B1]], $LocalVariable[[B2]]] = $LocalVariable[[A]];
+        auto [$LocalVariable[[G1]], $LocalVariable[[G2]]] = $Variable[[Global]];
+        $Class[[auto]] [$LocalVariable[[P1]], $LocalVariable[[P2]]] = $Parameter[[P]];
         // Highlights references to BindingDecls.
-        $Variable[[B1]]++;
+        $LocalVariable[[B1]]++;
       }
     )cpp",
       R"cpp(
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -90,8 +90,10 @@
                ? HighlightingKind::StaticField
                : VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
                                       : HighlightingKind::Variable;
-  if (isa<BindingDecl>(D))
-    return HighlightingKind::Variable;
+  if (const auto *BD = dyn_cast<BindingDecl>(D))
+    return BD->getDeclContext()->isFunctionOrMethod()
+               ? HighlightingKind::LocalVariable
+               : HighlightingKind::Variable;
   if (isa<FunctionDecl>(D))
     return HighlightingKind::Function;
   if (isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D) ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85500.283827.patch
Type: text/x-patch
Size: 2060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200807/e2966803/attachment.bin>


More information about the cfe-commits mailing list