Skip to content

Commit e833623

Browse files
committed
Add progress reporting for chat response processing and simplify tab group restoration logic
- in the progress modal, start reporting progress as soon files are being applied. continue using to keep the same modal t('common.progress.preparing-preview') - make on_progress parameter required - all functions with "on_progress" should accept params variable, don't destructure inside. - If you have moved a tab to a different View Column (e.g., dragged a file from the left group to the right group) or changed the order of the tabs, are_states_equal becomes false. Should not.
1 parent a9e0733 commit e833623

5 files changed

Lines changed: 40 additions & 23 deletions

File tree

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ export const apply_chat_response_command = (params: {
378378

379379
before_checkpoint = undefined
380380
} else if (saved_tab_groups) {
381-
// Restore tab groups when preview gets rejected
382381
await restore_tab_groups(saved_tab_groups)
383382
}
384383
}
@@ -422,12 +421,9 @@ const restore_tab_groups = async (
422421

423422
const are_states_equal =
424423
current_editors.length == saved_state.editors.length &&
425-
current_editors.every((editor, index) => {
426-
const saved = saved_state.editors[index]
427-
return (
428-
editor.uri == saved.uri && editor.view_column == saved.view_column
429-
)
430-
})
424+
current_editors.every((editor) =>
425+
saved_state.editors.some((saved) => saved.uri == editor.uri)
426+
)
431427

432428
if (are_states_equal) {
433429
if (saved_state.active_editor_uri) {

‎apps/editor/src/commands/apply-chat-response-command/handlers/conflict-markers-handler.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ import {
1313
import { apply_conflict_markers_to_content } from '../utils/edit-formats/conflict-markers/apply-conflict-markers-to-content'
1414
import { parse_conflict_segments } from '../utils/edit-formats/conflict-markers'
1515

16-
export const handle_conflict_markers = async (
16+
export const handle_conflict_markers = async (params: {
1717
files: FileItem[]
18-
): Promise<{
18+
on_progress: (progress: number) => void
19+
}): Promise<{
1920
success: boolean
2021
original_states?: OriginalFileState[]
2122
failed_files?: FileItem[]
2223
}> => {
2324
Logger.info({
2425
function_name: 'handle_conflict_markers',
2526
message: 'start',
26-
data: { file_count: files.length }
27+
data: { file_count: params.files.length }
2728
})
2829
try {
2930
if (
@@ -45,7 +46,10 @@ export const handle_conflict_markers = async (
4546
const original_states: OriginalFileState[] = []
4647
const failed_files: FileItem[] = []
4748

48-
for (const file of files) {
49+
const total_files = params.files.length
50+
for (let i = 0; i < total_files; i++) {
51+
params.on_progress(Math.round((i / total_files) * 100))
52+
const file = params.files[i]
4953
let workspace_root = default_workspace
5054
if (file.workspace_name && workspace_map.has(file.workspace_name)) {
5155
workspace_root = workspace_map.get(file.workspace_name)!

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import {
1313
cleanup_rename_source
1414
} from '../utils/file-operations'
1515

16-
export const handle_fast_replace = async (
16+
export const handle_fast_replace = async (params: {
1717
files: FileItem[]
18-
): Promise<{ success: boolean; original_states?: OriginalFileState[] }> => {
18+
on_progress: (progress: number) => void
19+
}): Promise<{ success: boolean; original_states?: OriginalFileState[] }> => {
1920
Logger.info({
2021
function_name: 'handle_fast_replace',
2122
message: 'start',
22-
data: { file_count: files.length }
23+
data: { file_count: params.files.length }
2324
})
2425
try {
2526
const safe_files: FileItem[] = []
@@ -46,7 +47,7 @@ export const handle_fast_replace = async (
4647

4748
const default_workspace = vscode.workspace.workspaceFolders[0].uri.fsPath
4849

49-
for (const file of files) {
50+
for (const file of params.files) {
5051
let workspace_root = default_workspace
5152
if (file.workspace_name && workspace_map.has(file.workspace_name)) {
5253
workspace_root = workspace_map.get(file.workspace_name)!
@@ -94,7 +95,10 @@ export const handle_fast_replace = async (
9495
}
9596

9697
const original_states: OriginalFileState[] = []
97-
for (const file of safe_files) {
98+
const total_files = safe_files.length
99+
for (let i = 0; i < total_files; i++) {
100+
params.on_progress(Math.round((i / total_files) * 100))
101+
const file = safe_files[i]
98102
let workspace_root = default_workspace
99103
if (file.workspace_name && workspace_map.has(file.workspace_name)) {
100104
workspace_root = workspace_map.get(file.workspace_name)!

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ import {
1212
cleanup_rename_source
1313
} from '../utils/file-operations'
1414

15-
export const handle_truncated_edit = async (
15+
export const handle_truncated_edit = async (params: {
1616
files: FileItem[]
17-
): Promise<{
17+
on_progress: (progress: number) => void
18+
}): Promise<{
1819
success: boolean
1920
original_states?: OriginalFileState[]
2021
failed_files?: FileItem[]
2122
}> => {
2223
Logger.info({
2324
function_name: 'handle_truncated_edit',
2425
message: 'start',
25-
data: { file_count: files.length }
26+
data: { file_count: params.files.length }
2627
})
2728

2829
if (
@@ -44,7 +45,10 @@ export const handle_truncated_edit = async (
4445
const original_states: OriginalFileState[] = []
4546
const failed_files: FileItem[] = []
4647

47-
for (const file of files) {
48+
const total_files = params.files.length
49+
for (let i = 0; i < total_files; i++) {
50+
params.on_progress(Math.round((i / total_files) * 100))
51+
const file = params.files[i]
4852
let workspace_root = default_workspace
4953
if (file.workspace_name && workspace_map.has(file.workspace_name)) {
5054
workspace_root = workspace_map.get(file.workspace_name)!

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ export const process_chat_response = async (
5656
panel_provider: PanelProvider,
5757
workspace_provider: WorkspaceProvider
5858
): Promise<PreviewData | null> => {
59+
const on_progress = (progress: number) => {
60+
panel_provider.send_message({
61+
command: 'SHOW_PROGRESS',
62+
title: t('common.progress.preparing-preview'),
63+
progress
64+
})
65+
}
66+
5967
if (args?.files_with_content) {
6068
const result = await handle_restore_preview(args.files_with_content)
6169
if (result.success && result.original_states) {
@@ -286,6 +294,7 @@ export const process_chat_response = async (
286294
const total_patches = patches.length
287295

288296
for (let i = 0; i < total_patches; i++) {
297+
on_progress(Math.round((i / total_patches) * 100))
289298
const patch = patches[i]
290299
let workspace_path = default_workspace
291300

@@ -563,7 +572,7 @@ export const process_chat_response = async (
563572
let operation_success = false
564573

565574
if (selected_mode_label == 'Fast replace') {
566-
const result = await handle_fast_replace(files)
575+
const result = await handle_fast_replace({ files, on_progress })
567576
if (result.success && result.original_states) {
568577
final_original_states = result.original_states
569578
operation_success = true
@@ -574,7 +583,7 @@ export const process_chat_response = async (
574583
data: { success: result.success }
575584
})
576585
} else if (selected_mode_label == 'Truncated') {
577-
const result = await handle_truncated_edit(files)
586+
const result = await handle_truncated_edit({ files, on_progress })
578587
const successful_states = result.original_states || []
579588
const failed_files = result.failed_files || []
580589

@@ -603,7 +612,7 @@ export const process_chat_response = async (
603612
data: { success: result.success }
604613
})
605614
} else if (selected_mode_label == 'Conflict markers') {
606-
const result = await handle_conflict_markers(files)
615+
const result = await handle_conflict_markers({ files, on_progress })
607616

608617
const successful_states = result.original_states || []
609618
const failed_files: FileItem[] = result.failed_files || []

0 commit comments

Comments
 (0)