Skip to content

Commit 555dec1

Browse files
committed
Persist raw instructions for undo and remove commit message details when undoing applied response
- Store the applied `raw_instructions` in `workspaceState` within `update_undo_button_state` when changes are accepted, and in `handle-undo.ts`, call `CommitMessageDetails.remove` with that stored prompt during undo before clearing the state. └── apps └── editor └── src ├── commands │ ├── apply-response-command │ │ ├── apply-response-command.ts │ │ ├── handlers │ │ │ ├── diff-handler.ts │ │ │ ├── fast-replace-handler.ts │ │ │ ├── restore-preview-handler.ts │ │ │ ├── search-replace-handler.ts │ │ │ └── truncated-handler.ts │ │ ├── response-processor.ts │ │ ├── types │ │ │ └── original-file-state.ts │ │ └── utils │ │ ├── file-operations.ts │ │ ├── preview-handler.ts │ │ └── state-manager.ts │ ├── code-at-cursor-command │ │ └── code-at-cursor-commands.ts │ ├── generate-commit-message-commands │ │ └── actions │ │ ├── get-prompt-data.ts │ │ └── run-generate-action.ts │ └── history-command │ ├── actions │ │ └── restore-checkpoint.ts │ └── history-command.ts ├── constants │ └── state-keys.ts ├── features │ └── checkpoints │ └── types │ └── checkpoint.ts ├── services │ └── git-discard-file-watcher.ts ├── utils │ └── commit-message-details.ts └── views └── prompt └── backend ├── message-handlers │ ├── handle-request-can-undo.ts │ ├── handle-undo.ts │ └── index.ts └── prompt-view-provider.ts
1 parent 38848a2 commit 555dec1

5 files changed

Lines changed: 38 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export const process_response = async (params: {
101101
prompt_view_provider: params.prompt_view_provider,
102102
states: augmented_states,
103103
applied_content: params.response,
104-
original_editor_state: params.args?.original_editor_state
104+
original_editor_state: params.args?.original_editor_state,
105+
raw_instructions: params.args?.raw_instructions
105106
})
106107
return {
107108
original_states: augmented_states,
@@ -359,7 +360,8 @@ export const process_response = async (params: {
359360
prompt_view_provider: params.prompt_view_provider,
360361
states: all_original_states,
361362
applied_content: params.response,
362-
original_editor_state: params.args?.original_editor_state
363+
original_editor_state: params.args?.original_editor_state,
364+
raw_instructions: params.args?.raw_instructions
363365
})
364366
}
365367

@@ -513,7 +515,8 @@ export const process_response = async (params: {
513515
prompt_view_provider: params.prompt_view_provider,
514516
states: final_original_states,
515517
applied_content: params.response,
516-
original_editor_state: params.args?.original_editor_state
518+
original_editor_state: params.args?.original_editor_state,
519+
raw_instructions: params.args?.raw_instructions
517520
})
518521

519522
return {

‎apps/editor/src/commands/apply-response-command/utils/preview-handler.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ export const preview_handler = async (params: {
182182
prompt_view_provider: params.prompt_view_provider,
183183
states: accepted_states,
184184
applied_content: params.chat_response,
185-
original_editor_state: params.original_editor_state
185+
original_editor_state: params.original_editor_state,
186+
raw_instructions: params.raw_instructions
186187
})
187188

188189
if (preview_result.active_editor_state) {

‎apps/editor/src/commands/apply-response-command/utils/state-manager.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as vscode from 'vscode'
22
import {
33
LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY,
44
LAST_APPLIED_CHANGES_STATE_KEY,
5-
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY
5+
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY,
6+
LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY
67
} from '@/constants/state-keys'
78
import { OriginalFileState } from '../types/original-file-state'
89
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
@@ -16,6 +17,7 @@ export const update_undo_button_state = (params: {
1617
file_path: string
1718
position: { line: number; character: number }
1819
} | null
20+
raw_instructions?: string | null
1921
}) => {
2022
if (params.states && params.states.length > 0) {
2123
params.extension_context.workspaceState.update(
@@ -30,6 +32,10 @@ export const update_undo_button_state = (params: {
3032
LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY,
3133
params.original_editor_state
3234
)
35+
params.extension_context.workspaceState.update(
36+
LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY,
37+
params.raw_instructions
38+
)
3339
params.prompt_view_provider.set_undo_button_state(true)
3440
} else {
3541
params.extension_context.workspaceState.update(
@@ -44,6 +50,10 @@ export const update_undo_button_state = (params: {
4450
LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY,
4551
null
4652
)
53+
params.extension_context.workspaceState.update(
54+
LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY,
55+
null
56+
)
4757
params.prompt_view_provider.set_undo_button_state(false)
4858
}
4959
}

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export const LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY =
33
'last-applied-changes-editor-state'
44
export const LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY =
55
'last-applied-clipboard-content'
6+
export const LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY =
7+
'last-applied-raw-instructions'
68
export const RANGES_STATE_KEY = 'ranges'
79
export const LAST_RANGES_SAVE_LOCATION_STATE_KEY = 'last-ranges-save-location'
810
export const LAST_APPLY_CONTEXT_OPTION_STATE_KEY = 'last-apply-context-option'

‎apps/editor/src/views/prompt/backend/message-handlers/handle-undo.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import * as vscode from 'vscode'
22
import {
33
LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY,
44
LAST_APPLIED_CHANGES_STATE_KEY,
5-
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY
5+
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY,
6+
LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY
67
} from '@/constants/state-keys'
78
import { dictionary } from '@shared/constants/dictionary'
89
import { t } from '@/i18n'
910
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
1011
import { OriginalFileState } from '@/commands/apply-response-command/types/original-file-state'
1112
import { undo_files } from '@/commands/apply-response-command/utils/file-operations'
13+
import { CommitMessageDetails } from '@/utils/commit-message-details'
1214

1315
export const handle_undo = async (
1416
prompt_view_provider: PromptViewProvider
@@ -24,6 +26,9 @@ export const handle_undo = async (
2426
}
2527
| undefined
2628
>(LAST_APPLIED_CHANGES_EDITOR_STATE_STATE_KEY)
29+
const raw_instructions = extension_context.workspaceState.get<
30+
string | undefined
31+
>(LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY)
2732

2833
if (!original_states || original_states.length == 0) {
2934
vscode.window.showInformationMessage(
@@ -39,6 +44,13 @@ export const handle_undo = async (
3944
return
4045
}
4146

47+
if (raw_instructions) {
48+
CommitMessageDetails.remove({
49+
extension_context,
50+
prompt: raw_instructions
51+
})
52+
}
53+
4254
if (editor_state) {
4355
try {
4456
const uri = vscode.Uri.file(editor_state.file_path)
@@ -72,6 +84,10 @@ export const handle_undo = async (
7284
LAST_APPLIED_CLIPBOARD_CONTENT_STATE_KEY,
7385
null
7486
)
87+
extension_context.workspaceState.update(
88+
LAST_APPLIED_RAW_INSTRUCTIONS_STATE_KEY,
89+
null
90+
)
7591
prompt_view_provider.set_undo_button_state(false)
7692
prompt_view_provider.send_message({
7793
command: 'SHOW_AUTO_CLOSING_MODAL',

0 commit comments

Comments
 (0)