ClangCodeModel: Add test case for documentation in cpp files

See https://github.com/llvm/llvm-project/pull/67802.

Task-number: QTCREATORBUG-4557
Change-Id: I1b7135414104d67426eefded679a03fdaa306944
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2024-02-05 12:35:37 +01:00
parent 62f47adea2
commit 6911ae7b02
9 changed files with 67 additions and 8 deletions

View File

@@ -1507,10 +1507,9 @@ void ClangdClient::Private::setHelpItemForTooltip(const MessageId &token,
mark = type;
const HelpItem helpItem(helpIds, filePath, mark, category);
if (isTesting)
emit q->helpItemGathered(helpItem);
else
q->hoverHandler()->setHelpItem(token, helpItem);
if (isTesting)
emit q->helpItemGathered(helpItem, q->hoverHandler()->toolTip());
}
// Unfortunately, clangd ignores almost everything except symbols when sending

View File

@@ -127,7 +127,7 @@ signals:
void indexingFinished();
void foundReferences(const Utils::SearchResultItems &items);
void findUsagesDone();
void helpItemGathered(const Core::HelpItem &helpItem);
void helpItemGathered(const Core::HelpItem &helpItem, const QString &toolTip);
void highlightingResultsReady(const TextEditor::HighlightingResults &results,
const Utils::FilePath &file);
void proposalReady(TextEditor::IAssistProposal *proposal);

View File

@@ -670,14 +670,55 @@ public:
ClangdTestTooltips()
{
setProjectFileName("tooltips.pro");
setSourceFileNames({"tooltips.cpp"});
setSourceFileNames({"main.cpp", "tooltips.cpp"});
}
private slots:
void testTooltipFromIndex();
void test_data();
void test();
};
void ClangdTestTooltips::testTooltipFromIndex()
{
TextEditor::TextDocument * const doc = document("main.cpp");
QVERIFY(doc);
const auto editor = qobject_cast<BaseTextEditor *>(EditorManager::openEditor(doc->filePath()));
QVERIFY(editor);
QCOMPARE(editor->document(), doc);
QVERIFY(editor->editorWidget());
QTimer timer;
timer.setSingleShot(true);
QEventLoop loop;
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
HelpItem helpItem;
QString tooltip;
const auto handler = [&helpItem, &tooltip, &loop](const HelpItem &h, const QString &t) {
helpItem = h;
tooltip = t;
loop.quit();
};
connect(client(), &ClangdClient::helpItemGathered, &loop, handler);
QTextCursor cursor(doc->document());
const int pos = Text::positionInText(doc->document(), 5, 5);
cursor.setPosition(pos);
editor->editorWidget()->processTooltipRequest(cursor);
timer.start(10000);
loop.exec();
QVERIFY(timer.isActive());
timer.stop();
QCOMPARE(int(helpItem.category()), HelpItem::Function);
QCOMPARE(helpItem.helpIds(), {"funcWithDocInside"});
if (client()->versionNumber().majorVersion() < 20)
QEXPECT_FAIL(nullptr, "Requires clangd >= 20", Continue);
QVERIFY2(tooltip.contains("Documentation in source file"), qPrintable(tooltip));
}
void ClangdTestTooltips::test_data()
{
QTest::addColumn<int>("line");
@@ -772,7 +813,7 @@ void ClangdTestTooltips::test()
TextEditor::TextDocument * const doc = document("tooltips.cpp");
QVERIFY(doc);
const auto editor = TextEditor::BaseTextEditor::currentTextEditor();
const auto editor = qobject_cast<BaseTextEditor *>(EditorManager::openEditor(doc->filePath()));
QVERIFY(editor);
QCOMPARE(editor->document(), doc);
QVERIFY(editor->editorWidget());

View File

@@ -64,5 +64,8 @@
<file>indirect-changes/indirectheader.h</file>
<file>indirect-changes/main.cpp</file>
<file>indirect-changes/unrelatedheader.h</file>
<file>tooltips/main.cpp</file>
<file>tooltips/tooltipfromindex.cpp</file>
<file>tooltips/tooltipfromindex.h</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,6 @@
#include "tooltipfromindex.h"
int main()
{
funcWithDocInside();
}

View File

@@ -0,0 +1,6 @@
#include "tooltipfromindex.h"
// Documentation in source file
void funcWithDocInside()
{
}

View File

@@ -0,0 +1,3 @@
#pragma one
void funcWithDocInside();

View File

@@ -1,4 +1,5 @@
TEMPLATE = app
CONFIG -= qt
SOURCES = tooltips.cpp
HEADERS = tooltipfromindex.h
SOURCES = main.cpp tooltipfromindex.cpp tooltips.cpp
INCLUDEPATH += subdir

View File

@@ -33,6 +33,7 @@ public:
void showToolTip(TextEditorWidget *widget, const QPoint &point);
bool lastHelpItemAppliesTo(const TextEditorWidget *widget) const;
const QString &toolTip() const;
protected:
enum {
@@ -46,7 +47,6 @@ protected:
int priority() const;
void setToolTip(const QString &tooltip, Qt::TextFormat format = Qt::PlainText);
const QString &toolTip() const;
void setLastHelpItemIdentified(const Core::HelpItem &help);
const Core::HelpItem &lastHelpItemIdentified() const;