@@ -115,57 +115,54 @@ export const preview_handler = async (params: {
115115 } )
116116 }
117117
118- if ( params . raw_instructions ) {
119- const workspace_map = new Map < string , string > ( )
120- vscode . workspace . workspaceFolders ?. forEach ( ( folder ) => {
121- workspace_map . set ( folder . name , folder . uri . fsPath )
122- } )
123- const default_workspace =
124- vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
125-
126- const files_by_workspace = new Map < string , string [ ] > ( )
127- for ( const state of accepted_states ) {
128- let workspace_root = default_workspace
129- if ( state . workspace_name && workspace_map . has ( state . workspace_name ) ) {
130- workspace_root = workspace_map . get ( state . workspace_name ) !
131- }
132- if ( workspace_root ) {
133- const current_files = files_by_workspace . get ( workspace_root ) || [ ]
134- if ( ! current_files . includes ( state . file_path ) ) {
135- current_files . push ( state . file_path )
136- }
137- files_by_workspace . set ( workspace_root , current_files )
138- }
118+ const workspace_map = new Map < string , string > ( )
119+ vscode . workspace . workspaceFolders ?. forEach ( ( folder ) => {
120+ workspace_map . set ( folder . name , folder . uri . fsPath )
121+ } )
122+ const default_workspace =
123+ vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
124+
125+ const files_by_workspace = new Map < string , string [ ] > ( )
126+ for ( const state of accepted_states ) {
127+ let workspace_root = default_workspace
128+ if ( state . workspace_name && workspace_map . has ( state . workspace_name ) ) {
129+ workspace_root = workspace_map . get ( state . workspace_name ) !
139130 }
140-
141- const selected_files_by_workspace = new Map < string , string [ ] > ( )
142- const checked_files = params . workspace_provider . get_checked_files ( )
143- for ( const file of checked_files ) {
144- const workspace_root =
145- params . workspace_provider . get_workspace_root_for_file ( file )
146- if ( workspace_root ) {
147- const relative_path = path
148- . relative ( workspace_root , file )
149- . replace ( / \\ / g, '/' )
150- const current_selected =
151- selected_files_by_workspace . get ( workspace_root ) || [ ]
152- current_selected . push ( relative_path )
153- selected_files_by_workspace . set ( workspace_root , current_selected )
131+ if ( workspace_root ) {
132+ const current_files = files_by_workspace . get ( workspace_root ) || [ ]
133+ if ( ! current_files . includes ( state . file_path ) ) {
134+ current_files . push ( state . file_path )
154135 }
136+ files_by_workspace . set ( workspace_root , current_files )
155137 }
138+ }
156139
157- for ( const [ workspace_root , files ] of files_by_workspace . entries ( ) ) {
158- PromptsForCommitMessagesUtils . add ( {
159- extension_context : params . extension_context ,
160- workspace_root,
161- prompt : params . raw_instructions ,
162- files,
163- selected_files :
164- selected_files_by_workspace . get ( workspace_root ) || [ ]
165- } )
140+ const selected_files_by_workspace = new Map < string , string [ ] > ( )
141+ const checked_files = params . workspace_provider . get_checked_files ( )
142+ for ( const file of checked_files ) {
143+ const workspace_root =
144+ params . workspace_provider . get_workspace_root_for_file ( file )
145+ if ( workspace_root ) {
146+ const relative_path = path
147+ . relative ( workspace_root , file )
148+ . replace ( / \\ / g, '/' )
149+ const current_selected =
150+ selected_files_by_workspace . get ( workspace_root ) || [ ]
151+ current_selected . push ( relative_path )
152+ selected_files_by_workspace . set ( workspace_root , current_selected )
166153 }
167154 }
168155
156+ for ( const [ workspace_root , files ] of files_by_workspace . entries ( ) ) {
157+ PromptsForCommitMessagesUtils . add ( {
158+ extension_context : params . extension_context ,
159+ workspace_root,
160+ prompt : params . raw_instructions || '' ,
161+ files,
162+ selected_files : selected_files_by_workspace . get ( workspace_root ) || [ ]
163+ } )
164+ }
165+
169166 update_undo_button_state ( {
170167 extension_context : params . extension_context ,
171168 prompt_view_provider : params . prompt_view_provider ,
0 commit comments