@@ -5,12 +5,16 @@ import { WorkspaceProvider } from '../../../context/providers/workspace/workspac
55import { resolve_context_paths } from './resolve-context-paths'
66import { t } from '@/i18n'
77import { display_token_count } from '@shared/utils/display-token-count'
8+ import { search_files } from '@/features/search-files'
9+ import { WebSocketManager } from '@/services/websocket-manager'
810
911let active_deletion_timestamp : number | undefined
1012
1113export const select_context_paths = async ( params : {
1214 context : SavedContext
1315 workspace_provider : WorkspaceProvider
16+ extension_context : vscode . ExtensionContext
17+ websocket_manager : WebSocketManager
1418 update_context_paths ?: ( remaining_files : string [ ] ) => Promise < void >
1519} ) : Promise < 'back' | void > => {
1620 const primary_workspace_root =
@@ -26,6 +30,13 @@ export const select_context_paths = async (params: {
2630 tooltip : t ( 'common.delete' )
2731 }
2832
33+ const search_button = {
34+ iconPath : new vscode . ThemeIcon ( 'search' ) ,
35+ tooltip : t ( 'common.search-in-selected-results' )
36+ }
37+
38+ let restored_selected_paths : Set < string > | undefined
39+
2940 while ( true ) {
3041 const create_quick_pick_items = async ( local_params : {
3142 paths : string [ ]
@@ -51,7 +62,7 @@ export const select_context_paths = async (params: {
5162 const buttons : vscode . QuickInputButton [ ] = [
5263 {
5364 iconPath : new vscode . ThemeIcon ( 'go-to-file' ) ,
54- tooltip : 'Go to file'
65+ tooltip : t ( 'common.go-to- file')
5566 }
5667 ]
5768
@@ -74,9 +85,12 @@ export const select_context_paths = async (params: {
7485 }
7586
7687 const quick_pick_items = await create_quick_pick_items ( {
77- paths : resolved_paths
88+ paths : resolved_paths ,
89+ selected_paths_override : restored_selected_paths
7890 } )
7991
92+ restored_selected_paths = undefined
93+
8094 const list_quick_pick = vscode . window . createQuickPick <
8195 vscode . QuickPickItem & { file_path : string ; token_count : number }
8296 > ( )
@@ -92,19 +106,24 @@ export const select_context_paths = async (params: {
92106 0
93107 )
94108 const total_text =
95- total > 0 ? ` (totalling ${ display_token_count ( total ) } tokens)` : ''
109+ total > 0
110+ ? ` (${ t ( 'common.totalling-tokens' , {
111+ tokens : display_token_count ( total )
112+ } ) } )`
113+ : ''
96114 list_quick_pick . placeholder = `Select files to apply to context${ total_text } `
97115 }
98116 update_placeholder ( )
99117 list_quick_pick . onDidChangeSelection ( update_placeholder )
100- list_quick_pick . buttons = [ vscode . QuickInputButtons . Back ]
118+ list_quick_pick . buttons = [ vscode . QuickInputButtons . Back , search_button ]
101119
102120 const list_selection = await new Promise <
103121 | readonly ( vscode . QuickPickItem & {
104122 file_path : string
105123 token_count : number
106124 } ) [ ]
107125 | 'back'
126+ | { search : string [ ] }
108127 | undefined
109128 > ( ( resolve ) => {
110129 let is_resolved = false
@@ -119,11 +138,26 @@ export const select_context_paths = async (params: {
119138 if ( button === vscode . QuickInputButtons . Back ) {
120139 list_quick_pick . hide ( )
121140 resolve_once ( 'back' )
141+ } else if ( button === search_button ) {
142+ const selected_paths = list_quick_pick . selectedItems . map (
143+ ( i ) => i . file_path
144+ )
145+ if ( selected_paths . length === 0 ) {
146+ vscode . window . showInformationMessage (
147+ t ( 'common.info.select-files-to-search' )
148+ )
149+ return
150+ }
151+ list_quick_pick . hide ( )
152+ resolve_once ( { search : selected_paths } )
122153 }
123154 } )
124155
125156 list_quick_pick . onDidTriggerItemButton ( async ( e ) => {
126- if ( e . button . tooltip === 'Go to file' ) {
157+ if (
158+ e . button . tooltip === 'Go to file' ||
159+ e . button . tooltip === t ( 'common.go-to-file' )
160+ ) {
127161 const uri = vscode . Uri . file ( e . item . file_path )
128162 vscode . window . showTextDocument ( uri , {
129163 preview : true ,
@@ -204,6 +238,37 @@ export const select_context_paths = async (params: {
204238 if ( ! list_selection ) return undefined
205239 if ( list_selection === 'back' ) return 'back'
206240
241+ if ( ! Array . isArray ( list_selection ) && 'search' in list_selection ) {
242+ const search_result = await search_files ( {
243+ get_files : async ( ) => list_selection . search ,
244+ workspace_provider : params . workspace_provider ,
245+ extension_context : params . extension_context ,
246+ websocket_manager : params . websocket_manager ,
247+ show_back_button : true ,
248+ is_sub_search : true
249+ } )
250+
251+ if ( search_result === 'back' ) {
252+ restored_selected_paths = new Set ( list_selection . search )
253+ continue
254+ }
255+
256+ if ( ! search_result ) {
257+ return undefined
258+ }
259+
260+ const select_paths_set = new Set ( resolved_paths )
261+ const current_selected_files =
262+ params . workspace_provider . get_selected_files ( )
263+ const final_selected = current_selected_files
264+ . filter ( ( p ) => ! select_paths_set . has ( p ) )
265+ . concat ( search_result . selected_paths )
266+ await params . workspace_provider . set_selected_files ( [
267+ ...new Set ( final_selected )
268+ ] )
269+ return undefined
270+ }
271+
207272 if ( Array . isArray ( list_selection ) ) {
208273 const new_selected = list_selection . map ( ( i ) => i . file_path )
209274 const select_paths_set = new Set ( resolved_paths )
0 commit comments