[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
zyn0217 wrote: > (I still need to figure out how to do proper stacked PRs...) AFAIK, not possible unless our release manager installs e.g. [such an application](https://github.com/marketplace/stacked-pull-requests) to the repository; but candidly, I have never used it before so I have no idea what kind of shape that would be. This issue is also being tracked at https://github.com/llvm/llvm-project/issues/56636, in case you don't know. https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
@@ -136,6 +136,41 @@ std::string getNamespaceScope(const Decl *D) { return ""; } +void printDeclAndWrappers(const TypedefNameDecl *TND, + llvm::raw_string_ostream , PrintingPolicy PP) { + TND->print(OS, PP); + const Decl *LastPrintedDecl = TND; + + auto PrintDeclForType = [&](QualType T) { +Decl *D = nullptr; +if (const auto *TT = dyn_cast(T.getTypePtr())) { + D = TT->getDecl(); +} else if (const auto *TT = dyn_cast(T.getTypePtr())) { + D = TT->getDecl(); +} +if (D == LastPrintedDecl) { + return false; +} +if (D) { + OS << ";\n"; + D->print(OS, PP); + LastPrintedDecl = D; +} +// In case of D == nullptr, return true. We might have a layer of type +// sugar like ElaboratedType that doesn't itself have a distinct Decl, +// but a subsequent layer of type sugar might. +return true; + }; + + QualType Type = TND->getUnderlyingType(); + while (PrintDeclForType(Type)) { +QualType Desugared = Type->getLocallyUnqualifiedSingleStepDesugaredType(); zyn0217 wrote: My thought: what do you think of resolving pointer types as well? I could envision cases where pointers are involved in an alias type e.g. ```cpp typedef struct _PROCESS_INFORMATION { HANDLE hProcess; HANDLE hThread; DWORD dwProcessId; DWORD dwThreadId; } PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION; ``` (excerpted from [`PROCESS_INFORMATION`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-process_information)) People may want to peek at the definition of the struct while hovering over `LPPROCESS_INFORMATION` too. https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
https://github.com/zyn0217 commented: Thanks for working on this! One thought from me. https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 9617da88ab961145047076c45bb2bb1ac4513634 44aba390954c7b551ed7102e8e7b4209207c0d87 -- clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp `` View the diff from clang-format here. ``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.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.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.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.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 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.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.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.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.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 : 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;\nusing type = int"); + EXPECT_EQ(H->Definition, +"using foo = type;\nusing type = int"); } TEST(Hover, EvaluateMacros) { `` https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
HighCommander4 wrote: Updated patch with the following changes: * Decoupled from https://github.com/clangd/clangd/issues/959 * Handle the case of multiple layers of typedefs, and add tests for this case * Add C language specific tests https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
https://github.com/HighCommander4 edited https://github.com/llvm/llvm-project/pull/89570 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits