31 QLspSpecification::WorkspaceEdit result;
32 ResponseScopeGuard guard(result, request->m_response);
34 auto itemsFound = itemsForRequest(request);
35 if (guard.setErrorFrom(itemsFound))
39 std::get<QList<QQmlLSUtils::ItemLocation>>(itemsFound).front();
41 const QString newName = QString::fromUtf8(request->m_parameters.newName);
45 if (!expressionType) {
46 guard.setError(QQmlLSUtils::ErrorMessage{ 0, u"Cannot rename the requested object"_s });
50 if (guard.setErrorFrom(QQmlLSUtils::checkNameForRename(front.domItem, newName, expressionType)))
53 auto &editsByFileForResult = result.documentChanges.emplace();
57 QMap<QUrl, QList<QLspSpecification::TextEdit>> editsByFileUris;
59 const auto renames = QQmlLSUtils::renameUsagesOf(front.domItem, newName, expressionType);
60 for (
const auto &rename : renames.renameInFile()) {
61 QLspSpecification::TextEdit edit;
63 const QUrl uri = QUrl::fromLocalFile(rename.location.filename());
64 edit.range = QQmlLSUtils::qmlLocationToLspLocation(rename.location);
65 edit.newText = rename.replacement.toUtf8();
67 editsByFileUris[uri].append(edit);
70 for (
auto it = editsByFileUris.keyValueBegin(); it != editsByFileUris.keyValueEnd(); ++it) {
71 QLspSpecification::TextDocumentEdit editsForCurrentFile;
72 editsForCurrentFile.textDocument.uri = it->first.toEncoded();
79 for (
const auto &x : std::as_const(it->second)) {
80 editsForCurrentFile.edits.append(x);
82 editsByFileForResult.append(editsForCurrentFile);
86 for (
const auto &rename : renames.renameInFilename()) {
87 QLspSpecification::RenameFile currentRenameFile;
88 currentRenameFile.kind =
"rename";
89 currentRenameFile.oldUri = QUrl::fromLocalFile(rename.oldFilename).toEncoded();
90 currentRenameFile.newUri = QUrl::fromLocalFile(rename.newFilename).toEncoded();
91 editsByFileForResult.append(currentRenameFile);