forked from qt-creator/qt-creator
Clang: Fix tooltips for constructors
Constructors were not handled yet, so the tooltip for e.g. the "QString()" constructor was "void ()". Also, since the help system has problems with overloads, show the function signature as clang sees it and provide a help system query that will show the documentation for the class instead of the wrong overload. Change-Id: Idc0cf9dce6a50c323e6fd945f277c7816b0f9b34 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -237,7 +237,7 @@ Utf8String ToolTipInfoCollector::text(const Cursor &cursor, const Cursor &refere
|
||||
if (referenced.isAnyTypeAlias())
|
||||
return textForAnyTypeAlias(referenced);
|
||||
|
||||
if (referenced.isFunctionLike())
|
||||
if (referenced.isFunctionLike() || referenced.kind() == CXCursor_Constructor)
|
||||
return textForFunctionLike(referenced);
|
||||
|
||||
if (referenced.type().canonical().isBuiltinType())
|
||||
@@ -412,6 +412,14 @@ ToolTipInfo ToolTipInfoCollector::qDocInfo(const Cursor &cursor) const
|
||||
if (isBuiltinOrPointerToBuiltin(cursor.type()))
|
||||
return result;
|
||||
|
||||
if (cursor.kind() == CXCursor_Constructor) {
|
||||
const ToolTipInfo parentInfo = qDocInfo(cursor.semanticParent());
|
||||
result.setQdocIdCandidates(parentInfo.qdocIdCandidates());
|
||||
result.setQdocMark(parentInfo.qdocMark());
|
||||
result.setQdocCategory(ToolTipInfo::Unknown);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.setQdocIdCandidates(qDocIdCandidates(cursor));
|
||||
result.setQdocMark(qdocMark(cursor));
|
||||
result.setQdocCategory(qdocCategory(cursor));
|
||||
|
@@ -614,6 +614,48 @@ TEST_F(ToolTipInfo, AutoTypeClassTemplateType)
|
||||
ASSERT_THAT(actual.text(), Utf8StringLiteral("Zii<int>"));
|
||||
}
|
||||
|
||||
TEST_F(ToolTipInfo, DISABLED_WITHOUT_PRETTYDECL_PATCH(Function_DefaultConstructor))
|
||||
{
|
||||
const ::ToolTipInfo actual = tooltip(193, 5);
|
||||
|
||||
ASSERT_THAT(actual.text(), Utf8StringLiteral("inline constexpr Con::Con() noexcept"));
|
||||
}
|
||||
|
||||
TEST_F(ToolTipInfo, DISABLED_WITHOUT_PRETTYDECL_PATCH(Function_ExplicitDefaultConstructor))
|
||||
{
|
||||
const ::ToolTipInfo actual = tooltip(194, 5);
|
||||
|
||||
ASSERT_THAT(actual.text(), Utf8StringLiteral("ExplicitCon::ExplicitCon() noexcept = default"));
|
||||
}
|
||||
|
||||
TEST_F(ToolTipInfo, DISABLED_WITHOUT_PRETTYDECL_PATCH(Function_CustomConstructor))
|
||||
{
|
||||
const ::ToolTipInfo actual = tooltip(195, 5);
|
||||
|
||||
ASSERT_THAT(actual.text(), Utf8StringLiteral("ExplicitCon::ExplicitCon(int m)"));
|
||||
}
|
||||
|
||||
// Overloads are problematic for the help system since the data base has not
|
||||
// enough information about them. At least for constructors we can improve
|
||||
// the situation a bit - provide a help system query that:
|
||||
// 1) will not lead to the replacement of the constructor signature as
|
||||
// clang sees it with the wrong overload documentation
|
||||
// (signature + main help sentence). That's the qdocCategory=Unknown
|
||||
// part.
|
||||
// 2) finds the documentation for the class instead of the overload,
|
||||
// so F1 will go to the class documentation.
|
||||
TEST_F(ToolTipInfo, Function_ConstructorQDoc)
|
||||
{
|
||||
::ToolTipInfo expected;
|
||||
expected.setQdocIdCandidates({Utf8StringLiteral("Con")});
|
||||
expected.setQdocMark(Utf8StringLiteral("Con"));
|
||||
expected.setQdocCategory(::ToolTipInfo::Unknown);
|
||||
|
||||
const ::ToolTipInfo actual = tooltip(193, 5);
|
||||
|
||||
ASSERT_THAT(actual, IsQdocToolTip(expected));
|
||||
}
|
||||
|
||||
std::unique_ptr<Data> ToolTipInfo::d;
|
||||
|
||||
void ToolTipInfo::SetUpTestCase()
|
||||
|
@@ -178,3 +178,19 @@ void autoTypes()
|
||||
auto c = Bar(); (void)c;
|
||||
auto d = Zii<int>(); (void)d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
struct Con {};
|
||||
struct ExplicitCon {
|
||||
ExplicitCon() = default;
|
||||
ExplicitCon(int m) :member(m) {}
|
||||
int member;
|
||||
};
|
||||
void constructor()
|
||||
{
|
||||
Con();
|
||||
ExplicitCon();
|
||||
ExplicitCon(2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user