Skip to content

Commit 057d0bf

Browse files
committed
Replace boolean is_new/is_deleted flags with a single file_state enum in file preview types and update all related code
1 parent 9556c1c commit 057d0bf

11 files changed

Lines changed: 54 additions & 53 deletions

File tree

‎packages/shared/src/types/file-in-preview.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export type FileInPreview = {
33
file_path: string
44
is_checked: boolean
55
workspace_name?: string
6-
is_new?: boolean
7-
is_deleted?: boolean
6+
file_state?: 'new' | 'deleted'
87
lines_added: number
98
lines_removed: number
109
is_replaced?: boolean

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ export const ResponsePreview: FC<Props> = (props) => {
163163
/>
164164
<div
165165
className={cn(styles['list__file__left__label'], {
166-
[styles['list__file__left__label--new']]: file.is_new,
166+
[styles['list__file__left__label--new']]:
167+
file.file_state == 'new',
167168
[styles['list__file__left__label--deleted']]:
168-
file.is_deleted
169+
file.file_state == 'deleted'
169170
})}
170171
>
171172
<span>
@@ -217,7 +218,7 @@ export const ResponsePreview: FC<Props> = (props) => {
217218
}}
218219
/>
219220
</div>
220-
{!file.is_deleted && (
221+
{file.file_state != 'deleted' && (
221222
<div className={styles['list__file__line-numbers']}>
222223
<span
223224
className={styles['list__file__line-numbers__added']}

‎packages/vscode/src/commands/apply-chat-response-command/apply-chat-response-command.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,20 @@ export const apply_chat_response_command = (params: {
192192
total_lines_removed += diff_stats.lines_removed
193193

194194
const is_deleted =
195-
!state.is_new && current_content === '' && state.content !== ''
195+
state.file_state != 'new' &&
196+
current_content == '' &&
197+
state.content != ''
196198

197199
files_for_history.push({
198200
type: 'file',
199201
file_path: state.file_path,
200202
workspace_name: state.workspace_name,
201-
is_new: state.is_new,
202-
is_deleted,
203+
file_state:
204+
state.file_state == 'new'
205+
? 'new'
206+
: is_deleted
207+
? 'deleted'
208+
: undefined,
203209
lines_added: diff_stats.lines_added,
204210
lines_removed: diff_stats.lines_removed,
205211
is_replaced: state.is_replaced,

‎packages/vscode/src/commands/apply-chat-response-command/handlers/diff-handler.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export const store_original_file_states = async (
124124
original_states.push({
125125
file_path,
126126
content,
127-
is_new: false,
128127
workspace_name: path.basename(workspace_path)
129128
})
130129
} catch (error) {
@@ -138,7 +137,7 @@ export const store_original_file_states = async (
138137
original_states.push({
139138
file_path,
140139
content: '',
141-
is_new: true,
140+
file_state: 'new',
142141
workspace_name: path.basename(workspace_path)
143142
})
144143
}

‎packages/vscode/src/commands/apply-chat-response-command/handlers/fast-replace-handler.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ export const handle_fast_replace = async (
110110
original_states.push({
111111
file_path: file.file_path,
112112
content: original_content,
113-
is_new: false,
114113
workspace_name: file.workspace_name,
115-
is_deleted: true
114+
file_state: 'deleted'
116115
})
117116

118117
const tabs_to_close: vscode.Tab[] = []
@@ -148,7 +147,6 @@ export const handle_fast_replace = async (
148147
original_states.push({
149148
file_path: file.file_path,
150149
content: original_content,
151-
is_new: false,
152150
workspace_name: file.workspace_name
153151
})
154152
const editor = await vscode.window.showTextDocument(document)
@@ -180,7 +178,7 @@ export const handle_fast_replace = async (
180178
original_states.push({
181179
file_path: file.file_path,
182180
content: '',
183-
is_new: true,
181+
file_state: 'new',
184182
workspace_name: file.workspace_name
185183
})
186184
if (file.content == '') {

‎packages/vscode/src/commands/apply-chat-response-command/handlers/intelligent-update-handler.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export const handle_intelligent_update = async (params: {
203203
original_states.push({
204204
file_path: file.file_path,
205205
content: current_content,
206-
is_new: false,
207206
workspace_name: file.workspace_name
208207
})
209208
} catch (error) {
@@ -219,7 +218,7 @@ export const handle_intelligent_update = async (params: {
219218
original_states.push({
220219
file_path: file.file_path,
221220
content: '',
222-
is_new: true,
221+
file_state: 'new',
223222
workspace_name: file.workspace_name
224223
})
225224
}
@@ -270,7 +269,7 @@ export const handle_intelligent_update = async (params: {
270269
(s) =>
271270
s.file_path == file.file_path &&
272271
s.workspace_name == file.workspace_name &&
273-
!s.is_new
272+
s.file_state != 'new'
274273
)
275274
const original_content_for_api = original_state
276275
? original_state.content

‎packages/vscode/src/commands/apply-chat-response-command/handlers/restore-preview-handler.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@ export const handle_restore_preview = async (
7979
original_states.push({
8080
file_path: file.file_path,
8181
content: original_content,
82-
is_new: !file_exists,
8382
workspace_name: file.workspace_name,
84-
is_deleted: file.is_deleted,
83+
file_state:
84+
file.file_state == 'deleted'
85+
? 'deleted'
86+
: !file_exists
87+
? 'new'
88+
: file.file_state,
8589
is_checked: file.is_checked,
8690
is_replaced: file.is_replaced,
8791
diff_application_method: file.diff_application_method
8892
})
8993

9094
if (file.is_checked !== false) {
91-
if (file.is_deleted) {
95+
if (file.file_state == 'deleted') {
9296
if (file_exists) {
9397
try {
9498
const tabs_to_close: vscode.Tab[] = []
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
export type OriginalFileState = {
22
file_path: string
33
content: string
4-
is_new?: boolean
54
workspace_name?: string
65
cursor_offset?: number
76
new_file_path?: string
87
file_path_to_restore?: string
98
diff_application_method?: 'recount' | 'search_and_replace'
109
is_replaced?: boolean
11-
is_deleted?: boolean
10+
file_state?: 'new' | 'deleted'
1211
is_checked?: boolean
1312
ai_content?: string
1413
}

‎packages/vscode/src/commands/apply-chat-response-command/utils/file-operations.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export const undo_files = async (params: {
342342
}
343343
let file_uri = vscode.Uri.file(safe_path)
344344

345-
if (state.is_new && !state.file_path_to_restore) {
345+
if (state.file_state == 'new' && !state.file_path_to_restore) {
346346
if (await uri_exists(file_uri)) {
347347
// Close any open editors for this file before deleting
348348
const text_editors = vscode.window.visibleTextEditors.filter(

‎packages/vscode/src/commands/apply-chat-response-command/utils/preview/file-preparer.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,21 @@ export const prepare_files_from_original_states = async (params: {
6161
new_content: new_content_for_diff
6262
})
6363
const is_deleted =
64-
state.is_deleted ||
65-
(!state.is_new && current_content == '' && state.content != '')
64+
state.file_state == 'deleted' ||
65+
(state.file_state != 'new' &&
66+
current_content == '' &&
67+
state.content != '')
6668

6769
const reviewable_file: ReviewableFile = {
6870
type: 'file',
6971
file_path: state.file_path,
7072
content: current_content,
7173
workspace_name: state.workspace_name,
72-
is_new: state.is_new || !!state.file_path_to_restore,
73-
is_deleted,
74+
file_state: is_deleted
75+
? 'deleted'
76+
: state.file_state == 'new' || !!state.file_path_to_restore
77+
? 'new'
78+
: undefined,
7479
lines_added: diff_stats.lines_added,
7580
lines_removed: diff_stats.lines_removed,
7681
is_replaced: state.is_replaced,
@@ -83,7 +88,7 @@ export const prepare_files_from_original_states = async (params: {
8388
sanitized_path: sanitized_file_path,
8489
original_content: state.content,
8590
temp_file_path,
86-
file_exists: !state.is_new
91+
file_exists: state.file_state !== 'new'
8792
})
8893

8994
if (state.file_path_to_restore) {
@@ -117,8 +122,7 @@ export const prepare_files_from_original_states = async (params: {
117122
file_path: state.file_path_to_restore,
118123
content: restored_current_content,
119124
workspace_name: state.workspace_name,
120-
is_new: false,
121-
is_deleted: true,
125+
file_state: 'deleted',
122126
lines_added: restored_diff_stats.lines_added,
123127
lines_removed: restored_diff_stats.lines_removed,
124128
is_checked: state.is_checked ?? true

0 commit comments

Comments
 (0)