This revision was automatically updated to reflect the committed changes. Closed by commit rG1fbb1d6df011: [clangd] Drop returntype/type when hovering over type-ish names (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D73110/new/ https://reviews.llvm.org/D73110 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 @@ -327,7 +327,6 @@ 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 @@ 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( Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -266,20 +266,19 @@ } } - 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. }
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -327,7 +327,6 @@ 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 @@ 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( Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -266,20 +266,19 @@ } } - 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. }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits