Skip to content

Commit e9a87ad

Browse files
committed
Replace native QuickPick with a webview modal for relevant file selection and introduce an action-based auto-closing modal
- create a modal for accepting 'relevant files', so that quick pick is no longer used. - for 'relevant files' use modal instead of the quick pick - instead of [Fragment] we want to show a new modal inspired by "auto closing modal" (create new) with 2 buttons: [Close] [Edit context] (edit context is a default action that auto-runs once timeout finishes)
1 parent 8e70789 commit e9a87ad

13 files changed

Lines changed: 542 additions & 121 deletions

File tree

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

Lines changed: 54 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
} from './utils/clipboard-parser'
1313
import { create_safe_path } from '@/utils/path-sanitizer'
1414
import { dictionary } from '@shared/constants/dictionary'
15-
import { display_token_count } from '../../utils/display-token-count'
1615
import { Logger } from '@shared/utils/logger'
1716
import { apply_git_patch } from './handlers/diff-handler'
1817
import { apply_file_relocations } from './utils/file-operations'
@@ -116,164 +115,100 @@ export const process_chat_response = async (
116115
(item) => item.type == 'relevant-files'
117116
) as RelevantFilesItem
118117

119-
panel_provider.send_message({
120-
command: 'SHOW_PROGRESS',
121-
title: 'Waiting for confirmation...'
122-
})
123-
124118
const current_checked_files =
125119
workspace_provider.get_export_state().regular.checked_files
126120

127121
const workspace_roots = workspace_provider.get_workspace_roots()
128122
const all_paths_to_process = new Set<string>(relevant_files_item.file_paths)
129123

