[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 16:02:59 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 9617da88ab961145047076c45bb2bb1ac4513634 44aba390954c7b551ed7102e8e7b4209207c0d87 -- clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 582a311f35..fbef81f781 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1657,35 +1657,34 @@ TEST(Hover, All) {
             HI.NamespaceScope = "ns1::";
             HI.Definition = "struct MyClass {}";
           }},
-          {
-            R"cpp(// Typedef to struct
+      {
+          R"cpp(// Typedef to struct
               struct Point { int x; int y; };
               typedef Point TPoint;
               [[TP^oint]] tp;
             )cpp",
-            [](HoverInfo &HI) {
-              HI.Name = "TPoint";
-              HI.Kind = index::SymbolKind::TypeAlias;
-              HI.NamespaceScope = "";
-              HI.Type = "struct Point";
-              HI.Definition = "typedef Point TPoint;\nstruct Point {}";
-            }
-          },
-          {
-            R"cpp(// Two layers of typedef
+          [](HoverInfo &HI) {
+            HI.Name = "TPoint";
+            HI.Kind = index::SymbolKind::TypeAlias;
+            HI.NamespaceScope = "";
+            HI.Type = "struct Point";
+            HI.Definition = "typedef Point TPoint;\nstruct Point {}";
+          }},
+      {
+          R"cpp(// Two layers of typedef
               struct Point { int x; int y; };
               typedef Point TPoint;
               typedef TPoint TTPoint;
               [[TTP^oint]] tp;
             )cpp",
-            [](HoverInfo &HI) {
-              HI.Name = "TTPoint";
-              HI.Kind = index::SymbolKind::TypeAlias;
-              HI.NamespaceScope = "";
-              HI.Type = "struct Point";
-              HI.Definition = "typedef TPoint TTPoint;\ntypedef Point TPoint;\nstruct Point {}";
-            }
-          },
+          [](HoverInfo &HI) {
+            HI.Name = "TTPoint";
+            HI.Kind = index::SymbolKind::TypeAlias;
+            HI.NamespaceScope = "";
+            HI.Type = "struct Point";
+            HI.Definition = "typedef TPoint TTPoint;\ntypedef Point "
+                            "TPoint;\nstruct Point {}";
+          }},
       {
           R"cpp(// Class
             namespace ns1 {
@@ -3158,35 +3157,34 @@ TEST(Hover, CLanguage) {
     const char *const Code;
     const std::function<void(HoverInfo &)> ExpectedBuilder;
   } Cases[] = {
-    {
-      R"cpp(// Typedef to struct
+      {
+          R"cpp(// Typedef to struct
         struct Point { int x; int y; };
         typedef struct Point TPoint;
         [[TP^oint]] tp;
       )cpp",
-      [](HoverInfo &HI) {
-        HI.Name = "TPoint";
-        HI.Kind = index::SymbolKind::TypeAlias;
-        HI.NamespaceScope = "";
-        HI.Type = "struct Point";
-        HI.Definition = "typedef struct Point TPoint;\nstruct Point {}";
-      }
-    },
-    {
-      R"cpp(// Two layers of typedef
+          [](HoverInfo &HI) {
+            HI.Name = "TPoint";
+            HI.Kind = index::SymbolKind::TypeAlias;
+            HI.NamespaceScope = "";
+            HI.Type = "struct Point";
+            HI.Definition = "typedef struct Point TPoint;\nstruct Point {}";
+          }},
+      {
+          R"cpp(// Two layers of typedef
         struct Point { int x; int y; };
         typedef struct Point TPoint;
         typedef TPoint TTPoint;
         [[TTP^oint]] tp;
       )cpp",
-      [](HoverInfo &HI) {
-        HI.Name = "TTPoint";
-        HI.Kind = index::SymbolKind::TypeAlias;
-        HI.NamespaceScope = "";
-        HI.Type = "struct Point";
-        HI.Definition = "typedef TPoint TTPoint;\ntypedef struct Point TPoint;\nstruct Point {}";
-      }
-    },
+          [](HoverInfo &HI) {
+            HI.Name = "TTPoint";
+            HI.Kind = index::SymbolKind::TypeAlias;
+            HI.NamespaceScope = "";
+            HI.Type = "struct Point";
+            HI.Definition = "typedef TPoint TTPoint;\ntypedef struct Point "
+                            "TPoint;\nstruct Point {}";
+          }},
   };
   for (const auto &Case : Cases) {
     SCOPED_TRACE(Case.Code);
@@ -4117,7 +4115,8 @@ TEST(Hover, Typedefs) {
 
   ASSERT_TRUE(H && H->Type);
   EXPECT_EQ(H->Type->Type, "int");
-  EXPECT_EQ(H->Definition, "using foo = type<true, int, double>;\nusing type = int");
+  EXPECT_EQ(H->Definition,
+            "using foo = type<true, int, double>;\nusing type = int");
 }
 
 TEST(Hover, EvaluateMacros) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/89570


More information about the cfe-commits mailing list