forked from qt-creator/qt-creator
ClangCodeModel: Adapt clangd tooltip test for include directives
This feature was recently added upstream (https://reviews.llvm.org/D107137). Change-Id: I022855cd5d69230b755cdd657c5a7df2db5508ce Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -1370,12 +1370,13 @@ void ClangdClient::findLocalUsages(TextEditor::TextDocument *document, const QTe
|
||||
void ClangdClient::gatherHelpItemForTooltip(const HoverRequest::Response &hoverResponse,
|
||||
const DocumentUri &uri)
|
||||
{
|
||||
// Macros aren't locatable via the AST, so parse the formatted string.
|
||||
if (const Utils::optional<Hover> result = hoverResponse.result()) {
|
||||
const HoverContent content = result->content();
|
||||
const MarkupContent * const markup = Utils::get_if<MarkupContent>(&content);
|
||||
if (markup) {
|
||||
const QString markupString = markup->content();
|
||||
|
||||
// Macros aren't locatable via the AST, so parse the formatted string.
|
||||
static const QString magicMacroPrefix = "### macro `";
|
||||
if (markupString.startsWith(magicMacroPrefix)) {
|
||||
const int nameStart = magicMacroPrefix.length();
|
||||
@@ -1387,6 +1388,19 @@ void ClangdClient::gatherHelpItemForTooltip(const HoverRequest::Response &hoverR
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Is it the file path for an include directive?
|
||||
QString cleanString = markupString;
|
||||
cleanString.remove('`');
|
||||
const QStringList lines = cleanString.trimmed().split('\n');
|
||||
if (!lines.isEmpty()) {
|
||||
const auto filePath = Utils::FilePath::fromUserInput(lines.last().simplified());
|
||||
if (filePath.exists()) {
|
||||
d->setHelpItemForTooltip(hoverResponse.id(), filePath.fileName(),
|
||||
HelpItem::Brief);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -604,8 +604,10 @@ void ClangdTestTooltips::test()
|
||||
QCOMPARE(editor->document(), doc);
|
||||
QVERIFY(editor->editorWidget());
|
||||
|
||||
if (QLatin1String(QTest::currentDataTag()) == QLatin1String("IncludeDirective"))
|
||||
if (client()->versionNumber() < QVersionNumber(14)
|
||||
&& QLatin1String(QTest::currentDataTag()) == QLatin1String("IncludeDirective")) {
|
||||
QSKIP("FIXME: clangd sends empty or no hover data for includes");
|
||||
}
|
||||
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
@@ -631,7 +633,6 @@ void ClangdTestTooltips::test()
|
||||
QEXPECT_FAIL("TypeName_ResolveTemplateTypeAlias", "typedef already resolved in AST", Abort);
|
||||
QCOMPARE(int(helpItem.category()), expectedCategory);
|
||||
QEXPECT_FAIL("TemplateClassQualified", "Additional look-up needed?", Abort);
|
||||
QEXPECT_FAIL("AutoTypeTemplate", "Additional look-up needed?", Abort);
|
||||
QCOMPARE(helpItem.helpIds(), expectedIds);
|
||||
QCOMPARE(helpItem.docMark(), expectedMark);
|
||||
}
|
||||
|
@@ -43,5 +43,6 @@
|
||||
<file>tooltips/tooltips.pro</file>
|
||||
<file>highlighting/highlighting.cpp</file>
|
||||
<file>highlighting/highlighting.pro</file>
|
||||
<file>tooltips/subdir/tooltipinfo.h</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -0,0 +1,3 @@
|
||||
#define MACRO_FROM_HEADER(x) x + \
|
||||
x + \
|
||||
x
|
@@ -1,3 +1,4 @@
|
||||
TEMPLATE = app
|
||||
CONFIG -= qt
|
||||
SOURCES = tooltips.cpp
|
||||
INCLUDEPATH += subdir
|
||||
|
Reference in New Issue
Block a user