@@ -12,7 +12,6 @@ import {
1212} from './utils/clipboard-parser'
1313import { create_safe_path } from '@/utils/path-sanitizer'
1414import { dictionary } from '@shared/constants/dictionary'
15- import { display_token_count } from '../../utils/display-token-count'
1615import { Logger } from '@shared/utils/logger'
1716import { apply_git_patch } from './handlers/diff-handler'
1817import { 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
0 commit comments