@@ -9,6 +9,7 @@ import { build_commit_message_prompt } from './utils/build-commit-message-prompt
99import { generate_commit_message_with_api } from './utils/generate-commit-message-with-api'
1010import { ModelProvidersManager } from '@/services/model-providers-manager'
1111import { t } from '@/i18n'
12+ import axios from 'axios'
1213
1314export const generate_commit_message_command = (
1415 context : vscode . ExtensionContext
@@ -34,6 +35,7 @@ export const generate_commit_message_command = (
3435 let files_staged_by_action = false
3536 let is_single_change_flow = false
3637 const api_providers_manager = new ModelProvidersManager ( context )
38+ let force_show_quick_pick = false
3739
3840 while ( true ) {
3941 const data = await get_prompt_data ( source_control )
@@ -57,9 +59,12 @@ export const generate_commit_message_command = (
5759
5860 const api_config_data = await get_commit_message_config (
5961 context ,
60- show_back_button
62+ show_back_button ,
63+ force_show_quick_pick
6164 )
6265
66+ force_show_quick_pick = false
67+
6368 if ( api_config_data === 'back' ) {
6469 if ( was_empty_stage ) {
6570 if ( ! show_back_button ) {
@@ -81,85 +86,94 @@ export const generate_commit_message_command = (
8186 return
8287 }
8388
84- const commit_message = await generate_commit_message_with_api ( {
85- endpoint_url : api_config_data . endpoint_url ,
86- provider : api_config_data . provider ,
87- config : api_config_data . config ,
88- message : message_prompt
89- } )
90-
91- if ( commit_message ) {
92- if ( should_commit ) {
93- const edited_message = await new Promise < string | 'back' | undefined > (
94- ( resolve ) => {
95- const input_box = vscode . window . createInputBox ( )
96- input_box . value = commit_message
97- input_box . title = t ( 'command.commit-message.input.title' )
98- input_box . prompt = t ( 'command.commit-message.input.prompt' )
99-
100- if ( has_default_config && ! files_staged_by_action ) {
101- input_box . buttons = [
102- {
103- iconPath : new vscode . ThemeIcon ( 'close' ) ,
104- tooltip : t ( 'common.close' )
105- }
106- ]
107- } else {
108- input_box . buttons = [ vscode . QuickInputButtons . Back ]
109- }
110-
111- let is_resolved = false
89+ let commit_message : string
90+ try {
91+ commit_message = await generate_commit_message_with_api ( {
92+ endpoint_url : api_config_data . endpoint_url ,
93+ provider : api_config_data . provider ,
94+ config : api_config_data . config ,
95+ message : message_prompt
96+ } )
97+ } catch ( error ) {
98+ if ( axios . isCancel ( error ) ) {
99+ if ( was_empty_stage ) {
100+ await vscode . commands . executeCommand ( 'git.unstageAll' )
101+ }
102+ break
103+ } else {
104+ force_show_quick_pick = true
105+ continue
106+ }
107+ }
112108
113- input_box . onDidTriggerButton ( ( button ) => {
114- if (
115- button === vscode . QuickInputButtons . Back ||
116- button . tooltip === t ( 'common.close' )
117- ) {
118- is_resolved = true
119- resolve ( 'back' )
120- input_box . hide ( )
109+ if ( should_commit ) {
110+ const edited_message = await new Promise < string | 'back' | undefined > (
111+ ( resolve ) => {
112+ const input_box = vscode . window . createInputBox ( )
113+ input_box . value = commit_message
114+ input_box . title = t ( 'command.commit-message.input.title' )
115+ input_box . prompt = t ( 'command.commit-message.input.prompt' )
116+
117+ if ( has_default_config && ! files_staged_by_action ) {
118+ input_box . buttons = [
119+ {
120+ iconPath : new vscode . ThemeIcon ( 'close' ) ,
121+ tooltip : t ( 'common.close' )
121122 }
122- } )
123+ ]
124+ } else {
125+ input_box . buttons = [ vscode . QuickInputButtons . Back ]
126+ }
127+
128+ let is_resolved = false
123129
124- input_box . onDidAccept ( ( ) => {
130+ input_box . onDidTriggerButton ( ( button ) => {
131+ if (
132+ button === vscode . QuickInputButtons . Back ||
133+ button . tooltip === t ( 'common.close' )
134+ ) {
125135 is_resolved = true
126- resolve ( input_box . value )
136+ resolve ( 'back' )
127137 input_box . hide ( )
128- } )
138+ }
139+ } )
129140
130- input_box . onDidHide ( ( ) => {
131- if ( ! is_resolved ) {
132- resolve ( 'back' )
133- }
134- input_box . dispose ( )
135- } )
141+ input_box . onDidAccept ( ( ) => {
142+ is_resolved = true
143+ resolve ( input_box . value )
144+ input_box . hide ( )
145+ } )
136146
137- input_box . show ( )
138- }
139- )
140-
141- if ( edited_message === 'back' ) {
142- if ( has_default_config ) {
143- if ( files_staged_by_action ) {
144- await vscode . commands . executeCommand ( 'git.unstageAll' )
145- } else {
146- return
147+ input_box . onDidHide ( ( ) => {
148+ if ( ! is_resolved ) {
149+ resolve ( 'back' )
147150 }
151+ input_box . dispose ( )
152+ } )
153+
154+ input_box . show ( )
155+ }
156+ )
157+
158+ if ( edited_message === 'back' ) {
159+ if ( has_default_config ) {
160+ if ( files_staged_by_action ) {
161+ await vscode . commands . executeCommand ( 'git.unstageAll' )
162+ } else {
163+ return
148164 }
149- continue
150165 }
166+ continue
167+ }
151168
152- if ( edited_message ) {
153- repository . inputBox . value = edited_message
154- await vscode . commands . executeCommand ( 'git.commit' , repository )
155- } else if ( was_empty_stage ) {
156- await vscode . commands . executeCommand ( 'git.unstageAll' )
157- }
158- } else {
159- repository . inputBox . value = commit_message
169+ if ( edited_message ) {
170+ repository . inputBox . value = edited_message
171+ await vscode . commands . executeCommand ( 'git.commit' , repository )
172+ } else if ( was_empty_stage ) {
173+ await vscode . commands . executeCommand ( 'git.unstageAll' )
160174 }
161- } else if ( was_empty_stage ) {
162- await vscode . commands . executeCommand ( 'git.unstageAll' )
175+ } else {
176+ repository . inputBox . value = commit_message
163177 }
164178
165179 break
0 commit comments