Skip to content

Commit 1343eb0

Browse files
committed
Refactor output channel handling and improve file restore preview logic
- when applying changes, always print the markdown response that is being applied to the output channel but not focus on it (focus only when unable to apply - keep current behavior) - Broken flow with a file rename: apply from clipboard -> 'go back' -> apply from response history -> 'go back' result: file is restored but its content not. - Broken flow with a file rename: apply from clipboard -> 'go back' -> apply from response history -> we get a notification [Pasted text], and need to click its button "Overwrite" ├── apps │ └── editor │ └── src │ ├── commands │ │ └── apply-from-clipboard-command.ts │ ├── constants │ │ └── state-keys.ts │ ├── extension.ts │ ├── features │ │ └── apply-response │ │ ├── apply-response.ts │ │ ├── response-processor │ │ │ ├── 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 │ │ │ ├── apply-file-relocations.ts │ │ │ ├── prepare-rename-operation.ts │ │ │ ├── relocate-file.ts │ │ │ └── undo-files.ts │ │ ├── preview │ │ │ └── build-history-files.ts │ │ ├── preview-handler.ts │ │ ├── response-parser │ │ │ ├── parsers │ │ │ │ ├── diff-parser │ │ │ │ │ └── diff-parser.ts │ │ │ │ └── standard-parser │ │ │ │ └── standard-parser.ts │ │ │ └── response-parser.ts │ │ └── state-manager.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-apply-response-from-history.ts │ │ │ └── handle-undo.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-response-history.ts │ └── types │ └── messages.ts └── packages └── shared └── src └── types ├── file-in-preview.ts └── response-history-item.ts
1 parent dfc68f6 commit 1343eb0

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎apps/editor/src/features/apply-response/apply-response.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
preview_handler,
1515
ongoing_preview_cleanup_promise
1616
} from './utils/preview-handler'
17-
import { process_response, ApplyResponseArgs } from './response-processor'
17+
import {
18+
process_response,
19+
ApplyResponseArgs,
20+
get_apply_response_output_channel
21+
} from './response-processor'
1822
import { ResponseHistoryItem } from '@shared/types/response-history-item'
1923
import { PromptViewApiCallsManager } from '@/services/prompt-view-api-calls-manager'
2024
import { t } from '@/i18n'
@@ -366,6 +370,10 @@ export const setup_apply_response = (params: {
366370
}
367371
}
368372

373+
const output_channel = get_apply_response_output_channel()
374+
output_channel.clear()
375+
output_channel.append(response)
376+
369377
in_progress = true
370378
} catch (err) {
371379
params.prompt_view_provider.send_message({ command: 'HIDE_PROGRESS' })

‎apps/editor/src/features/apply-response/response-processor/handlers/restore-preview-handler.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export const handle_restore_preview = async (
5656
}
5757

5858
for (const file of files) {
59+
const file_key = `${file.workspace_name ?? ''}:${file.file_path}`
60+
if (file.file_state === 'deleted' && rename_sources.has(file_key)) {
61+
continue
62+
}
63+
5964
const workspace_root = resolve_workspace_root({
6065
workspace_name: file.workspace_name,
6166
workspace_map,
@@ -118,9 +123,11 @@ export const handle_restore_preview = async (
118123
file_state:
119124
file.file_state === 'deleted'
120125
? 'deleted'
121-
: !file_exists
122-
? 'new'
123-
: file.file_state,
126+
: file.renamed_from
127+
? undefined
128+
: !file_exists
129+
? 'new'
130+
: file.file_state,
124131
is_checked: file.is_checked,
125132
diff_application_method: file.diff_application_method,
126133
is_pure_rename: file.is_pure_rename,
@@ -145,24 +152,21 @@ export const handle_restore_preview = async (
145152

146153
if (!file.is_pure_rename && file.content !== undefined) {
147154
const file_uri = vscode.Uri.file(safe_path)
148-
const document = await vscode.workspace.openTextDocument(file_uri)
149155
const final_content = preserve_trailing_newline(
150156
original_content,
151157
file.content
152158
)
153-
await replace_document_content(document, final_content)
159+
await vscode.workspace.fs.writeFile(
160+
file_uri,
161+
new Uint8Array(Buffer.from(final_content, 'utf8'))
162+
)
154163
Logger.info({
155164
function_name: 'handle_restore_preview',
156165
message: 'Existing file replaced and saved after relocation',
157166
data: safe_path
158167
})
159168
}
160169
} else if (file.file_state === 'deleted') {
161-
const file_key = `${file.workspace_name ?? ''}:${file.file_path}`
162-
if (rename_sources.has(file_key)) {
163-
continue
164-
}
165-
166170
if (file_exists) {
167171
try {
168172
await close_file_tabs(safe_path)

‎apps/editor/src/features/apply-response/response-processor/response-processor.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040

4141
let _apply_response_output_channel: vscode.OutputChannel | undefined
4242

43-
const get_apply_response_output_channel = () => {
43+
export const get_apply_response_output_channel = () => {
4444
if (!_apply_response_output_channel) {
4545
_apply_response_output_channel =
4646
vscode.window.createOutputChannel('CWC Apply Response')
@@ -405,8 +405,6 @@ export const process_response = async (params: {
405405
)
406406

407407
const output_channel = get_apply_response_output_channel()
408-
output_channel.clear()
409-
output_channel.append(params.response)
410408
output_channel.show(true)
411409

412410
return null

0 commit comments

Comments
 (0)