Author: Kadir Cetinkaya Date: 2022-06-15T16:10:49+02:00 New Revision: 7212977fbb41bcffaf28a33a70c2df2b40492524
URL: https://github.com/llvm/llvm-project/commit/7212977fbb41bcffaf28a33a70c2df2b40492524 DIFF: https://github.com/llvm/llvm-project/commit/7212977fbb41bcffaf28a33a70c2df2b40492524.diff LOG: [clangd] Always desugar type aliases in hover The alias itself is already included in the definition section of the hover (it's printed as spelled in source code). So it doesn't provide any value when we print the aliases as-is. Fixes https://github.com/clangd/clangd/issues/1134. Differential Revision: https://reviews.llvm.org/D127832 Added: Modified: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index fcf3af756184..07552c5869fa 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -623,7 +623,8 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP, 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); diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 25ce19b2c580..0f149b724296 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -3206,6 +3206,30 @@ TEST(Hover, HideBigInitializers) { 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits