| 70 | } |
| 71 | |
| 72 | void ChangesManager::addFileEdit( |
| 73 | const QString &editId, |
| 74 | const QString &filePath, |
| 75 | const QString &oldContent, |
| 76 | const QString &newContent, |
| 77 | bool autoApply, |
| 78 | bool isFromHistory, |
| 79 | const QString &requestId) |
| 80 | { |
| 81 | QMutexLocker locker(&m_mutex); |
| 82 | |
| 83 | if (m_fileEdits.contains(editId)) { |
| 84 | LOG_MESSAGE(QString("File edit already exists, skipping: %1").arg(editId)); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | FileEdit edit; |
| 89 | edit.editId = editId; |
| 90 | edit.filePath = filePath; |
| 91 | edit.oldContent = oldContent; |
| 92 | edit.newContent = newContent; |
| 93 | edit.timestamp = QDateTime::currentDateTime(); |
| 94 | edit.wasAutoApplied = false; |
| 95 | edit.isFromHistory = isFromHistory; |
| 96 | |
| 97 | LOG_MESSAGE(QString("Creating diff for edit %1").arg(editId)); |
| 98 | locker.unlock(); |
| 99 | edit.diffInfo = createDiffInfo(oldContent, newContent, filePath); |
| 100 | locker.relock(); |
| 101 | LOG_MESSAGE(QString("Diff created for edit %1: %2 hunk(s), fallback: %3") |
| 102 | .arg(editId) |
| 103 | .arg(edit.diffInfo.hunks.size()) |
| 104 | .arg(edit.diffInfo.useFallback ? "yes" : "no")); |
| 105 | |
| 106 | if (isFromHistory) { |
| 107 | edit.status = Archived; |
| 108 | edit.statusMessage = "Loaded from chat history"; |
| 109 | autoApply = false; |
| 110 | } else { |
| 111 | edit.status = Pending; |
| 112 | edit.statusMessage = "Waiting to be applied"; |
| 113 | } |
| 114 | |
| 115 | m_fileEdits.insert(editId, edit); |
| 116 | |
| 117 | if (!requestId.isEmpty() && !isFromHistory) { |
| 118 | if (!m_requestEdits.contains(requestId)) { |
| 119 | m_requestEdits[requestId] = RequestEdits(); |
| 120 | } |
| 121 | m_requestEdits[requestId].editIds.append(editId); |
| 122 | |
| 123 | LOG_MESSAGE(QString("File edit tracked for request: %1 (requestId: %2)") |
| 124 | .arg(editId, requestId)); |
| 125 | } |
| 126 | |
| 127 | emit fileEditAdded(editId); |
| 128 | |
| 129 | LOG_MESSAGE(QString("File edit added: %1 for file %2 (history: %3, autoApply: %4)") |
no test coverage detected