diff --git a/src/tools/clangbackend/source/clangtooltipinfocollector.cpp b/src/tools/clangbackend/source/clangtooltipinfocollector.cpp index 44dde1edbbc..c9b70350a41 100644 --- a/src/tools/clangbackend/source/clangtooltipinfocollector.cpp +++ b/src/tools/clangbackend/source/clangtooltipinfocollector.cpp @@ -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)); diff --git a/tests/unit/unittest/clangtooltipinfo-test.cpp b/tests/unit/unittest/clangtooltipinfo-test.cpp index acaa3e18d73..c796932092a 100644 --- a/tests/unit/unittest/clangtooltipinfo-test.cpp +++ b/tests/unit/unittest/clangtooltipinfo-test.cpp @@ -614,6 +614,48 @@ TEST_F(ToolTipInfo, AutoTypeClassTemplateType) ASSERT_THAT(actual.text(), Utf8StringLiteral("Zii")); } +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 ToolTipInfo::d; void ToolTipInfo::SetUpTestCase() diff --git a/tests/unit/unittest/data/tooltipinfo.cpp b/tests/unit/unittest/data/tooltipinfo.cpp index 1945577b635..266d86bc47c 100644 --- a/tests/unit/unittest/data/tooltipinfo.cpp +++ b/tests/unit/unittest/data/tooltipinfo.cpp @@ -178,3 +178,19 @@ void autoTypes() auto c = Bar(); (void)c; auto d = Zii(); (void)d; } + + + + +struct Con {}; +struct ExplicitCon { + ExplicitCon() = default; + ExplicitCon(int m) :member(m) {} + int member; +}; +void constructor() +{ + Con(); + ExplicitCon(); + ExplicitCon(2); +}