Skip to content

Commit 4101b7c

Browse files
committed
Add silent mode to checkpoint creation to suppress progress notifications and refactor restoration progress logic
1 parent 5a78b37 commit 4101b7c

3 files changed

Lines changed: 118 additions & 105 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ export const apply_chat_response_command = (params: {
209209
context: params.context,
210210
panel_provider: params.panel_provider,
211211
trigger: 'before-response-previewed',
212-
description: args?.raw_instructions
212+
description: args?.raw_instructions,
213+
silent: true
213214
})
214215
}
215216

apps/editor/src/commands/checkpoints-command/actions/create-checkpoint.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const create_checkpoint = async (params: {
3030
panel_provider: PanelProvider
3131
trigger?: CheckpointTrigger
3232
description?: string
33+
silent?: boolean
3334
}): Promise<Checkpoint | undefined> => {
3435
try {
3536
const trigger = params.trigger ?? 'manual'
@@ -233,13 +234,15 @@ export const create_checkpoint = async (params: {
233234
let did_show_modal = false
234235

235236
try {
236-
timer = setTimeout(() => {
237-
did_show_modal = true
238-
params.panel_provider.send_message({
239-
command: 'SHOW_PROGRESS',
240-
title: 'Creating checkpoint...'
241-
})
242-
}, 1000)
237+
if (!params.silent) {
238+
timer = setTimeout(() => {
239+
did_show_modal = true
240+
params.panel_provider.send_message({
241+
command: 'SHOW_PROGRESS',
242+
title: 'Creating checkpoint...'
243+
})
244+
}, 1000)
245+
}
243246

244247
await create_checkpoint_task()
245248
} finally {

apps/editor/src/commands/checkpoints-command/actions/restore-checkpoint.ts

Lines changed: 106 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@ export const restore_checkpoint = async (params: {
4444
return
4545
}
4646

47+
const title = params.options?.skip_confirmation
48+
? 'Reverting...'
49+
: 'Restoring checkpoint...'
50+
51+
let current_progress = 0
52+
let progress_reporter: vscode.Progress<{ message?: string; increment?: number }> | undefined
53+
54+
if (!params.options?.use_native_progress) {
55+
params.panel_provider.send_message({
56+
command: 'SHOW_PROGRESS',
57+
title,
58+
progress: current_progress,
59+
delay_visibility: false
60+
})
61+
progress_reporter = {
62+
report: (value) => {
63+
if (value.increment) {
64+
current_progress += value.increment
65+
params.panel_provider.send_message({
66+
command: 'SHOW_PROGRESS',
67+
title,
68+
progress: Math.min(current_progress, 100),
69+
delay_visibility: false
70+
})
71+
}
72+
}
73+
}
74+
}
75+
76+
const main_task = async (native_progress?: vscode.Progress<{ message?: string; increment?: number }>) => {
77+
const progress = native_progress || progress_reporter
78+
4779
if (
4880
params.checkpoint.trigger == 'response-accepted' &&
4981
params.checkpoint.description
@@ -100,7 +132,8 @@ export const restore_checkpoint = async (params: {
100132
workspace_provider: params.workspace_provider,
101133
context: params.context,
102134
panel_provider: params.panel_provider,
103-
trigger: 'before-checkpoint-restored'
135+
trigger: 'before-checkpoint-restored',
136+
silent: true
104137
})
105138
}
106139

@@ -148,15 +181,6 @@ export const restore_checkpoint = async (params: {
148181
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
149182
Date.now()
150183
)
151-
152-
const title = params.options?.skip_confirmation
153-
? 'Reverting...'
154-
: 'Restoring checkpoint...'
155-
156-
// This is the task that was inside withProgress
157-
const restoration_task = async (
158-
progress: vscode.Progress<{ message?: string; increment?: number }>
159-
) => {
160184
const checkpoint_dir_path = get_checkpoint_path(
161185
params.checkpoint.timestamp
162186
)
@@ -419,49 +443,6 @@ export const restore_checkpoint = async (params: {
419443
progress
420444
})
421445
}
422-
}
423-
424-
if (params.options?.use_native_progress) {
425-
await vscode.window.withProgress(
426-
{
427-
location: vscode.ProgressLocation.Notification,
428-
title,
429-
cancellable: false
430-
},
431-
restoration_task
432-
)
433-
} else {
434-
let current_progress = 0
435-
params.panel_provider.send_message({
436-
command: 'SHOW_PROGRESS',
437-
title,
438-
progress: current_progress,
439-
delay_visibility: true
440-
})
441-
const progress: vscode.Progress<{
442-
message?: string
443-
increment?: number
444-
}> = {
445-
report: (value) => {
446-
if (value.increment) {
447-
current_progress += value.increment
448-
params.panel_provider.send_message({
449-
command: 'SHOW_PROGRESS',
450-
title,
451-
progress: Math.min(current_progress, 100),
452-
delay_visibility: true
453-
})
454-
}
455-
}
456-
}
457-
try {
458-
await restoration_task(progress)
459-
} finally {
460-
params.panel_provider.send_message({
461-
command: 'HIDE_PROGRESS'
462-
})
463-
}
464-
}
465446

466447
if (params.checkpoint.response_history) {
467448
params.panel_provider.response_history =
@@ -540,50 +521,6 @@ export const restore_checkpoint = async (params: {
540521
})
541522
}
542523
}
543-
544-
const message = params.options?.skip_confirmation
545-
? 'Successfully reverted changes.'
546-
: 'Checkpoint has been restored.'
547-
548-
if (params.checkpoint.trigger == 'response-accepted') {
549-
params.panel_provider.send_message({
550-
command: 'SHOW_PROGRESS',
551-
title: message.endsWith('.') ? message.slice(0, -1) : message,
552-
cancellable: false,
553-
delay_visibility: true
554-
})
555-
} else if (params.options?.show_auto_closing_modal_on_success) {
556-
params.panel_provider.send_message({
557-
command: 'SHOW_AUTO_CLOSING_MODAL',
558-
title: message.slice(0, -1),
559-
type: 'success'
560-
})
561-
} else if (temp_checkpoint) {
562-
const action = await vscode.window.showInformationMessage(
563-
message,
564-
'Revert'
565-
)
566-
if (action == 'Revert') {
567-
await restore_checkpoint({
568-
checkpoint: temp_checkpoint,
569-
workspace_provider: params.workspace_provider,
570-
context: params.context,
571-
panel_provider: params.panel_provider,
572-
options: { skip_confirmation: true, use_native_progress: true }
573-
})
574-
await delete_checkpoint({
575-
context: params.context,
576-
checkpoint_to_delete: temp_checkpoint,
577-
panel_provider: params.panel_provider
578-
})
579-
await params.context.workspaceState.update(
580-
TEMPORARY_CHECKPOINT_STATE_KEY,
581-
undefined
582-
)
583-
}
584-
} else {
585-
vscode.window.showInformationMessage(message)
586-
}
587524
} catch (err: any) {
588525
await params.context.workspaceState.update(
589526
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
@@ -603,5 +540,77 @@ export const restore_checkpoint = async (params: {
603540
undefined
604541
)
605542
}
543+
throw err
544+
}
545+
546+
return temp_checkpoint
547+
}
548+
549+
let temp_check: Checkpoint | undefined
550+
try {
551+
if (params.options?.use_native_progress) {
552+
temp_check = await vscode.window.withProgress(
553+
{
554+
location: vscode.ProgressLocation.Notification,
555+
title,
556+
cancellable: false
557+
},
558+
main_task
559+
)
560+
} else {
561+
temp_check = await main_task()
562+
}
563+
} catch (e) {
564+
return
565+
} finally {
566+
if (!params.options?.use_native_progress) {
567+
params.panel_provider.send_message({
568+
command: 'HIDE_PROGRESS'
569+
})
570+
}
571+
}
572+
573+
const message = params.options?.skip_confirmation
574+
? 'Successfully reverted changes.'
575+
: 'Checkpoint has been restored.'
576+
577+
if (params.checkpoint.trigger == 'response-accepted') {
578+
params.panel_provider.send_message({
579+
command: 'SHOW_PROGRESS',
580+
title: message.endsWith('.') ? message.slice(0, -1) : message,
581+
cancellable: false,
582+
delay_visibility: true
583+
})
584+
} else if (params.options?.show_auto_closing_modal_on_success) {
585+
params.panel_provider.send_message({
586+
command: 'SHOW_AUTO_CLOSING_MODAL',
587+
title: message.slice(0, -1),
588+
type: 'success'
589+
})
590+
} else if (temp_check) {
591+
const action = await vscode.window.showInformationMessage(
592+
message,
593+
'Revert'
594+
)
595+
if (action == 'Revert') {
596+
await restore_checkpoint({
597+
checkpoint: temp_check,
598+
workspace_provider: params.workspace_provider,
599+
context: params.context,
600+
panel_provider: params.panel_provider,
601+
options: { skip_confirmation: true, use_native_progress: true }
602+
})
603+
await delete_checkpoint({
604+
context: params.context,
605+
checkpoint_to_delete: temp_check,
606+
panel_provider: params.panel_provider
607+
})
608+
await params.context.workspaceState.update(
609+
TEMPORARY_CHECKPOINT_STATE_KEY,
610+
undefined
611+
)
612+
}
613+
} else {
614+
vscode.window.showInformationMessage(message)
606615
}
607616
}

0 commit comments

Comments
 (0)