@@ -23,6 +23,76 @@ export const remove_file_from_context_command = (
2323 return
2424 }
2525
26+ const workspace_roots = workspace_provider . getWorkspaceRoots ( )
27+ let files_to_show = current_checked
28+ let show_workspace_prefix = workspace_roots . length > 1
29+
30+ if ( workspace_roots . length > 1 ) {
31+ const roots_with_checked_files = new Map < string , string [ ] > ( )
32+
33+ for ( const file_path of current_checked ) {
34+ const root = workspace_provider . get_workspace_root_for_file ( file_path )
35+ if ( root ) {
36+ if ( ! roots_with_checked_files . has ( root ) ) {
37+ roots_with_checked_files . set ( root , [ ] )
38+ }
39+ roots_with_checked_files . get ( root ) ! . push ( file_path )
40+ }
41+ }
42+
43+ const eligible_roots = Array . from ( roots_with_checked_files . keys ( ) )
44+
45+ if ( eligible_roots . length > 1 ) {
46+ const items : vscode . QuickPickItem [ ] = eligible_roots
47+ . map ( ( root ) => ( {
48+ label : workspace_provider . get_workspace_name ( root ) ,
49+ description : root
50+ } ) )
51+ . sort ( ( a , b ) => natural_sort ( a . label , b . label ) )
52+
53+ const selected = await new Promise < vscode . QuickPickItem | undefined > (
54+ ( resolve ) => {
55+ const quick_pick = vscode . window . createQuickPick ( )
56+ quick_pick . items = items
57+ quick_pick . placeholder =
58+ 'Select a workspace folder to remove files from'
59+ quick_pick . title = 'Workspace Folders'
60+ quick_pick . buttons = [
61+ {
62+ iconPath : new vscode . ThemeIcon ( 'close' ) ,
63+ tooltip : 'Close'
64+ }
65+ ]
66+
67+ quick_pick . onDidTriggerButton ( ( button ) => {
68+ if ( button . tooltip == 'Close' ) {
69+ quick_pick . hide ( )
70+ }
71+ } )
72+
73+ quick_pick . onDidAccept ( ( ) => {
74+ resolve ( quick_pick . selectedItems [ 0 ] )
75+ quick_pick . hide ( )
76+ } )
77+
78+ quick_pick . onDidHide ( ( ) => {
79+ resolve ( undefined )
80+ quick_pick . dispose ( )
81+ } )
82+
83+ quick_pick . show ( )
84+ }
85+ )
86+
87+ if ( ! selected || ! selected . description ) {
88+ return
89+ }
90+
91+ files_to_show = roots_with_checked_files . get ( selected . description ) !
92+ show_workspace_prefix = false
93+ }
94+ }
95+
2696 const quick_pick = vscode . window . createQuickPick < FileQuickPickItem > ( )
2797 quick_pick . title = 'Context Files'
2898 quick_pick . placeholder = 'Select a file to remove from context'
@@ -156,9 +226,7 @@ export const remove_file_from_context_command = (
156226 }
157227 } )
158228
159- const workspace_roots = workspace_provider . getWorkspaceRoots ( )
160-
161- const items : FileQuickPickItem [ ] = current_checked . map ( ( file_path ) => {
229+ const items : FileQuickPickItem [ ] = files_to_show . map ( ( file_path ) => {
162230 const workspace_root =
163231 workspace_provider . get_workspace_root_for_file ( file_path )
164232
@@ -174,7 +242,7 @@ export const remove_file_from_context_command = (
174242 directory = ''
175243 }
176244
177- if ( workspace_roots . length > 1 && workspace_root ) {
245+ if ( show_workspace_prefix && workspace_root ) {
178246 const workspace_name =
179247 workspace_provider . get_workspace_name ( workspace_root )
180248 directory = directory
0 commit comments