[clang-tools-extra] [clangd] Handle IndirectFieldDecl in kindForDecl (PR #80588)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 00:16:15 PST 2024


https://github.com/HighCommander4 updated https://github.com/llvm/llvm-project/pull/80588

>From a2f622aa59d0bd2d2220ae08a6c3e26dd794e2e0 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Sun, 4 Feb 2024 02:22:38 -0500
Subject: [PATCH] [clangd] Handle IndirectFieldDecl in kindForDecl

https://github.com/clangd/clangd/issues/1925
---
 .../clangd/SemanticHighlighting.cpp              |  2 +-
 .../unittests/SemanticHighlightingTests.cpp      | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index 37939d36425a9..078b40c9db148 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -136,7 +136,7 @@ std::optional<HighlightingKind> kindForDecl(const NamedDecl *D,
   if (auto *OMD = dyn_cast<ObjCMethodDecl>(D))
     return OMD->isClassMethod() ? HighlightingKind::StaticMethod
                                 : HighlightingKind::Method;
-  if (isa<FieldDecl, ObjCPropertyDecl>(D))
+  if (isa<FieldDecl, IndirectFieldDecl, ObjCPropertyDecl>(D))
     return HighlightingKind::Field;
   if (isa<EnumDecl>(D))
     return HighlightingKind::Enum;
diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index da12accc7898b..4156921d83edf 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -1076,6 +1076,22 @@ sizeof...($TemplateParameter[[Elements]]);
             using $Class[[Y]]$Bracket[[<]]0$Bracket[[>]]::$Unknown_dependentName[[xxx]];
           };
         };
+    )cpp",
+      // Heuristically resolved IndirectFieldDecl
+      R"cpp(
+        template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+        struct $Class_def[[Base]] {
+          struct {
+            int $Field_decl[[waldo]];
+          };
+        };
+        template $Bracket[[<]]typename $TemplateParameter_def[[T]]$Bracket[[>]]
+        struct $Class_def[[Derived]] : $Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]] {
+          using $Class[[Base]]$Bracket[[<]]$TemplateParameter[[T]]$Bracket[[>]]::$Field_dependentName[[waldo]];
+          void $Method_def[[foo]]() {
+            $Field_dependentName[[waldo]];
+          }
+        };
     )cpp"};
   for (const auto &TestCase : TestCases)
     // Mask off scope modifiers to keep the tests manageable.



More information about the cfe-commits mailing list