[clang-tools-extra] [clangd] Show definition of underlying struct when hovering over a typedef (PR #89570)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 26 21:35:51 PDT 2024
================
@@ -136,6 +136,41 @@ std::string getNamespaceScope(const Decl *D) {
return "";
}
+void printDeclAndWrappers(const TypedefNameDecl *TND,
+ llvm::raw_string_ostream &OS, PrintingPolicy PP) {
+ TND->print(OS, PP);
+ const Decl *LastPrintedDecl = TND;
+
+ auto PrintDeclForType = [&](QualType T) {
+ Decl *D = nullptr;
+ if (const auto *TT = dyn_cast<TagType>(T.getTypePtr())) {
+ D = TT->getDecl();
+ } else if (const auto *TT = dyn_cast<TypedefType>(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
More information about the cfe-commits
mailing list