[PATCH] D72498: [clangd] Print underlying type for decltypes in hover
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 10 04:21:56 PST 2020
kadircet updated this revision to Diff 237284.
kadircet marked an inline comment as done.
kadircet added a comment.
- Update comment
- Iteratively resolve underlying decltypes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72498/new/
https://reviews.llvm.org/D72498
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
@@ -1501,6 +1501,40 @@
HI.Name = "cls<cls<cls<int> > >";
HI.Documentation = "type of nested templates.";
}},
+ {
+ R"cpp(// type with decltype
+ int a;
+ decltype(a) [[b^]] = a;)cpp",
+ [](HoverInfo &HI) {
+ HI.Definition = "decltype(a) b = a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Name = "b";
+ HI.Type = "int";
+ }},
+ {
+ R"cpp(// type with decltype
+ int a;
+ decltype(a) c;
+ decltype(c) [[b^]] = a;)cpp",
+ [](HoverInfo &HI) {
+ HI.Definition = "decltype(c) b = a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Name = "b";
+ HI.Type = "int";
+ }},
+ {
+ R"cpp(// type with decltype
+ int a;
+ const decltype(a) [[b^]] = a;)cpp",
+ [](HoverInfo &HI) {
+ HI.Definition = "const decltype(a) b = a";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.NamespaceScope = "";
+ HI.Name = "b";
+ HI.Type = "int";
+ }},
};
// Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -345,8 +345,14 @@
// Fill in types and params.
if (const FunctionDecl *FD = getUnderlyingFunction(D))
fillFunctionTypeAndParams(HI, D, FD, Policy);
- else if (const auto *VD = dyn_cast<ValueDecl>(D))
- HI.Type = VD->getType().getAsString(Policy);
+ else if (const auto *VD = dyn_cast<ValueDecl>(D)) {
+ QualType QT = VD->getType();
+ // TypePrinter doesn't resolve decltypes, so resolve them here. We are going
+ // to include spelling "decltype(X)" in `HoverInfo::Definition` anyway.
+ while (auto *DT = QT->getAs<DecltypeType>())
+ QT = DT->getUnderlyingType();
+ HI.Type = QT.getAsString(Policy);
+ }
// Fill in value with evaluated initializer if possible.
if (const auto *Var = dyn_cast<VarDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72498.237284.patch
Type: text/x-patch
Size: 2497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200110/767d9bee/attachment.bin>
More information about the cfe-commits
mailing list