@@ -251,6 +251,7 @@ export const setup_api_tool_multi_config = async (params: {
251251 : 'No configurations found, add one to use this API tool'
252252
253253 let is_accepted = false
254+ let is_showing_dialog = false
254255
255256 return new Promise < boolean > ( ( resolve ) => {
256257 quick_pick . onDidAccept ( async ( ) => {
@@ -297,28 +298,55 @@ export const setup_api_tool_multi_config = async (params: {
297298 quick_pick . items = create_config_items ( )
298299 quick_pick . show ( )
299300 } else if ( event . button === delete_button ) {
301+ const config_to_delete = item . config
302+ const config_name = config_to_delete . model
303+ const delete_button_text = 'Delete'
304+
305+ // Set flag before hiding to prevent disposal
306+ is_showing_dialog = true
307+ quick_pick . hide ( )
308+
309+ const delete_message = `Are you sure you want to delete the configuration "${ config_name } " (${ config_to_delete . provider_name } )?`
310+
311+ const result = await vscode . window . showWarningMessage (
312+ delete_message ,
313+ { modal : true } ,
314+ delete_button_text
315+ )
316+
317+ is_showing_dialog = false // Reset flag after dialog closes
318+
319+ if ( result !== delete_button_text ) {
320+ // User cancelled, show the quick pick again
321+ resolve ( await show_configs_quick_pick ( ) )
322+ return
323+ }
324+
325+ const deleted_config = current_configs [ item . index ]
326+ const was_default =
327+ default_config &&
328+ default_config . provider_type == deleted_config . provider_type &&
329+ default_config . provider_name == deleted_config . provider_name &&
330+ default_config . model == deleted_config . model &&
331+ default_config . temperature == deleted_config . temperature &&
332+ default_config . reasoning_effort == deleted_config . reasoning_effort
333+
334+ // Remove the config
300335 current_configs . splice ( item . index , 1 )
301336 await tool_methods . save_configs ( current_configs )
302337
303- if (
304- default_config &&
305- default_config . provider_type == item . config . provider_type &&
306- default_config . provider_name == item . config . provider_name &&
307- default_config . model == item . config . model &&
308- default_config . temperature == item . config . temperature &&
309- default_config . reasoning_effort == item . config . reasoning_effort
310- ) {
338+ // Clear default if the deleted config was the default
339+ if ( was_default ) {
311340 default_config = undefined
312341 await tool_methods . set_default_config ( null )
313342 }
314343
315344 if ( current_configs . length == 0 ) {
316345 is_accepted = true
317- quick_pick . hide ( )
318346 resolve ( await show_configs_quick_pick ( ) )
319347 } else {
320- quick_pick . items = create_config_items ( )
321- quick_pick . show ( )
348+ // Show the quick pick immediately after deletion
349+ resolve ( await show_configs_quick_pick ( ) )
322350 }
323351 } else if (
324352 event . button === move_up_button ||
@@ -356,6 +384,12 @@ export const setup_api_tool_multi_config = async (params: {
356384 } )
357385
358386 quick_pick . onDidHide ( ( ) => {
387+ if ( is_showing_dialog ) {
388+ // We are showing a dialog (warning/info message) which hides the quick pick.
389+ // We don't want to dispose of everything in this case.
390+ return
391+ }
392+
359393 if ( ! is_accepted ) {
360394 resolve ( false )
361395 }
0 commit comments