[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 03:22:40 PST 2020
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Fixes https://github.com/clangd/clangd/issues/249
Repository:
rG LLVM Github Monorepo
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,17 @@
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";
+ }},
};
// 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 decltype(X) info in `HoverInfo::Definition` anyway.
+ if (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.237276.patch
Type: text/x-patch
Size: 1750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200110/58f06f31/attachment.bin>
More information about the cfe-commits
mailing list