qmlls: put import warnings on the correct line

In qmllint, the import warnings are printed right after the "warnings
occurred while importing" warning despite them having no sourcelocation.

This warning gets a default sourcelocation when used in qmlls which
points to the first line of the file, so the "Failed to import" warning
ends up an the first line of a file, and not on the same line as the
"warnings occurred while importing" warning. This is confusing for users.

Modify a test to expect that the "Failed to import" warning has a valid
sourcelocation, so that it is shown on the correct line in qmlls.

Fixes: QTBUG-131958
Pick-to: 6.8 6.9
Change-Id: Ia0c327b82e89cd0a003d05b4c3efe693fb3b3ed7
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Sami Shalayel 2024-12-05 10:02:29 +01:00
parent dfccd0d628
commit 7188ee3513
4 changed files with 7 additions and 5 deletions

View File

@ -415,7 +415,7 @@ void QQmlJSImportVisitor::processImportWarnings(
m_logger->log(QStringLiteral("Warnings occurred while importing %1:").arg(what), qmlImport,
srcLocation);
m_logger->processMessages(warnings, qmlImport);
m_logger->processMessages(warnings, qmlImport, srcLocation);
}
void QQmlJSImportVisitor::importBaseModules()

View File

@ -288,7 +288,8 @@ void QQmlJSLogger::log(const QString &message, QQmlJS::LoggerWarningId id,
}
void QQmlJSLogger::processMessages(const QList<QQmlJS::DiagnosticMessage> &messages,
QQmlJS::LoggerWarningId id)
QQmlJS::LoggerWarningId id,
const QQmlJS::SourceLocation &sourceLocation)
{
if (messages.isEmpty() || isCategoryIgnored(id))
return;
@ -298,7 +299,7 @@ void QQmlJSLogger::processMessages(const QList<QQmlJS::DiagnosticMessage> &messa
// TODO: we should instead respect message's category here (potentially, it
// should hold a category instead of type)
for (const QQmlJS::DiagnosticMessage &message : messages)
log(message.message, id, QQmlJS::SourceLocation(), false, false);
log(message.message, id, sourceLocation, false, false);
m_output.write(QStringLiteral("---\n\n"));
}

View File

@ -182,7 +182,8 @@ public:
}
void processMessages(const QList<QQmlJS::DiagnosticMessage> &messages,
const QQmlJS::LoggerWarningId id);
const QQmlJS::LoggerWarningId id,
const QQmlJS::SourceLocation &sourceLocation = QQmlJS::SourceLocation{});
void ignoreWarnings(uint32_t line, const QSet<QString> &categories)
{

View File

@ -796,7 +796,7 @@ void TestQmllint::dirtyQmlCode_data()
QTest::newRow("InvalidImport")
<< QStringLiteral("invalidImport.qml")
<< Result { { Message { QStringLiteral(
"Failed to import FooBar. Are your import paths set up properly?") } } };
"Failed to import FooBar. Are your import paths set up properly?"), 2, 1 } } };
QTest::newRow("Unused Import (simple)")
<< QStringLiteral("unused_simple.qml")
<< Result { { Message { QStringLiteral("Unused import"), 1, 1, QtInfoMsg } },