@@ -11,6 +11,7 @@ import {
1111} from './utils/clipboard-parser'
1212import { create_safe_path } from '@/utils/path-sanitizer'
1313import { dictionary } from '@shared/constants/dictionary'
14+ import { display_token_count } from '../../utils/display-token-count'
1415import { Logger } from '@shared/utils/logger'
1516import { apply_git_patch } from './handlers/diff-handler'
1617import { apply_file_relocations } from './utils/file-operations'
@@ -110,14 +111,8 @@ export const process_chat_response = async (
110111 relevant_files_item . file_paths . map ( ( p ) => p . replace ( / \\ / g, '/' ) )
111112 )
112113
113- const quick_pick_items : {
114- label : string
115- picked : boolean
116- description ?: string
117- } [ ] = relevant_files_item . file_paths . map ( ( path ) => ( {
118- label : path ,
119- picked : true
120- } ) )
114+ const workspace_roots = workspace_provider . get_workspace_roots ( )
115+ const all_paths_to_process = new Set < string > ( relevant_files_item . file_paths )
121116
122117 for ( const file_path of current_checked_files ) {
123118 const workspace_root =
@@ -126,47 +121,102 @@ export const process_chat_response = async (
126121 const relative_path = path
127122 . relative ( workspace_root , file_path )
128123 . replace ( / \\ / g, '/' )
129- if ( ! relevant_paths_normalized . has ( relative_path ) ) {
130- if ( ! quick_pick_items . some ( ( item ) => item . label == relative_path ) ) {
131- quick_pick_items . push ( {
132- label : relative_path ,
133- picked : false
134- } )
135- }
136- }
124+ all_paths_to_process . add ( relative_path )
137125 }
138126 }
139127
140- quick_pick_items . sort ( ( a , b ) => natural_sort ( a . label , b . label ) )
128+ const open_file_button = {
129+ iconPath : new vscode . ThemeIcon ( 'go-to-file' ) ,
130+ tooltip : t ( 'common.go-to-file' )
131+ }
132+
133+ const quick_pick_items = await Promise . all (
134+ Array . from ( all_paths_to_process ) . map ( async ( rel_path ) => {
135+ let absolute_path : string | undefined
136+ for ( const root of workspace_roots ) {
137+ const potential = path . join ( root , rel_path )
138+ if ( fs . existsSync ( potential ) ) {
139+ absolute_path = potential
140+ break
141+ }
142+ }
143+
144+ let token_info = ''
145+ if ( absolute_path ) {
146+ const count =
147+ await workspace_provider . calculate_file_tokens ( absolute_path )
148+ token_info = display_token_count ( count . total )
149+ }
141150
142- const quick_pick = vscode . window . createQuickPick ( )
151+ const dir_name = path . dirname ( rel_path )
152+ const display_dir = dir_name === '.' ? '' : dir_name
153+
154+ return {
155+ label : path . basename ( rel_path ) ,
156+ description : display_dir
157+ ? `${ token_info } · ${ display_dir } `
158+ : token_info ,
159+ picked : relevant_paths_normalized . has ( rel_path ) ,
160+ file_path : absolute_path ,
161+ relative_path : rel_path ,
162+ buttons : [ open_file_button ]
163+ }
164+ } )
165+ )
166+
167+ quick_pick_items . sort ( ( a , b ) =>
168+ natural_sort ( a . relative_path , b . relative_path )
169+ )
170+
171+ const quick_pick =
172+ vscode . window . createQuickPick < ( typeof quick_pick_items ) [ 0 ] > ( )
143173 quick_pick . items = quick_pick_items
144174 quick_pick . selectedItems = quick_pick_items . filter ( ( i ) => i . picked )
145175 quick_pick . canSelectMany = true
146176 quick_pick . title = t ( 'command.apply-chat-response.context-pruning.title' )
147177 quick_pick . placeholder = t (
148178 'command.apply-chat-response.context-pruning.placeholder'
149179 )
150- quick_pick . buttons = [
151- { iconPath : new vscode . ThemeIcon ( 'close' ) , tooltip : t ( 'common.close' ) }
152- ]
180+ quick_pick . ignoreFocusOut = true
181+
182+ const close_button = {
183+ iconPath : new vscode . ThemeIcon ( 'close' ) ,
184+ tooltip : t ( 'common.close' )
185+ }
186+ quick_pick . buttons = [ close_button ]
153187
154188 const selected_items = await new Promise <
155- readonly vscode . QuickPickItem [ ] | undefined
189+ readonly ( typeof quick_pick_items ) [ 0 ] [ ] | undefined
156190 > ( ( resolve ) => {
157191 let is_accepted = false
158192 const disposables : vscode . Disposable [ ] = [ ]
159193
160194 disposables . push (
161195 quick_pick . onDidTriggerButton ( ( button ) => {
162- if ( button . tooltip == 'Close' ) {
196+ if ( button === close_button ) {
163197 quick_pick . hide ( )
164198 resolve ( undefined )
165199 }
166200 } ) ,
201+ quick_pick . onDidTriggerItemButton ( async ( e ) => {
202+ if ( e . button === open_file_button && e . item . file_path ) {
203+ try {
204+ const doc = await vscode . workspace . openTextDocument (
205+ e . item . file_path
206+ )
207+ await vscode . window . showTextDocument ( doc , { preview : true } )
208+ } catch ( error ) {
209+ vscode . window . showErrorMessage (
210+ t ( 'command.context.check-references.error-opening' , {
211+ error : String ( error )
212+ } )
213+ )
214+ }
215+ }
216+ } ) ,
167217 quick_pick . onDidAccept ( ( ) => {
168218 is_accepted = true
169- resolve ( quick_pick . selectedItems )
219+ resolve ( [ ... quick_pick . selectedItems ] )
170220 quick_pick . hide ( )
171221 } ) ,
172222 quick_pick . onDidHide ( ( ) => {
@@ -181,16 +231,11 @@ export const process_chat_response = async (
181231 } )
182232
183233 if ( selected_items && selected_items . length > 0 ) {
184- const workspace_roots = workspace_provider . get_workspace_roots ( )
185234 const files_to_check : string [ ] = [ ]
186235
187236 for ( const selection of selected_items ) {
188- for ( const root of workspace_roots ) {
189- const potential_path = path . join ( root , selection . label )
190- if ( fs . existsSync ( potential_path ) ) {
191- files_to_check . push ( potential_path )
192- break
193- }
237+ if ( selection . file_path ) {
238+ files_to_check . push ( selection . file_path )
194239 }
195240 }
196241
0 commit comments