diff --git a/tests/auto/qmlls/qmlls/tst_qmlls.cpp b/tests/auto/qmlls/qmlls/tst_qmlls.cpp index ddaedb4a5a..937d191f60 100644 --- a/tests/auto/qmlls/qmlls/tst_qmlls.cpp +++ b/tests/auto/qmlls/qmlls/tst_qmlls.cpp @@ -191,9 +191,23 @@ void tst_Qmlls::didOpenTextDocument() auto list = std::get(response); - QList> expectedData = { - { QLatin1StringView("Did you mean \"width\"?"), QLatin1StringView("width") }, - { QLatin1StringView("Did you mean \"z\"?"), QLatin1StringView("z") } + struct ReplacementData + { + QString replacement; + Range range; + }; + + QHash expectedData = { + { QLatin1StringView("Did you mean \"width\"?"), + { QLatin1StringView("width"), + Range { Position { 3, 4 }, Position { 3, 10 } } } }, + { QLatin1StringView("Did you mean \"z\"?"), + { QLatin1StringView("z"), + Range { Position { + 3, + 12, + }, + Position { 3, 15 } } } } }; QCOMPARE(list.size(), expectedData.size()); @@ -222,14 +236,18 @@ void tst_Qmlls::didOpenTextDocument() QVERIFY(std::holds_alternative(editVariant)); TextEdit textEdit = std::get(editVariant); - QString newText = QString::fromUtf8(textEdit.newText); - QPair data = { title, newText }; + QString replacement = QString::fromUtf8(textEdit.newText); + const Range &range = textEdit.range; - qsizetype dataIndex = expectedData.indexOf(data); - QVERIFY2(dataIndex != -1, - qPrintable(QLatin1String("{\"%1\",\"%2\"}").arg(title, newText))); + QVERIFY2(expectedData.contains(title), + qPrintable(QLatin1String("Unexpected fix \"%1\"").arg(title))); + QCOMPARE(replacement, expectedData[title].replacement); + QCOMPARE(range.start.line, expectedData[title].range.start.line); + QCOMPARE(range.start.character, expectedData[title].range.start.character); + QCOMPARE(range.end.line, expectedData[title].range.end.line); + QCOMPARE(range.end.character, expectedData[title].range.end.character); // Make sure every expected entry only occurs once - expectedData.remove(dataIndex); + expectedData.remove(title); } success = true; diff --git a/tools/qmlls/qmllintsuggestions.cpp b/tools/qmlls/qmllintsuggestions.cpp index 471d6fc816..c26f154a47 100644 --- a/tools/qmlls/qmllintsuggestions.cpp +++ b/tools/qmlls/qmllintsuggestions.cpp @@ -221,8 +221,8 @@ void QmlLintSuggestions::diagnose(const QByteArray &uri) for (const FixSuggestion::Fix &fix : suggestion->fixes) { QQmlJS::SourceLocation cut = fix.cutLocation; - int line = cut.isValid() ? cut.startLine : 0; - int column = cut.isValid() ? cut.startColumn : 0; + int line = cut.isValid() ? cut.startLine - 1 : 0; + int column = cut.isValid() ? cut.startColumn - 1 : 0; QJsonObject object; object[u"lspBeginLine"] = line; @@ -230,8 +230,8 @@ void QmlLintSuggestions::diagnose(const QByteArray &uri) Position end = { line, column }; - addLength(end, srcLoc.isValid() ? srcLoc.offset : 0, - srcLoc.isValid() ? srcLoc.length : 0); + addLength(end, srcLoc.isValid() ? cut.offset : 0, + srcLoc.isValid() ? cut.length : 0); object[u"lspEndLine"] = end.line; object[u"lspEndCharacter"] = end.character;