aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2024-08-27 15:54:25 +0200
committerSami Shalayel <sami.shalayel@qt.io>2024-09-05 11:43:50 +0200
commit8d874a1b3ca3f5f6db48a526ca62215464f97ef5 (patch)
tree883b70192eceae680fbc3e14839149a0ce4dce67
parentbc7e41124afc31eac0dabfe0aaa9165c9a5dfaa5 (diff)
qmlls: move Location computation logic to utils
It turns out that QQmlJSUtils::Location is missing an end location which is actually needed by the LSP. The qmlls modules worked around that by manually creating the end location from the source code, which is hard to test, mainly untested and buggy. In this case, qqmllsutils would return a correct Location, and the qmlls modules would fail on loading the qmlfile to get the missing position information while trying to convey the Location to the LSP layer. Therefore, extend Location to actually contain the end position and move the end position computations to qqmllsutils which has much better test coverage because it is way easier to test. Extend the Location computation logic by adding a TextPosition field in QQmlJSUtils::Location and adding adequate static from() and tryFrom() construction methods in Location. Make the fields private and add some getters to avoid the newly added field from being forgotten. This is needed for QTBUG-127661 because you can't retrieve the qml file code from the DomItem if the filepath points to the source folder instead of the build folder, except if you happened to open the build folder file in your editor. Pick-to: 6.7 6.8 Task-number: QTBUG-127661 Change-Id: Id2ff400feeebeb90da6cfeadbd81260ac99ce46a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qmlls/qqmlfindusagessupport.cpp21
-rw-r--r--src/qmlls/qqmlgotodefinitionsupport.cpp12
-rw-r--r--src/qmlls/qqmlgototypedefinitionsupport.cpp13
-rw-r--r--src/qmlls/qqmllsutils.cpp121
-rw-r--r--src/qmlls/qqmllsutils_p.h38
-rw-r--r--src/qmlls/qqmlrenamesymbolsupport.cpp26
-rw-r--r--tests/auto/qmlls/utils/tst_qmlls_utils.cpp54
7 files changed, 125 insertions, 160 deletions
diff --git a/src/qmlls/qqmlfindusagessupport.cpp b/src/qmlls/qqmlfindusagessupport.cpp
index dc407f71bc..4ec712b22d 100644
--- a/src/qmlls/qqmlfindusagessupport.cpp
+++ b/src/qmlls/qqmlfindusagessupport.cpp
@@ -51,28 +51,11 @@ void QQmlFindUsagesSupport::process(QQmlFindUsagesSupport::RequestPointerArgumen
QQmlJS::Dom::DomItem files = front.domItem.top().field(QQmlJS::Dom::Fields::qmlFileWithPath);
- QHash<QString, QString> codeCache;
-
// note: ignore usages in filenames here as that is not supported by the protocol.
for (const auto &usage : usages.usagesInFile()) {
QLspSpecification::Location location;
- location.uri = QUrl::fromLocalFile(usage.filename).toEncoded();
-
- auto cacheEntry = codeCache.find(usage.filename);
- if (cacheEntry == codeCache.end()) {
- auto file = files.key(usage.filename)
- .field(QQmlJS::Dom::Fields::currentItem)
- .ownerAs<QQmlJS::Dom::QmlFile>();
- if (!file) {
- qDebug() << "File" << usage.filename << "not found in DOM! Available files are"
- << files.keys();
- continue;
- }
- cacheEntry = codeCache.insert(usage.filename, file->code());
- }
-
- location.range =
- QQmlLSUtils::qmlLocationToLspLocation(cacheEntry.value(), usage.sourceLocation);
+ location.uri = QUrl::fromLocalFile(usage.filename()).toEncoded();
+ location.range = QQmlLSUtils::qmlLocationToLspLocation(usage);
results.append(location);
}
diff --git a/src/qmlls/qqmlgotodefinitionsupport.cpp b/src/qmlls/qqmlgotodefinitionsupport.cpp
index 366fbe7d09..e27f3decf2 100644
--- a/src/qmlls/qqmlgotodefinitionsupport.cpp
+++ b/src/qmlls/qqmlgotodefinitionsupport.cpp
@@ -54,16 +54,8 @@ void QmlGoToDefinitionSupport::process(RequestPointerArgument request)
return;
QLspSpecification::Location l;
- l.uri = QUrl::fromLocalFile(location->filename).toEncoded();
-
- QQmlJS::Dom::DomItem file = front.domItem.goToFile(location->filename);
- auto fileOfBasePtr = file.ownerAs<QQmlJS::Dom::QmlFile>();
- if (!fileOfBasePtr) {
- qDebug() << "Could not find file" << location->filename << "in the dom!";
- return;
- }
- const QString qmlCode = fileOfBasePtr->code();
- l.range = QQmlLSUtils::qmlLocationToLspLocation(qmlCode, location->sourceLocation);
+ l.uri = QUrl::fromLocalFile(location->filename()).toEncoded();
+ l.range = QQmlLSUtils::qmlLocationToLspLocation(*location);
results.append(l);
}
diff --git a/src/qmlls/qqmlgototypedefinitionsupport.cpp b/src/qmlls/qqmlgototypedefinitionsupport.cpp
index b29cf3b833..b6129ac524 100644
--- a/src/qmlls/qqmlgototypedefinitionsupport.cpp
+++ b/src/qmlls/qqmlgototypedefinitionsupport.cpp
@@ -55,18 +55,9 @@ void QmlGoToTypeDefinitionSupport::process(RequestPointerArgument request)
return;
}
- QQmlJS::Dom::DomItem fileOfBase = front.domItem.goToFile(base->filename);
- auto fileOfBasePtr = fileOfBase.ownerAs<QQmlJS::Dom::QmlFile>();
- if (!fileOfBasePtr) {
- qDebug() << u"Could not obtain the file of the base."_s;
- return;
- }
-
QLspSpecification::Location l;
- l.uri = QUrl::fromLocalFile(fileOfBasePtr->canonicalFilePath()).toEncoded();
-
- const QString qmlCode = fileOfBasePtr->code();
- l.range = QQmlLSUtils::qmlLocationToLspLocation(qmlCode, base->sourceLocation);
+ l.uri = QUrl::fromLocalFile(base->filename()).toEncoded();
+ l.range = QQmlLSUtils::qmlLocationToLspLocation(*base);
results.append(l);
}
diff --git a/src/qmlls/qqmllsutils.cpp b/src/qmlls/qqmllsutils.cpp
index c3d93f36ad..617262faaa 100644
--- a/src/qmlls/qqmllsutils.cpp
+++ b/src/qmlls/qqmllsutils.cpp
@@ -168,21 +168,16 @@ QByteArray qmlUrlToLspUri(const QByteArray &url)
\brief Converts a QQmlJS::SourceLocation to a LSP Range.
QQmlJS::SourceLocation starts counting lines and rows at 1, but the LSP Range starts at 0.
- Also, the QQmlJS::SourceLocation contains startLine, startColumn and length while the LSP Range
- contains startLine, startColumn, endLine and endColumn, which must be computed from the actual
- qml code.
*/
-QLspSpecification::Range qmlLocationToLspLocation(const QString &code,
- QQmlJS::SourceLocation qmlLocation)
+QLspSpecification::Range qmlLocationToLspLocation(Location qmlLocation)
{
QLspSpecification::Range range;
- range.start.line = qmlLocation.startLine - 1;
- range.start.character = qmlLocation.startColumn - 1;
+ range.start.line = qmlLocation.sourceLocation().startLine - 1;
+ range.start.character = qmlLocation.sourceLocation().startColumn - 1;
+ range.end.line = qmlLocation.end().line;
+ range.end.character = qmlLocation.end().character;
- auto end = QQmlLSUtils::textRowAndColumnFrom(code, qmlLocation.end());
- range.end.line = end.line;
- range.end.character = end.character;
return range;
}
@@ -459,18 +454,16 @@ DomItem baseObject(const DomItem &object)
static std::optional<Location> locationFromDomItem(const DomItem &item, FileLocationRegion region)
{
- Location location;
- location.filename = item.canonicalFilePath();
-
auto tree = FileLocations::treeOf(item);
// tree is null for C++ defined types, for example
if (!tree)
return {};
- location.sourceLocation = FileLocations::region(tree, region);
- if (!location.sourceLocation.isValid() && region != QQmlJS::Dom::MainRegion)
- location.sourceLocation = FileLocations::region(tree, MainRegion);
- return location;
+ 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);
}
/*!
@@ -569,8 +562,8 @@ std::optional<Location> findTypeDefinitionOf(const DomItem &object)
return {};
if (scope->type == QmlObjectIdIdentifier) {
- return Location{ scope->semanticScope->filePath(),
- scope->semanticScope->sourceLocation() };
+ return Location::tryFrom(scope->semanticScope->filePath(),
+ scope->semanticScope->sourceLocation(), object);
}
typeDefinition = sourceLocationToDomItem(object.containingFile(),
@@ -889,7 +882,7 @@ static void findUsagesOfNonJSIdentifiers(const DomItem &item, const QString &nam
const QStringList namesToCheck = namesOfPossibleUsages(name, item, expressionType->semanticScope);
const auto addLocationIfTypeMatchesTarget =
- [&result, &expressionType](const DomItem &toBeResolved, FileLocationRegion subRegion) {
+ [&result, &expressionType, &item](const DomItem &toBeResolved, FileLocationRegion subRegion) {
const auto currentType =
resolveExpressionType(toBeResolved, ResolveOptions::ResolveOwnerType);
if (!currentType)
@@ -905,8 +898,10 @@ static void findUsagesOfNonJSIdentifiers(const DomItem &item, const QString &nam
if (!sourceLocation.isValid())
return;
- Location location{ toBeResolved.canonicalFilePath(), sourceLocation };
- result.appendUsage(location);
+ if (auto location = Location::tryFrom(toBeResolved.canonicalFilePath(),
+ sourceLocation, item)) {
+ result.appendUsage(*location);
+ }
}
};
@@ -983,19 +978,18 @@ static void findUsagesOfNonJSIdentifiers(const DomItem &item, const QString &nam
}
}
-static Location locationFromJSIdentifierDefinition(const DomItem &definitionOfItem,
- const QString &name)
+static std::optional<Location> locationFromJSIdentifierDefinition(const DomItem &definitionOfItem,
+ const QString &name)
{
Q_ASSERT_X(!definitionOfItem.semanticScope().isNull()
&& definitionOfItem.semanticScope()->ownJSIdentifier(name).has_value(),
"QQmlLSUtils::locationFromJSIdentifierDefinition",
"JS definition does not actually define the JS identifier. "
"Did you obtain definitionOfItem from findJSIdentifierDefinition() ?");
- QQmlJS::SourceLocation location =
+ const QQmlJS::SourceLocation location =
definitionOfItem.semanticScope()->ownJSIdentifier(name).value().location;
- Location result = { definitionOfItem.canonicalFilePath(), location };
- return result;
+ return Location::tryFrom(definitionOfItem.canonicalFilePath(), location, definitionOfItem);
}
static void findUsagesHelper(const DomItem &item, const QString &name, Usages &result)
@@ -1022,9 +1016,10 @@ static void findUsagesHelper(const DomItem &item, const QString &name, Usages &r
qCWarning(QQmlLSUtilsLog) << "Failed finding filelocation of found usage";
return true;
}
- const QQmlJS::SourceLocation location = fileLocation->info().fullRegion;
+ const QQmlJS::SourceLocation sourceLocation = fileLocation->info().fullRegion;
const QString fileName = item.canonicalFilePath();
- result.appendUsage({ fileName, location });
+ if (auto location = Location::tryFrom(fileName, sourceLocation, item))
+ result.appendUsage(*location);
return true;
}
QQmlJSScope::ConstPtr scope = item.semanticScope();
@@ -1041,8 +1036,8 @@ static void findUsagesHelper(const DomItem &item, const QString &name, Usages &r
},
emptyChildrenVisitor, filterForFindUsages());
- const Location definition = locationFromJSIdentifierDefinition(definitionOfItem, name);
- result.appendUsage(definition);
+ if (const auto definition = locationFromJSIdentifierDefinition(definitionOfItem, name))
+ result.appendUsage(*definition);
}
Usages findUsagesOf(const DomItem &item)
@@ -1090,9 +1085,9 @@ Usages findUsagesOf(const DomItem &item)
if (QQmlLSUtilsLog().isDebugEnabled()) {
qCDebug(QQmlLSUtilsLog) << "Found following usages in files:";
for (auto r : result.usagesInFile()) {
- qCDebug(QQmlLSUtilsLog)
- << r.filename << " @ " << r.sourceLocation.startLine << ":"
- << r.sourceLocation.startColumn << " with length " << r.sourceLocation.length;
+ qCDebug(QQmlLSUtilsLog) << r.filename() << " @ " << r.sourceLocation().startLine << ":"
+ << r.sourceLocation().startColumn << " with length "
+ << r.sourceLocation().length;
}
qCDebug(QQmlLSUtilsLog) << "And following usages in file names:"
<< result.usagesInFilename();
@@ -1935,10 +1930,7 @@ findMethodDefinitionOf(const DomItem &file, QQmlJS::SourceLocation location, con
auto regions = fileLocation->info().regions;
if (auto it = regions.constFind(IdentifierRegion); it != regions.constEnd()) {
- Location result;
- result.sourceLocation = *it;
- result.filename = method.canonicalFilePath();
- return result;
+ return Location::tryFrom(method.canonicalFilePath(), *it, file);
}
return {};
@@ -1958,10 +1950,7 @@ findPropertyDefinitionOf(const DomItem &file, QQmlJS::SourceLocation propertyDef
auto regions = fileLocation->info().regions;
if (auto it = regions.constFind(IdentifierRegion); it != regions.constEnd()) {
- Location result;
- result.sourceLocation = *it;
- result.filename = propertyDefinition.canonicalFilePath();
- return result;
+ return Location::tryFrom(propertyDefinition.canonicalFilePath(), *it, file);
}
return {};
@@ -1985,7 +1974,8 @@ std::optional<Location> findDefinitionOf(const DomItem &item)
if (!jsIdentifier)
return {};
- return Location{ resolvedExpression->semanticScope->filePath(), jsIdentifier->location };
+ return Location::tryFrom(resolvedExpression->semanticScope->filePath(),
+ jsIdentifier->location, item);
}
case PropertyIdentifier: {
@@ -2019,17 +2009,13 @@ std::optional<Location> findDefinitionOf(const DomItem &item)
return {};
}
- Location result;
- result.sourceLocation = FileLocations::treeOf(domId)->info().fullRegion;
- result.filename = domId.canonicalFilePath();
- return result;
+ return Location::tryFrom(domId.canonicalFilePath(),
+ FileLocations::treeOf(domId)->info().fullRegion, domId);
}
case AttachedTypeIdentifier:
case QmlComponentIdentifier: {
- Location result;
- result.sourceLocation = resolvedExpression->semanticScope->sourceLocation();
- result.filename = resolvedExpression->semanticScope->filePath();
- return result;
+ return Location::tryFrom(resolvedExpression->semanticScope->filePath(),
+ resolvedExpression->semanticScope->sourceLocation(), item);
}
case QualifiedModuleIdentifier: {
const DomItem imports = item.fileObject().field(Fields::imports);
@@ -2039,10 +2025,7 @@ std::optional<Location> findDefinitionOf(const DomItem &item)
if (!fileLocations)
continue;
- Location result;
- result.sourceLocation = fileLocations->info().regions[IdNameRegion];
- result.filename = item.canonicalFilePath();
- return result;
+ return Location::tryFrom(item.canonicalFilePath(), fileLocations->info().regions[IdNameRegion], item);
}
}
return {};
@@ -2322,7 +2305,7 @@ RenameUsages renameUsagesOf(const DomItem &item, const QString &dirtyNewName,
// set the new name at the found usages, but add "on"-prefix and "Changed"-suffix if needed
for (const auto &location : locations.usagesInFile()) {
- const qsizetype currentLength = location.sourceLocation.length;
+ const qsizetype currentLength = location.sourceLocation().length;
Edit edit;
edit.location = location;
if (oldNameLength == currentLength) {
@@ -2371,14 +2354,30 @@ RenameUsages renameUsagesOf(const DomItem &item, const QString &dirtyNewName,
return result;
}
+std::optional<Location> Location::tryFrom(const QString &fileName,
+ const QQmlJS::SourceLocation &sourceLocation,
+ const QQmlJS::Dom::DomItem &someItem)
+{
+ auto qmlFile = someItem.goToFile(fileName).ownerAs<QQmlJS::Dom::QmlFile>();
+ if (!qmlFile) {
+ qDebug() << "Could not find file" << fileName << "in the dom!";
+ return {};
+ }
+ return Location{ fileName, sourceLocation,
+ textRowAndColumnFrom(qmlFile->code(), sourceLocation.end()) };
+}
+
+Location Location::from(const QString &fileName, const QQmlJS::SourceLocation &sourceLocation, const QString &code)
+{
+ return Location{ fileName, sourceLocation, textRowAndColumnFrom(code, sourceLocation.end()) };
+}
+
Location Location::from(const QString &fileName, const QString &code, quint32 startLine,
quint32 startCharacter, quint32 length)
{
- quint32 offset = QQmlLSUtils::textOffsetFrom(code, startLine - 1, startCharacter - 1);
-
- Location location{ fileName,
- QQmlJS::SourceLocation{ offset, length, startLine, startCharacter } };
- return location;
+ const quint32 offset = QQmlLSUtils::textOffsetFrom(code, startLine - 1, startCharacter - 1);
+ return from(fileName, QQmlJS::SourceLocation{ offset, length, startLine, startCharacter },
+ code);
}
Edit Edit::from(const QString &fileName, const QString &code, quint32 startLine,
diff --git a/src/qmlls/qqmllsutils_p.h b/src/qmlls/qqmllsutils_p.h
index 6c1fe29831..36e6448181 100644
--- a/src/qmlls/qqmllsutils_p.h
+++ b/src/qmlls/qqmllsutils_p.h
@@ -73,24 +73,45 @@ struct ExpressionType
IdentifierType type;
};
-struct Location
+class Location
{
- QString filename;
- QQmlJS::SourceLocation sourceLocation;
+public:
+ Location() = default;
+ Location(const QString &filename, const QQmlJS::SourceLocation &sourceLocation,
+ const TextPosition &end)
+ : m_filename(filename), m_sourceLocation(sourceLocation), m_end(end)
+ {
+ }
+
+ QString filename() const { return m_filename; }
+ QQmlJS::SourceLocation sourceLocation() const { return m_sourceLocation; }
+ TextPosition end() const { return m_end; }
static Location from(const QString &fileName, const QString &code, quint32 startLine,
quint32 startCharacter, quint32 length);
+ static Location from(const QString &fileName, const QQmlJS::SourceLocation &sourceLocation,
+ const QString &code);
+ static std::optional<Location> tryFrom(const QString &fileName,
+ const QQmlJS::SourceLocation &sourceLocation,
+ const QQmlJS::Dom::DomItem &someItem);
friend bool operator<(const Location &a, const Location &b)
{
- return std::make_tuple(a.filename, a.sourceLocation.begin(), a.sourceLocation.end())
- < std::make_tuple(b.filename, b.sourceLocation.begin(), b.sourceLocation.end());
+ return std::make_tuple(a.m_filename, a.m_sourceLocation.begin(), a.m_sourceLocation.end())
+ < std::make_tuple(b.m_filename, b.m_sourceLocation.begin(),
+ b.m_sourceLocation.end());
}
friend bool operator==(const Location &a, const Location &b)
{
- return std::make_tuple(a.filename, a.sourceLocation.begin(), a.sourceLocation.end())
- == std::make_tuple(b.filename, b.sourceLocation.begin(), b.sourceLocation.end());
+ return std::make_tuple(a.m_filename, a.m_sourceLocation.begin(), a.m_sourceLocation.end())
+ == std::make_tuple(b.m_filename, b.m_sourceLocation.begin(),
+ b.m_sourceLocation.end());
}
+
+private:
+ QString m_filename;
+ QQmlJS::SourceLocation m_sourceLocation;
+ TextPosition m_end;
};
/*!
@@ -236,8 +257,7 @@ QList<ItemLocation> itemsFromTextLocation(const DomItem &file, int line, int cha
DomItem sourceLocationToDomItem(const DomItem &file, const QQmlJS::SourceLocation &location);
QByteArray lspUriToQmlUrl(const QByteArray &uri);
QByteArray qmlUrlToLspUri(const QByteArray &url);
-QLspSpecification::Range qmlLocationToLspLocation(const QString &code,
- QQmlJS::SourceLocation qmlLocation);
+QLspSpecification::Range qmlLocationToLspLocation(Location qmlLocation);
DomItem baseObject(const DomItem &qmlObject);
std::optional<Location> findTypeDefinitionOf(const DomItem &item);
std::optional<Location> findDefinitionOf(const DomItem &item);
diff --git a/src/qmlls/qqmlrenamesymbolsupport.cpp b/src/qmlls/qqmlrenamesymbolsupport.cpp
index a1e16ad87b..2a094dd791 100644
--- a/src/qmlls/qqmlrenamesymbolsupport.cpp
+++ b/src/qmlls/qqmlrenamesymbolsupport.cpp
@@ -60,32 +60,12 @@ void QQmlRenameSymbolSupport::process(QQmlRenameSymbolSupport::RequestPointerArg
// collect them into editsByFileUris.
QMap<QUrl, QList<QLspSpecification::TextEdit>> editsByFileUris;
- auto renames = QQmlLSUtils::renameUsagesOf(front.domItem, newName, expressionType);
-
- QQmlJS::Dom::DomItem files = front.domItem.top().field(QQmlJS::Dom::Fields::qmlFileWithPath);
-
- QHash<QString, QString> codeCache;
-
+ const auto renames = QQmlLSUtils::renameUsagesOf(front.domItem, newName, expressionType);
for (const auto &rename : renames.renameInFile()) {
QLspSpecification::TextEdit edit;
- const QUrl uri = QUrl::fromLocalFile(rename.location.filename);
-
- auto cacheEntry = codeCache.find(rename.location.filename);
- if (cacheEntry == codeCache.end()) {
- auto file = files.key(rename.location.filename)
- .field(QQmlJS::Dom::Fields::currentItem)
- .ownerAs<QQmlJS::Dom::QmlFile>();
- if (!file) {
- qDebug() << "File" << rename.location.filename
- << "not found in DOM! Available files are" << files.keys();
- continue;
- }
- cacheEntry = codeCache.insert(rename.location.filename, file->code());
- }
-
- edit.range = QQmlLSUtils::qmlLocationToLspLocation(cacheEntry.value(),
- rename.location.sourceLocation);
+ const QUrl uri = QUrl::fromLocalFile(rename.location.filename());
+ edit.range = QQmlLSUtils::qmlLocationToLspLocation(rename.location);
edit.newText = rename.replacement.toUtf8();
editsByFileUris[uri].append(edit);
diff --git a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp
index 7e2acb510d..2787adc4a3 100644
--- a/tests/auto/qmlls/utils/tst_qmlls_utils.cpp
+++ b/tests/auto/qmlls/utils/tst_qmlls_utils.cpp
@@ -443,21 +443,21 @@ void tst_qmlls_utils::findTypeDefinitionFromLocation()
QVERIFY(base);
auto fileObject =
- locations[resultIndex].domItem.goToFile(base->filename).as<QQmlJS::Dom::QmlFile>();
+ locations[resultIndex].domItem.goToFile(base->filename()).as<QQmlJS::Dom::QmlFile>();
// print some debug message when failing, instead of using QVERIFY2
// (printing the type every time takes a lot of time).
if constexpr (enable_debug_output) {
if (!fileObject)
- qDebug() << "Could not find the file" << base->filename << "in the Dom.";
+ qDebug() << "Could not find the file" << base->filename() << "in the Dom.";
}
QVERIFY(fileObject);
- QCOMPARE(base->filename, expectedFilePath);
+ QCOMPARE(base->filename(), expectedFilePath);
QCOMPARE(fileObject->canonicalFilePath(), expectedFilePath);
- QCOMPARE(base->sourceLocation.startLine, quint32(expectedLine));
- QCOMPARE(base->sourceLocation.startColumn, quint32(expectedCharacter));
+ QCOMPARE(base->sourceLocation().startLine, quint32(expectedLine));
+ QCOMPARE(base->sourceLocation().startColumn, quint32(expectedCharacter));
}
void tst_qmlls_utils::findLocationOfItem_data()
@@ -632,8 +632,8 @@ void tst_qmlls_utils::findBaseObject()
QEXPECT_FAIL("inline-ic2", failOnInlineComponentsMessage, Abort);
QVERIFY(typeLocation);
QQmlJS::Dom::DomItem type = QQmlLSUtils::sourceLocationToDomItem(
- locations.front().domItem.goToFile(typeLocation->filename),
- typeLocation->sourceLocation);
+ locations.front().domItem.goToFile(typeLocation->filename()),
+ typeLocation->sourceLocation());
auto base = QQmlLSUtils::baseObject(type);
if constexpr (enable_debug_output) {
@@ -1464,16 +1464,16 @@ void tst_qmlls_utils::findUsages()
if (usages != data.expectedUsages) {
qDebug() << "Got:\n";
for (auto &x : usages.usagesInFile()) {
- qDebug() << x.filename << "(" << x.sourceLocation.startLine << ", "
- << x.sourceLocation.startColumn << "), " << x.sourceLocation.offset << "+"
- << x.sourceLocation.length;
+ qDebug() << x.filename() << "(" << x.sourceLocation().startLine << ", "
+ << x.sourceLocation().startColumn << "), " << x.sourceLocation().offset << "+"
+ << x.sourceLocation().length;
}
qDebug() << "with usages in filenames:" << usages.usagesInFilename();
qDebug() << "But expected: \n";
for (auto &x : data.expectedUsages.usagesInFile()) {
- qDebug() << x.filename << "(" << x.sourceLocation.startLine << ", "
- << x.sourceLocation.startColumn << "), " << x.sourceLocation.offset << "+"
- << x.sourceLocation.length;
+ qDebug() << x.filename() << "(" << x.sourceLocation().startLine << ", "
+ << x.sourceLocation().startColumn << "), " << x.sourceLocation().offset << "+"
+ << x.sourceLocation().length;
}
qDebug() << "with usages in filenames:" << data.expectedUsages.usagesInFilename();
}
@@ -1754,11 +1754,11 @@ void tst_qmlls_utils::renameUsages()
if (edits != expectedRenames) {
qDebug() << "Got:\n";
for (auto &x : edits.renameInFile()) {
- qDebug() << x.replacement << x.location.filename << "("
- << x.location.sourceLocation.startLine << ", "
- << x.location.sourceLocation.startColumn << "), "
- << x.location.sourceLocation.offset << "+"
- << x.location.sourceLocation.length;
+ qDebug() << x.replacement << x.location.filename() << "("
+ << x.location.sourceLocation().startLine << ", "
+ << x.location.sourceLocation().startColumn << "), "
+ << x.location.sourceLocation().offset << "+"
+ << x.location.sourceLocation().length;
}
qDebug() << "with renames in filenames:";
for (auto &x : edits.renameInFilename()) {
@@ -1766,11 +1766,11 @@ void tst_qmlls_utils::renameUsages()
}
qDebug() << "But expected: \n";
for (auto &x : expectedRenames.renameInFile()) {
- qDebug() << x.replacement << x.location.filename << "("
- << x.location.sourceLocation.startLine << ", "
- << x.location.sourceLocation.startColumn << "), "
- << x.location.sourceLocation.offset << "+"
- << x.location.sourceLocation.length;
+ qDebug() << x.replacement << x.location.filename() << "("
+ << x.location.sourceLocation().startLine << ", "
+ << x.location.sourceLocation().startColumn << "), "
+ << x.location.sourceLocation().offset << "+"
+ << x.location.sourceLocation().length;
}
qDebug() << "with renames in filenames:";
for (auto &x : expectedRenames.renameInFilename()) {
@@ -1967,11 +1967,11 @@ void tst_qmlls_utils::findDefinitionFromLocation()
QVERIFY(definition);
// don't work with absolute paths, and only compare the end of the file path
- QCOMPARE(QStringView(definition->filename).last(expectedFilePath.size()), expectedFilePath);
+ QCOMPARE(QStringView(definition->filename()).last(expectedFilePath.size()), expectedFilePath);
- QCOMPARE(definition->sourceLocation.startLine, quint32(expectedLine));
- QCOMPARE(definition->sourceLocation.startColumn, quint32(expectedCharacter));
- QCOMPARE(definition->sourceLocation.length, quint32(expectedLength));
+ QCOMPARE(definition->sourceLocation().startLine, quint32(expectedLine));
+ QCOMPARE(definition->sourceLocation().startColumn, quint32(expectedCharacter));
+ QCOMPARE(definition->sourceLocation().length, quint32(expectedLength));
}
void tst_qmlls_utils::resolveExpressionType_data()