Skip to content

Commit df8fd7e

Browse files
committed
Update file state management to include proposed_content and ai_content while prioritizing proposed content during file processing and preview generation
- we seem to have a race condition causing line added/removed count to be "+0 -0"
1 parent 3065258 commit df8fd7e

6 files changed

Lines changed: 37 additions & 16 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,17 @@ export const apply_chat_response_command = (params: {
224224
try {
225225
if (fs.existsSync(sanitized_file_path)) {
226226
file_exists = true
227-
const document =
228-
await vscode.workspace.openTextDocument(sanitized_file_path)
229-
current_content = document.getText()
227+
if (state.proposed_content !== undefined) {
228+
current_content = state.proposed_content
229+
} else {
230+
const document =
231+
await vscode.workspace.openTextDocument(
232+
sanitized_file_path
233+
)
234+
current_content = document.getText()
235+
}
236+
} else if (state.proposed_content !== undefined) {
237+
current_content = state.proposed_content
230238
}
231239
} catch (error) {
232240
continue

‎apps/editor/src/commands/apply-chat-response-command/handlers/active-editor-intelligent-update-handler.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export const handle_active_editor_intelligent_update = async (params: {
174174
{
175175
file_path: target_file_path,
176176
content: original_content,
177-
workspace_name: file_item.workspace_name
177+
workspace_name: file_item.workspace_name,
178+
ai_content: file_item.content,
179+
proposed_content: final_content
178180
}
179181
]
180182
} catch (error: any) {

‎apps/editor/src/commands/apply-chat-response-command/handlers/fast-replace-handler.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ export const handle_fast_replace = async (params: {
140140
file_path: file.file_path,
141141
content: original_content,
142142
workspace_name: file.workspace_name,
143-
file_state: 'deleted'
143+
file_state: 'deleted',
144+
proposed_content: ''
144145
})
145146
Logger.info({
146147
function_name: 'handle_fast_replace',
@@ -197,7 +198,9 @@ export const handle_fast_replace = async (params: {
197198
file_path: file.file_path,
198199
content: rename_source_content,
199200
workspace_name: file.workspace_name,
200-
file_path_to_restore: file.renamed_from
201+
file_path_to_restore: file.renamed_from,
202+
ai_content: file.content,
203+
proposed_content: new_content
201204
})
202205

203206
continue
@@ -224,11 +227,6 @@ export const handle_fast_replace = async (params: {
224227
const file_uri = vscode.Uri.file(safe_path)
225228
const document = await vscode.workspace.openTextDocument(file_uri)
226229
const original_content = document.getText()
227-
original_states.push({
228-
file_path: file.file_path,
229-
content: original_content,
230-
workspace_name: file.workspace_name
231-
})
232230
let final_content = file.content
233231
if (
234232
original_content.endsWith('\n') &&
@@ -237,6 +235,14 @@ export const handle_fast_replace = async (params: {
237235
final_content += '\n'
238236
}
239237

238+
original_states.push({
239+
file_path: file.file_path,
240+
content: original_content,
241+
workspace_name: file.workspace_name,
242+
ai_content: file.content,
243+
proposed_content: final_content
244+
})
245+
240246
const edit = new vscode.WorkspaceEdit()
241247
edit.replace(
242248
document.uri,
@@ -259,7 +265,9 @@ export const handle_fast_replace = async (params: {
259265
file_path: file.file_path,
260266
content: '',
261267
file_state: 'new',
262-
workspace_name: file.workspace_name
268+
workspace_name: file.workspace_name,
269+
ai_content: file.content,
270+
proposed_content: file.content
263271
})
264272
const directory = path.dirname(safe_path)
265273
if (!fs.existsSync(directory)) {

‎apps/editor/src/commands/apply-chat-response-command/response-processor.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export const process_chat_response = async (
7676
return {
7777
...state,
7878
ai_content: file_in_preview?.ai_content,
79-
proposed_content: file_in_preview?.proposed_content,
79+
proposed_content:
80+
file_in_preview?.proposed_content ?? file_in_preview?.content,
8081
is_checked: file_in_preview?.is_checked,
8182
apply_failed: file_in_preview?.apply_failed,
8283
applied_with_intelligent_update:

‎apps/editor/src/commands/apply-chat-response-command/utils/preview/file-preparer.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export const prepare_files_from_original_states = async (params: {
3535
try {
3636
if (fs.existsSync(sanitized_file_path)) {
3737
file_exists = true
38-
current_content = fs.readFileSync(sanitized_file_path, 'utf8')
38+
current_content =
39+
state.proposed_content ?? fs.readFileSync(sanitized_file_path, 'utf8')
40+
} else if (state.proposed_content !== undefined) {
41+
current_content = state.proposed_content
3942
}
4043
} catch (error) {
4144
continue

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ export const ResponsePreview: FC<Props> = (props) => {
150150
error_count,
151151
is_fixing_all,
152152
has_attempted_auto_fix,
153-
files_in_preview,
154-
props.on_fix_all_failed
153+
files_in_preview
155154
])
156155

157156
const get_status_text = (file: FileInPreview) => {

0 commit comments

Comments
 (0)