130-
const open_file_button = {
131-
iconPath: new vscode.ThemeIcon('go-to-file'),
132-
tooltip: t('common.go-to-file')
133-
}
134-
135-
const quick_pick_items = await Promise.all(
136-
Array.from(all_paths_to_process).map(async (rel_path) => {
137-
let absolute_path: string | undefined
138-
for (const root of workspace_roots) {
139-
const potential = path.join(root, rel_path)
140-
if (fs.existsSync(potential)) {
141-
absolute_path = potential
142-
break
124+
const files_for_modal = (
125+
await Promise.all(
126+
Array.from(all_paths_to_process).map(async (rel_path) => {
127+
let absolute_path: string | undefined
128+
for (const root of workspace_roots) {
129+
const potential = path.join(root, rel_path)
130+
if (fs.existsSync(potential)) {
131+
absolute_path = potential
132+
break
133+
}
143134
}
144-
}
145-
146-
let token_info = ''
147-
if (absolute_path) {
148-
const count =
149-
await workspace_provider.calculate_file_tokens(absolute_path)
150-
token_info = display_token_count(count.total)
151-
}
152135

153-
const dir_name = path.dirname(rel_path)
154-
const display_dir = dir_name === '.' ? '' : dir_name
136+
let token_count: number | undefined
137+
if (absolute_path) {
138+
const count =
139+
await workspace_provider.calculate_file_tokens(absolute_path)
140+
token_count = count.total
141+
}
155142

156-
return {
157-
label: path.basename(rel_path),
158-
description: display_dir
159-
? `${token_info} · ${display_dir}`
160-
: token_info,
161-
picked: true,
162-
file_path: absolute_path,
163-
relative_path: rel_path,
164-
buttons: [open_file_button]
165-
}
166-
})
143+
return {
144+
file_path: absolute_path,
145+
relative_path: rel_path,
146+
token_count
147+
}
148+
})
149+
)
150+
).filter(
151+
(
152+
f
153+
): f is {
154+
file_path: string
155+
relative_path: string
156+
token_count: number
157+
} => !!f.file_path
167158
)
168159

169-
quick_pick_items.sort((a, b) =>
160+
files_for_modal.sort((a, b) =>
170161
natural_sort(a.relative_path, b.relative_path)
171162
)
172163

173-
const quick_pick =
174-
vscode.window.createQuickPick<(typeof quick_pick_items)[0]>()
175-
quick_pick.items = quick_pick_items
176-
quick_pick.selectedItems = quick_pick_items.filter((i) => i.picked)
177-
quick_pick.canSelectMany = true
178-
quick_pick.title = t('command.apply-chat-response.relevant-files.title')
179-
quick_pick.placeholder = t(
180-
'command.apply-chat-response.relevant-files.placeholder'
181-
)
182-
quick_pick.ignoreFocusOut = true
183-
184-
const close_button = {
185-
iconPath: new vscode.ThemeIcon('close'),
186-
tooltip: t('common.close')
187-
}
188-
quick_pick.buttons = [close_button]
189-
190-
const selected_items = await new Promise<
191-
readonly (typeof quick_pick_items)[0][] | undefined
192-
>((resolve) => {
193-
let is_accepted = false
194-
const disposables: vscode.Disposable[] = []
195-
196-
disposables.push(
197-
quick_pick.onDidTriggerButton((button) => {
198-
if (button === close_button) {
199-
quick_pick.hide()
200-
resolve(undefined)
201-
}
202-
}),
203-
quick_pick.onDidTriggerItemButton(async (e) => {
204-
if (e.button === open_file_button && e.item.file_path) {
205-
try {
206-
const doc = await vscode.workspace.openTextDocument(
207-
e.item.file_path
208-
)
209-
await vscode.window.showTextDocument(doc, { preview: true })
210-
} catch (error) {
211-
vscode.window.showErrorMessage(
212-
t('command.context.check-references.error-opening', {
213-
error: String(error)
214-
})
215-
)
216-
}
217-
}
218-
}),
219-
quick_pick.onDidAccept(() => {
220-
is_accepted = true
221-
resolve([...quick_pick.selectedItems])
222-
quick_pick.hide()
223-
}),
224-
quick_pick.onDidHide(() => {
225-
if (!is_accepted) {
226-
resolve(undefined)
227-
}
228-
disposables.forEach((d) => d.dispose())
229-
quick_pick.dispose()
230-
})
231-
)
232-
quick_pick.show()
164+
panel_provider.send_message({
165+
command: 'SHOW_RELEVANT_FILES_MODAL',
166+
files: files_for_modal
233167
})
234168

235-
if (selected_items) {
236-
const files_to_check: string[] = []
237-
238-
for (const selection of selected_items) {
239-
if (selection.file_path) {
240-
files_to_check.push(selection.file_path)
241-
}
242-
}
243-
244-
const presented_files: string[] = []
245-
for (const item of quick_pick_items) {
246-
if (item.file_path) {
247-
presented_files.push(item.file_path)
248-
}
169+
const selected_files = await new Promise<string[] | undefined>(
170+
(resolve) => {
171+
panel_provider.relevant_files_choice_resolver = resolve
249172
}
173+
)
250174

175+
if (selected_files) {
251176
const shared_state = SharedFileState.get_instance()
252177
const was_frf = workspace_provider.is_frf_mode
253178

254179
if (was_frf) {
255180
shared_state.switch_context_state(false)
256181
}
257182

183+
const presented_files = files_for_modal.map((f) => f.file_path)
184+
258185
const filtered_current_files = current_checked_files.filter(
259186
(f) => !presented_files.includes(f)
260187
)
261188

262189
const merged_files = Array.from(
263-
new Set([...filtered_current_files, ...files_to_check])
190+
new Set([...filtered_current_files, ...selected_files])
264191
)
265192
await workspace_provider.set_checked_files(merged_files)
266193

267194
if (was_frf) {
268195
shared_state.switch_context_state(true)
269-
await panel_provider.switch_to_edit_context()
270196
}
271197

272198
panel_provider.send_message({
273-
command: 'SHOW_AUTO_CLOSING_MODAL',
199+
command: 'SHOW_AUTO_CLOSING_WITH_ACTIONS_MODAL',
274200
title: t('command.apply-chat-response.relevant-files.success'),
275-
type: 'success'
201+
type: 'success',
202+
action_label: 'Edit context'
276203
})
204+
205+
const action = await new Promise<'action' | 'close'>((resolve) => {
206+
panel_provider.auto_closing_action_resolver = resolve
207+
})
208+
209+
if (action == 'action') {
210+
await panel_provider.switch_to_edit_context()
211+
}
277212
}
278213

279214
return null

‎apps/editor/src/views/panel/backend/panel-provider.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ export class PanelProvider implements vscode.WebviewViewProvider {
186186
public audio_chunks: Buffer[] = []
187187
public recording_start_time: number = 0
188188

189+
public relevant_files_choice_resolver:
190+
| ((files: string[] | undefined) => void)
191+
| undefined = undefined
192+
public auto_closing_action_resolver:
193+
| ((action: 'action' | 'close') => void)
194+
| undefined = undefined
195+
189196
public get current_ask_about_context_instruction(): string {
190197
return (
191198
this.ask_about_context_instructions.instructions[
@@ -1019,6 +1026,18 @@ export class PanelProvider implements vscode.WebviewViewProvider {
10191026
this,
10201027
message.shrink_source_code
10211028
)
1029+
} else if (message.command == 'RELEVANT_FILES_MODAL_RESPONSE') {
1030+
if (this.relevant_files_choice_resolver) {
1031+
this.relevant_files_choice_resolver(message.files)
1032+
this.relevant_files_choice_resolver = undefined
1033+
}
1034+
} else if (
1035+
message.command == 'AUTO_CLOSING_WITH_ACTIONS_MODAL_RESPONSE'
1036+
) {
1037+
if (this.auto_closing_action_resolver) {
1038+
this.auto_closing_action_resolver(message.action)
1039+
this.auto_closing_action_resolver = undefined
1040+
}
10221041
}
10231042
} catch (error: any) {
10241043
Logger.error({

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { Modal as UiModal } from '@ui/components/editor/panel/modals/Modal'
1414
import { ProgressModal as UiProgressModal } from '@ui/components/editor/panel/modals/ProgressModal'
1515
import { ApiManagerModal as UiApiManagerModal } from '@ui/components/editor/panel/modals/ApiManagerModal'
1616
import { QRCodeModal as UiQRCodeModal } from '@ui/components/editor/panel/modals/QRCodeModal'
17+
import { RelevantFilesModal as UiRelevantFilesModal } from '@ui/components/editor/panel/modals/RelevantFilesModal'
1718
import { AutoClosingModal as UiAutoClosingModal } from '@ui/components/editor/panel/modals/AutoClosingModal'
19+
import { AutoClosingWithActionsModal as UiAutoClosingWithActionsModal } from '@ui/components/editor/panel/modals/AutoClosingWithActionsModal'
1820
import { EditCheckpointDescriptionModal as UiEditCheckpointDescriptionModal } from '@ui/components/editor/panel/modals/EditCheckpointDescriptionModal'
1921
import { use_panel } from './hooks/panel/use-panel'
2022
import { FileInPreview } from '@shared/types/file-in-preview'
@@ -139,8 +141,12 @@ export const Panel = () => {
139141
api_manager_progress_state,
140142
auto_closing_modal_data,
141143
set_auto_closing_modal_data,
144+
auto_closing_with_actions_modal_data,
145+
set_auto_closing_with_actions_modal_data,
142146
is_preview_ongoing_modal_visible,
143-
set_is_preview_ongoing_modal_visible
147+
set_is_preview_ongoing_modal_visible,
148+
relevant_files_modal_data,
149+
set_relevant_files_modal_data
144150
} = use_modal_manager()
145151

146152
const [checkpoint_to_edit, set_checkpoint_to_edit] = useState<
@@ -803,6 +809,34 @@ export const Panel = () => {
803809
</div>
804810
)}
805811

812+
{relevant_files_modal_data && (
813+
<div className={styles.slot}>
814+
<UiRelevantFilesModal
815+
files={relevant_files_modal_data.files}
816+
on_accept={(files) => {
817+
post_message(vscode, {
818+
command: 'RELEVANT_FILES_MODAL_RESPONSE',
819+
files
820+
})
821+
set_relevant_files_modal_data(undefined)
822+
}}
823+
on_cancel={() => {
824+
post_message(vscode, {
825+
command: 'RELEVANT_FILES_MODAL_RESPONSE',
826+
files: undefined
827+
})
828+
set_relevant_files_modal_data(undefined)
829+
}}
830+
on_go_to_file={(file_path) => {
831+
post_message(vscode, {
832+
command: 'OPEN_FILE_AND_SELECT',
833+
file_path
834+
})
835+
}}
836+
/>
837+
</div>
838+
)}
839+
806840
{active_qr_wallet && (
807841
<div className={styles.slot}>
808842
<UiQRCodeModal
@@ -826,6 +860,31 @@ export const Panel = () => {
826860
</div>
827861
)}
828862

863+
{auto_closing_with_actions_modal_data && (
864+
<div className={styles.slot}>
865+
<UiAutoClosingWithActionsModal
866+
title={auto_closing_with_actions_modal_data.title}
867+
type={auto_closing_with_actions_modal_data.type}
868+
duration={3000}
869+
action_label={auto_closing_with_actions_modal_data.action_label}
870+
on_action={() => {
871+
post_message(vscode, {
872+
command: 'AUTO_CLOSING_WITH_ACTIONS_MODAL_RESPONSE',
873+
action: 'action'
874+
})
875+
set_auto_closing_with_actions_modal_data(undefined)
876+
}}
877+
on_close={() => {
878+
post_message(vscode, {
879+
command: 'AUTO_CLOSING_WITH_ACTIONS_MODAL_RESPONSE',
880+
action: 'close'
881+
})
882+
set_auto_closing_with_actions_modal_data(undefined)
883+
}}
884+
/>
885+
</div>
886+
)}
887+
829888
{checkpoint_to_edit && (
830889
<div className={styles.slot}>
831890
<UiEditCheckpointDescriptionModal

0 commit comments

Comments
 (0)