38 QLspSpecification::WorkspaceEdit result;
41 auto itemsFound = itemsForRequest(request);
42 if (guard.setErrorFrom(itemsFound))
46 std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
48 const QString newName = QString::fromUtf8(request->m_parameters.newName);
52 if (!expressionType) {
53 guard.setError(QQmlLSUtils::ErrorMessage{ 0, u"Cannot rename the requested object"_s });
57 if (guard.setErrorFrom(QQmlLSUtils::checkNameForRename(front.domItem, newName, expressionType)))
60 auto &editsByFileForResult = result.documentChanges.emplace();
64 QMap<QUrl, QList<QLspSpecification::TextEdit>> editsByFileUris;
66 const auto renames = QQmlLSUtils::renameUsagesOf(front.domItem, newName, expressionType);
67 for (
const auto &rename : renames.renameInFile()) {
68 QLspSpecification::TextEdit edit;
70 const QUrl uri = QUrl::fromLocalFile(rename.location.filename());
71 edit.range = QQmlLSUtils::qmlLocationToLspLocation(rename.location);
72 edit.newText = rename.replacement.toUtf8();
74 editsByFileUris[uri].append(edit);
77 for (
auto it = editsByFileUris.keyValueBegin(); it != editsByFileUris.keyValueEnd(); ++it) {
78 QLspSpecification::TextDocumentEdit editsForCurrentFile;
79 editsForCurrentFile.textDocument.uri = it->first.toEncoded();
86 for (
const auto &x : std::as_const(it->second)) {
87 editsForCurrentFile.edits.append(x);
89 editsByFileForResult.append(editsForCurrentFile);
93 for (
const auto &rename : renames.renameInFilename()) {
94 QLspSpecification::RenameFile currentRenameFile;
95 currentRenameFile.kind =
"rename";
96 currentRenameFile.oldUri = QUrl::fromLocalFile(rename.oldFilename).toEncoded();
97 currentRenameFile.newUri = QUrl::fromLocalFile(rename.newFilename).toEncoded();
98 editsByFileForResult.append(currentRenameFile);