diff options
| -rw-r--r-- | src/qmlls/qqmllsutils.cpp | 41 | ||||
| -rw-r--r-- | src/qmlls/qqmllsutils_p.h | 1 | ||||
| -rw-r--r-- | tests/auto/qmlls/utils/tst_qmlls_utils.cpp | 150 | ||||
| -rw-r--r-- | tests/auto/qmlls/utils/tst_qmlls_utils.h | 3 |
4 files changed, 0 insertions, 195 deletions
diff --git a/src/qmlls/qqmllsutils.cpp b/src/qmlls/qqmllsutils.cpp index 07cd44db22..a1ed83ae05 100644 --- a/src/qmlls/qqmllsutils.cpp +++ b/src/qmlls/qqmllsutils.cpp @@ -391,47 +391,6 @@ QList<ItemLocation> itemsFromTextLocation(const DomItem &file, int line, int cha return filtered; } -DomItem baseObject(const DomItem &object) -{ - DomItem prototypes; - DomItem qmlObject = object.qmlObject(); - // object is (or is inside) an inline component definition - if (object.internalKind() == DomType::QmlComponent || !qmlObject) { - prototypes = object.component() - .field(Fields::objects) - .index(0) - .field(QQmlJS::Dom::Fields::prototypes); - } else { - // object is (or is inside) a QmlObject - prototypes = qmlObject.field(QQmlJS::Dom::Fields::prototypes); - } - switch (prototypes.indexes()) { - case 0: - return {}; - case 1: - break; - default: - qDebug() << "Multiple prototypes found for " << object.name() << ", taking the first one."; - break; - } - QQmlJS::Dom::DomItem base = prototypes.index(0).proceedToScope(); - return base; -} - -static std::optional<Location> locationFromDomItem(const DomItem &item, FileLocationRegion region) -{ - auto tree = FileLocations::treeOf(item); - // tree is null for C++ defined types, for example - if (!tree) - return {}; - - QQmlJS::SourceLocation sourceLocation = FileLocations::region(tree, region); - if (!sourceLocation.isValid() && region != QQmlJS::Dom::MainRegion) - sourceLocation = FileLocations::region(tree, QQmlJS::Dom::MainRegion); - - return Location::tryFrom(item.canonicalFilePath(), sourceLocation, item); -} - /*! \internal \brief Returns the location of the type definition pointed by object. diff --git a/src/qmlls/qqmllsutils_p.h b/src/qmlls/qqmllsutils_p.h index bef8016c4f..508ea248a4 100644 --- a/src/qmlls/qqmllsutils_p.h +++ b/src/qmlls/qqmllsutils_p.h @@ -265,7 +265,6 @@ DomItem sourceLocationToDomItem(const DomItem &file, const QQmlJS::SourceLocatio QByteArray lspUriToQmlUrl(const QByteArray &uri); QByteArray qmlUrlToLspUri(const QByteArray &url); QLspSpecification::Range qmlLocationToLspLocation(Location qmlLocation); -DomItem baseObject(const DomItem &qmlObject); std::optional<Location> findTypeDefinitionOf(const DomItem &item); QList<Location> findDefinitionOf(const DomItem &item, const QStringList &headerDirectories); Usages findUsagesOf(const DomItem &item); diff --git a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp index dc2bb58d3f..13345afd5e 100644 --- a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp +++ b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp @@ -21,12 +21,6 @@ const static int outOfTwo = 2; // enable/disable additional debug output constexpr static bool enable_debug_output = true; -static QString printSet(const QSet<QString> &s) -{ - const QString r = QStringList(s.begin(), s.end()).join(u", "_s); - return r; -} - static QString readFileContent(const QString &testFileName) { QFile file(testFileName); if (file.open(QIODeviceBase::ReadOnly)) @@ -526,150 +520,6 @@ void tst_qmlls_utils::findLocationOfItem() QCOMPARE(t->info().fullRegion.startColumn, quint32(expectedCharacter)); } -void tst_qmlls_utils::findBaseObject_data() -{ - QTest::addColumn<QString>("filePath"); - QTest::addColumn<int>("line"); - QTest::addColumn<int>("character"); - // to avoid mixing up the types (because they are all called Item or QQuickItem eitherway) - // mark them with properties and detect right types by their marker property, - // usually called (in<Filename>DotQml or in<Inline component Name>) - QTest::addColumn<QSet<QString>>("expectedPropertyName"); - // because types inherit properties, make sure that derived type properties are not in the base - // type, to correctly detect mixups between types and their base types - QTest::addColumn<QSet<QString>>("unExpectedPropertyName"); - - // (non) Expected Properties Names = ePN (nEPN) - // marker properties for the root object in BaseType.qml - QSet<QString> ePNBaseType; - ePNBaseType << u"inBaseTypeDotQml"_s; - QSet<QString> nEPNBaseType; - nEPNBaseType << u"inTypeDotQml"_s; - - // marker properties for the root object in Type.qml - QSet<QString> ePNType; - ePNType << u"inBaseTypeDotQml"_s << u"inTypeDotQml"_s; - QSet<QString> nEPNType; - - // marker properties for QQuickItem (e.g. the base of "Item") - QSet<QString> ePNQQuickItem; - QSet<QString> nEPNQQuickItem; - nEPNQQuickItem << u"inBaseTypeDotQml"_s << u"inTypeDotQml"_s; - - // marker properties for MyInlineComponent - QSet<QString> ePNMyInlineComponent; - QSet<QString> nEPNMyInlineComponent; - ePNMyInlineComponent << u"inBaseTypeDotQml"_s << u"inTypeDotQml"_s << u"inMyInlineComponent"_s; - - // marker properties for MyNestedInlineComponent - const QSet<QString> ePNMyNestedInlineComponent{ u"inMyNestedInlineComponent"_s }; - const QSet<QString> nEPNMyNestedInlineComponent{ u"inBaseTypeDotQml"_s, u"inTypeDotQml"_s, - u"inMyInlineComponent"_s }; - - // marker properties for MyBaseInlineComponent - const QSet<QString> ePNMyBaseInlineComponent{ u"inBaseTypeDotQml"_s }; - const QSet<QString> nEPNMyBaseInlineComponent{ u"inTypeDotQml"_s, u"inMyInlineComponent"_s }; - - const int rootElementDefLine = 6; - QTest::addRow("root-element") << testFile(u"Type.qml"_s) << rootElementDefLine << 5 - << ePNQQuickItem << nEPNQQuickItem; - QTest::addRow("root-element-from-id") << testFile(u"Type.qml"_s) << rootElementDefLine + 1 << 12 - << ePNBaseType << nEPNBaseType; - - const int myInlineComponentDefLine = 10; - // on the component name: go to BaseType - QTest::addRow("ic-name") << testFile(u"Type.qml"_s) << myInlineComponentDefLine << 26 - << ePNBaseType << nEPNBaseType; - // on the "BaseType" type: go to QQuickitem (base type of BaseType). - QTest::addRow("ic-basetypename") << testFile(u"Type.qml"_s) << myInlineComponentDefLine << 37 - << ePNQQuickItem << nEPNQQuickItem; - QTest::addRow("ic-from-id") << testFile(u"Type.qml"_s) << myInlineComponentDefLine + 1 << 19 - << ePNBaseType << nEPNBaseType; - - const int inlineTypeDefLine = 15; - QTest::addRow("inline") << testFile(u"Type.qml"_s) << inlineTypeDefLine << 23 << ePNQQuickItem - << nEPNQQuickItem; - QTest::addRow("inline2") << testFile(u"Type.qml"_s) << inlineTypeDefLine << 38 << ePNQQuickItem - << nEPNQQuickItem; - QTest::addRow("inline3") << testFile(u"Type.qml"_s) << inlineTypeDefLine << 15 << ePNQQuickItem - << nEPNQQuickItem; - QTest::addRow("inline-from-id") << testFile(u"Type.qml"_s) << inlineTypeDefLine + 1 << 24 - << ePNBaseType << nEPNBaseType; - - const int inlineIcDefLine = 23; - QTest::addRow("inline-ic") << testFile(u"Type.qml"_s) << inlineIcDefLine << 38 - << ePNMyBaseInlineComponent << nEPNMyBaseInlineComponent; - QTest::addRow("inline-ic-from-id") << testFile(u"Type.qml"_s) << inlineIcDefLine + 1 << 28 - << ePNMyBaseInlineComponent << nEPNMyBaseInlineComponent; - - const int inlineNestedIcDefLine = 27; - QTest::addRow("inline-ic2") << testFile(u"Type.qml"_s) << inlineNestedIcDefLine << 46 - << ePNMyNestedInlineComponent << nEPNMyNestedInlineComponent; - QTest::addRow("inline-ic2-from-id") - << testFile(u"Type.qml"_s) << inlineNestedIcDefLine + 1 << 23 - << ePNMyNestedInlineComponent << nEPNMyNestedInlineComponent; -} - -void tst_qmlls_utils::findBaseObject() -{ - const QByteArray failOnInlineComponentsMessage = - "The Dom cannot resolve inline components from the basetype yet."; - - QFETCH(QString, filePath); - QFETCH(int, line); - QFETCH(int, character); - QFETCH(QSet<QString>, expectedPropertyName); - QFETCH(QSet<QString>, unExpectedPropertyName); - - // they all start at 1. - Q_ASSERT(line > 0); - Q_ASSERT(character > 0); - - auto [env, file] = createEnvironmentAndLoadFile(filePath); - - // grab item using already tested QQmlLSUtils::findLastItemsContaining - auto locations = QQmlLSUtils::itemsFromTextLocation( - file.field(QQmlJS::Dom::Fields::currentItem), line - 1, character - 1); - if constexpr (enable_debug_output) { - if (locations.size() > 1) { - for (auto &x : locations) - qDebug() << x.domItem.toString(); - } - } - QCOMPARE(locations.size(), 1); - - auto typeLocation = QQmlLSUtils::findTypeDefinitionOf(locations.front().domItem); - QEXPECT_FAIL("inline-ic", failOnInlineComponentsMessage, Abort); - QEXPECT_FAIL("inline-ic2", failOnInlineComponentsMessage, Abort); - QVERIFY(typeLocation); - QQmlJS::Dom::DomItem type = QQmlLSUtils::sourceLocationToDomItem( - locations.front().domItem.goToFile(typeLocation->filename()), - typeLocation->sourceLocation()); - auto base = QQmlLSUtils::baseObject(type); - - if constexpr (enable_debug_output) { - if (!base) - qDebug() << u"Could not find the base of type "_s << type << u" from item:\n"_s - << locations.front().domItem.toString(); - } - - QEXPECT_FAIL("inline-ic-from-id", failOnInlineComponentsMessage, Abort); - QEXPECT_FAIL("inline-ic2-from-id", failOnInlineComponentsMessage, Abort); - QVERIFY(base); - - const QSet<QString> propertyDefs = base.field(QQmlJS::Dom::Fields::propertyDefs).keys(); - expectedPropertyName.subtract(propertyDefs); - QVERIFY2(expectedPropertyName.empty(), - u"Incorrect baseType found: it is missing following marker properties: "_s - .append(printSet(expectedPropertyName)) - .toLatin1()); - unExpectedPropertyName.intersect(propertyDefs); - QVERIFY2(unExpectedPropertyName.empty(), - u"Incorrect baseType found: it has an unexpected marker properties: "_s - .append(printSet(unExpectedPropertyName)) - .toLatin1()); -} - /*! \internal \brief Wrapper for findUsages data. */ diff --git a/tests/auto/qmlls/utils/tst_qmlls_utils.h b/tests/auto/qmlls/utils/tst_qmlls_utils.h index 65b432453b..498722fac9 100644 --- a/tests/auto/qmlls/utils/tst_qmlls_utils.h +++ b/tests/auto/qmlls/utils/tst_qmlls_utils.h @@ -64,9 +64,6 @@ private slots: void findLocationOfItem_data(); void findLocationOfItem(); - void findBaseObject(); - void findBaseObject_data(); - void findUsages(); void findUsages_data(); |
