diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2020-01-21 16:49:32 +0100 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2020-01-27 16:35:12 +0100 |
commit | 53f39c77b2ba74626b0dfd5efbfdf39b2f0d720e (patch) | |
tree | 52393a5b8acc70b7e6f775c8ad7d66174b1ffe72 /clang-tools-extra | |
parent | 1426bb44cc777fbbd867a1eaeb25d6460a99214c (diff) | |
download | bcm5719-llvm-53f39c77b2ba74626b0dfd5efbfdf39b2f0d720e.tar.gz bcm5719-llvm-53f39c77b2ba74626b0dfd5efbfdf39b2f0d720e.zip |
[clangd] Drop returntype/type when hovering over type-ish names
Summary:
Some names, e.g. constructor/destructor/conversions, already contain
the type info, no need to duplicate them in the hoverinfo.
Fixes https://github.com/clangd/clangd/issues/252
Reviewers: sammccall, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73110
(cherry picked from commit 1fbb1d6df0113ca341f6d257bc72e07343dd861a)
Diffstat (limited to 'clang-tools-extra')
-rw-r--r-- | clang-tools-extra/clangd/Hover.cpp | 25 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 |
2 files changed, 21 insertions, 15 deletions
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp index cfa5e3bf93f..8ce67018fd3 100644 --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -266,20 +266,19 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D, } } - if (const auto *CCD = llvm::dyn_cast<CXXConstructorDecl>(FD)) { - // Constructor's "return type" is the class type. - HI.ReturnType = declaredType(CCD->getParent()).getAsString(Policy); - // Don't provide any type for the constructor itself. - } else if (llvm::isa<CXXDestructorDecl>(FD)) { - HI.ReturnType = "void"; - } else { - HI.ReturnType = printType(FD->getReturnType(), Policy); + // We don't want any type info, if name already contains it. This is true for + // constructors/destructors and conversion operators. + const auto NK = FD->getDeclName().getNameKind(); + if (NK == DeclarationName::CXXConstructorName || + NK == DeclarationName::CXXDestructorName || + NK == DeclarationName::CXXConversionFunctionName) + return; - QualType QT = FD->getType(); - if (const VarDecl *VD = llvm::dyn_cast<VarDecl>(D)) // Lambdas - QT = VD->getType().getDesugaredType(D->getASTContext()); - HI.Type = printType(QT, Policy); - } + HI.ReturnType = printType(FD->getReturnType(), Policy); + QualType QT = FD->getType(); + if (const VarDecl *VD = llvm::dyn_cast<VarDecl>(D)) // Lambdas + QT = VD->getType().getDesugaredType(D->getASTContext()); + HI.Type = printType(QT, Policy); // FIXME: handle variadics. } diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 9b6f2b185bf..67257bac639 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -327,7 +327,6 @@ class Foo {})cpp"; HI.Name = "X"; HI.LocalScope = "X<T *>::"; // FIXME: X<T *, void>:: HI.Kind = index::SymbolKind::Constructor; - HI.ReturnType = "X<T *>"; HI.Definition = "X()"; HI.Parameters.emplace(); }}, @@ -337,10 +336,18 @@ class Foo {})cpp"; HI.Name = "~X"; HI.LocalScope = "X::"; HI.Kind = index::SymbolKind::Destructor; - HI.ReturnType = "void"; HI.Definition = "~X()"; HI.Parameters.emplace(); }}, + {"class X { operator [[in^t]](); };", + [](HoverInfo &HI) { + HI.NamespaceScope = ""; + HI.Name = "operator int"; + HI.LocalScope = "X::"; + HI.Kind = index::SymbolKind::ConversionFunction; + HI.Definition = "operator int()"; + HI.Parameters.emplace(); + }}, // auto on lambda {R"cpp( |