@@ -248,107 +248,109 @@ export const run_generate_action = async (params: {
248248 Math . ceil ( prompt_with_context . api_prompt . length / 4 ) -
249249 skip_tokens
250250
251- const attach_label = t (
252- 'command.generate-commit-message-command.attach-context-files.attach'
253- )
254- const skip_label = t ( 'common.action.skip' )
255- const last_selected_id =
256- params . extension_context . workspaceState . get < string > (
257- LAST_USE_CONTEXT_FILES_STATE_KEY ,
258- 'attach'
251+ if ( additional_tokens > 0 ) {
252+ const attach_label = t (
253+ 'command.generate-commit-message-command.attach-context-files.attach'
259254 )
260-
261- const answer = await new Promise < string | undefined | 'back' > (
262- ( resolve ) => {
263- const quick_pick = vscode . window . createQuickPick <
264- vscode . QuickPickItem & { id : string }
265- > ( )
266- quick_pick . items = [
267- {
268- label : skip_label ,
269- description : display_token_count ( skip_tokens ) ,
270- id : 'skip'
271- } ,
272- {
273- label : attach_label ,
274- description : `+${ display_token_count ( additional_tokens ) } ` ,
275- id : 'attach'
276- }
277- ]
278- quick_pick . activeItems = [
279- quick_pick . items . find ( ( i ) => i . id === last_selected_id ) ||
280- quick_pick . items [ 1 ]
281- ]
282- quick_pick . title = t (
283- 'command.generate-commit-message-command.attach-context-files.title'
284- )
285- quick_pick . placeholder = t (
286- 'command.generate-commit-message-command.attach-context-files.placeholder'
255+ const skip_label = t ( 'common.action.skip' )
256+ const last_selected_id =
257+ params . extension_context . workspaceState . get < string > (
258+ LAST_USE_CONTEXT_FILES_STATE_KEY ,
259+ 'attach'
287260 )
288- quick_pick . ignoreFocusOut = true
289- const close_button = {
290- iconPath : new vscode . ThemeIcon ( 'close' ) ,
291- tooltip : t ( 'common.close' )
292- }
293- quick_pick . buttons = [
294- vscode . QuickInputButtons . Back ,
295- close_button
296- ]
297261
298- let is_resolved = false
299-
300- quick_pick . onDidTriggerButton ( ( button ) => {
301- if ( button === vscode . QuickInputButtons . Back ) {
302- is_resolved = true
303- resolve ( 'back' )
304- quick_pick . hide ( )
305- } else if ( button === close_button ) {
262+ const answer = await new Promise < string | undefined | 'back' > (
263+ ( resolve ) => {
264+ const quick_pick = vscode . window . createQuickPick <
265+ vscode . QuickPickItem & { id : string }
266+ > ( )
267+ quick_pick . items = [
268+ {
269+ label : skip_label ,
270+ description : display_token_count ( skip_tokens ) ,
271+ id : 'skip'
272+ } ,
273+ {
274+ label : attach_label ,
275+ description : `+${ display_token_count ( additional_tokens ) } ` ,
276+ id : 'attach'
277+ }
278+ ]
279+ quick_pick . activeItems = [
280+ quick_pick . items . find ( ( i ) => i . id === last_selected_id ) ||
281+ quick_pick . items [ 1 ]
282+ ]
283+ quick_pick . title = t (
284+ 'command.generate-commit-message-command.attach-context-files.title'
285+ )
286+ quick_pick . placeholder = t (
287+ 'command.generate-commit-message-command.attach-context-files.placeholder'
288+ )
289+ quick_pick . ignoreFocusOut = true
290+ const close_button = {
291+ iconPath : new vscode . ThemeIcon ( 'close' ) ,
292+ tooltip : t ( 'common.close' )
293+ }
294+ quick_pick . buttons = [
295+ vscode . QuickInputButtons . Back ,
296+ close_button
297+ ]
298+
299+ let is_resolved = false
300+
301+ quick_pick . onDidTriggerButton ( ( button ) => {
302+ if ( button === vscode . QuickInputButtons . Back ) {
303+ is_resolved = true
304+ resolve ( 'back' )
305+ quick_pick . hide ( )
306+ } else if ( button === close_button ) {
307+ is_resolved = true
308+ resolve ( undefined )
309+ quick_pick . hide ( )
310+ }
311+ } )
312+
313+ quick_pick . onDidAccept ( ( ) => {
306314 is_resolved = true
307- resolve ( undefined )
315+ resolve ( quick_pick . selectedItems [ 0 ] ?. id )
308316 quick_pick . hide ( )
309- }
310- } )
317+ } )
311318
312- quick_pick . onDidAccept ( ( ) => {
313- is_resolved = true
314- resolve ( quick_pick . selectedItems [ 0 ] ?. id )
315- quick_pick . hide ( )
316- } )
319+ quick_pick . onDidHide ( ( ) => {
320+ if ( ! is_resolved ) {
321+ resolve ( 'back' )
322+ }
323+ quick_pick . dispose ( )
324+ } )
317325
318- quick_pick . onDidHide ( ( ) => {
319- if ( ! is_resolved ) {
320- resolve ( 'back' )
321- }
322- quick_pick . dispose ( )
323- } )
326+ quick_pick . show ( )
327+ }
328+ )
324329
325- quick_pick . show ( )
330+ if ( answer === 'back' ) {
331+ current_action = undefined
332+ continue
326333 }
327- )
328-
329- if ( answer === 'back' ) {
330- current_action = undefined
331- continue
332- }
333334
334- if ( answer === undefined ) {
335- if ( was_empty_stage ) {
336- await vscode . commands . executeCommand (
337- 'git.unstageAll' ,
338- repository
339- )
335+ if ( answer === undefined ) {
336+ if ( was_empty_stage ) {
337+ await vscode . commands . executeCommand (
338+ 'git.unstageAll' ,
339+ repository
340+ )
341+ }
342+ return
340343 }
341- return
342- }
343344
344- params . extension_context . workspaceState . update (
345- LAST_USE_CONTEXT_FILES_STATE_KEY ,
346- answer
347- )
345+ params . extension_context . workspaceState . update (
346+ LAST_USE_CONTEXT_FILES_STATE_KEY ,
347+ answer
348+ )
348349
349- if ( answer === 'attach' ) {
350- final_api_prompt = prompt_with_context . api_prompt
351- final_chatbot_prompt = prompt_with_context . chatbot_prompt
350+ if ( answer === 'attach' ) {
351+ final_api_prompt = prompt_with_context . api_prompt
352+ final_chatbot_prompt = prompt_with_context . chatbot_prompt
353+ }
352354 }
353355 }
354356 }
0 commit comments