[PATCH] D127832: [clangd] Always desugar type aliases in hover

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 07:13:04 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7212977fbb41: [clangd] Always desugar type aliases in hover (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127832

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3206,6 +3206,30 @@
   ASSERT_TRUE(H);
   EXPECT_EQ(H->Definition, "int arr[]");
 }
+
+TEST(Hover, Typedefs) {
+  Annotations T(R"cpp(
+  template <bool X, typename T, typename F>
+  struct cond { using type = T; };
+  template <typename T, typename F>
+  struct cond<false, T, F> { using type = F; };
+
+  template <bool X, typename T, typename F>
+  using type = typename cond<X, T, F>::type;
+
+  void foo() {
+    using f^oo = type<true, int, double>;
+  }
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+
+  ASSERT_TRUE(H && H->Type);
+  EXPECT_EQ(H->Type->Type, "int");
+  EXPECT_EQ(H->Definition, "using foo = type<true, int, double>");
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -623,7 +623,8 @@
     HI.Type =
         printType(VT->getTemplatedDecl()->getType(), VT->getASTContext(), PP);
   else if (const auto *TN = dyn_cast<TypedefNameDecl>(D))
-    HI.Type = printType(TN->getUnderlyingType(), TN->getASTContext(), PP);
+    HI.Type = printType(TN->getUnderlyingType().getDesugaredType(Ctx),
+                        TN->getASTContext(), PP);
   else if (const auto *TAT = dyn_cast<TypeAliasTemplateDecl>(D))
     HI.Type = printType(TAT->getTemplatedDecl()->getUnderlyingType(),
                         TAT->getASTContext(), PP);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127832.437150.patch
Type: text/x-patch
Size: 1800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/18075d9a/attachment.bin>


More information about the cfe-commits mailing list