Skip to content

Commit ee7c897

Browse files
committed
Enable API tool configuration flows to signal menu exit for improved user navigation
1 parent 7237f38 commit ee7c897

4 files changed

Lines changed: 44 additions & 53 deletions

File tree

packages/vscode/src/commands/open-settings-command/open-settings-command.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ export const open_settings_command = (context: vscode.ExtensionContext) => {
8888
tool: 'intelligent-update'
8989
})
9090
break
91-
case LABEL_COMMIT_MESSAGES:
92-
await setup_api_tool({
91+
case LABEL_COMMIT_MESSAGES: {
92+
const exit_menu = await setup_api_tool({
9393
context,
9494
tool: 'commit-messages'
9595
})
96+
if (exit_menu) {
97+
show_menu = false
98+
}
9699
break
100+
}
97101
}
98102
}
99103
})

packages/vscode/src/commands/open-settings-command/setup-api-tool-multi-config.ts

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface ToolMethods {
2424
export const setup_api_tool_multi_config = async (params: {
2525
context: vscode.ExtensionContext
2626
tool: SupportedTool
27-
}): Promise<void> => {
27+
}): Promise<boolean> => {
2828
const providers_manager = new ApiProvidersManager(params.context)
2929
const model_fetcher = new ModelFetcher()
3030

@@ -221,7 +221,7 @@ export const setup_api_tool_multi_config = async (params: {
221221
return items
222222
}
223223

224-
const show_configs_quick_pick = async (): Promise<void> => {
224+
const show_configs_quick_pick = async (): Promise<boolean> => {
225225
const quick_pick = vscode.window.createQuickPick()
226226
quick_pick.items = create_config_items()
227227
quick_pick.title = `${tool_methods.get_display_name()} Configurations`
@@ -233,32 +233,30 @@ export const setup_api_tool_multi_config = async (params: {
233233

234234
let is_accepted = false
235235

236-
return new Promise<void>((resolve) => {
236+
return new Promise<boolean>((resolve) => {
237237
quick_pick.onDidAccept(async () => {
238238
is_accepted = true
239239
const selected = quick_pick.selectedItems[0]
240240
if (!selected) {
241241
quick_pick.hide()
242-
resolve()
242+
resolve(false)
243243
return
244244
}
245245

246246
if (selected.label === BACK_LABEL) {
247247
quick_pick.hide()
248-
resolve()
248+
resolve(false)
249249
return
250250
}
251251

252252
if (selected.label == ADD_CONFIGURATION_LABEL) {
253253
quick_pick.hide()
254254
await add_configuration()
255-
await show_configs_quick_pick()
256-
resolve()
255+
resolve(await show_configs_quick_pick())
257256
} else if ('config' in selected && selected.config) {
258257
quick_pick.hide()
259258
await edit_configuration(selected.config as ToolConfig)
260-
await show_configs_quick_pick()
261-
resolve()
259+
resolve(await show_configs_quick_pick())
262260
}
263261
})
264262

@@ -272,8 +270,7 @@ export const setup_api_tool_multi_config = async (params: {
272270
is_accepted = true
273271
quick_pick.hide()
274272
await edit_configuration(item.config)
275-
await show_configs_quick_pick()
276-
resolve()
273+
resolve(await show_configs_quick_pick())
277274
} else if (event.button === duplicate_button) {
278275
const new_config = { ...item.config }
279276
current_configs.splice(item.index + 1, 0, new_config)
@@ -297,8 +294,7 @@ export const setup_api_tool_multi_config = async (params: {
297294
if (current_configs.length == 0) {
298295
is_accepted = true
299296
quick_pick.hide()
300-
await show_configs_quick_pick()
301-
resolve()
297+
resolve(await show_configs_quick_pick())
302298
} else {
303299
quick_pick.items = create_config_items()
304300
quick_pick.show()
@@ -340,23 +336,23 @@ export const setup_api_tool_multi_config = async (params: {
340336

341337
quick_pick.onDidHide(() => {
342338
if (!is_accepted) {
343-
resolve()
339+
resolve(false)
344340
}
345341
})
346342

347343
quick_pick.show()
348344
})
349345
}
350346

351-
async function add_configuration(): Promise<void> {
347+
async function add_configuration(): Promise<boolean> {
352348
const provider_info = await select_provider()
353349
if (!provider_info) {
354-
return
350+
return false
355351
}
356352

357353
const model = await select_model(provider_info)
358354
if (!model) {
359-
return
355+
return false
360356
}
361357

362358
const new_config: ToolConfig = {
@@ -368,10 +364,10 @@ export const setup_api_tool_multi_config = async (params: {
368364

369365
current_configs.push(new_config)
370366
await tool_methods.save_configs(current_configs)
371-
await edit_configuration(new_config)
367+
return await edit_configuration(new_config)
372368
}
373369

374-
async function edit_configuration(config: ToolConfig) {
370+
async function edit_configuration(config: ToolConfig): Promise<boolean> {
375371
const create_edit_options = () => {
376372
const options = [
377373
{ label: BACK_LABEL },
@@ -424,13 +420,13 @@ export const setup_api_tool_multi_config = async (params: {
424420

425421
let is_accepted = false
426422

427-
return new Promise<void>((resolve) => {
423+
return new Promise<boolean>((resolve) => {
428424
quick_pick.onDidAccept(async () => {
429425
is_accepted = true
430426
const selected_option = quick_pick.selectedItems[0]
431427
if (!selected_option || selected_option.label == BACK_LABEL) {
432428
quick_pick.hide()
433-
resolve()
429+
resolve(false)
434430
return
435431
}
436432

@@ -457,15 +453,13 @@ export const setup_api_tool_multi_config = async (params: {
457453
if (selected_option.label == PROVIDER_LABEL) {
458454
const new_provider = await select_provider()
459455
if (!new_provider) {
460-
await edit_configuration(config)
461-
resolve()
456+
resolve(await edit_configuration(config))
462457
return
463458
}
464459

465460
const new_model = await select_model(new_provider)
466461
if (!new_model) {
467-
await edit_configuration(config)
468-
resolve()
462+
resolve(await edit_configuration(config))
469463
return
470464
}
471465

@@ -479,8 +473,7 @@ export const setup_api_tool_multi_config = async (params: {
479473
updated_config_state.model = new_model
480474
config_changed_in_this_step = true
481475
} else {
482-
await edit_configuration(config)
483-
resolve()
476+
resolve(await edit_configuration(config))
484477
return
485478
}
486479
} else if (selected_option.label == MODEL_LABEL) {
@@ -493,42 +486,37 @@ export const setup_api_tool_multi_config = async (params: {
493486
provider_info as Pick<Provider, 'type' | 'name'>
494487
)
495488
if (!new_model) {
496-
await edit_configuration(config)
497-
resolve()
489+
resolve(await edit_configuration(config))
498490
return
499491
}
500492

501493
if (new_model != config.model) {
502494
updated_config_state.model = new_model
503495
config_changed_in_this_step = true
504496
} else {
505-
await edit_configuration(config)
506-
resolve()
497+
resolve(await edit_configuration(config))
507498
return
508499
}
509500
} else if (selected_option.label == TEMPERATURE_LABEL) {
510501
const new_temperature = await set_temperature(config.temperature)
511502
if (new_temperature === undefined) {
512-
await edit_configuration(config)
513-
resolve()
503+
resolve(await edit_configuration(config))
514504
return
515505
}
516506

517507
if (new_temperature != config.temperature) {
518508
updated_config_state.temperature = new_temperature
519509
config_changed_in_this_step = true
520510
} else {
521-
await edit_configuration(config)
522-
resolve()
511+
resolve(await edit_configuration(config))
523512
return
524513
}
525514
} else if (selected_option.label == REASONING_EFFORT_LABEL) {
526515
const new_reasoning_effort = await select_reasoning_effort(
527516
config.reasoning_effort
528517
)
529518
if (new_reasoning_effort.cancelled) {
530-
await edit_configuration(config)
531-
resolve()
519+
resolve(await edit_configuration(config))
532520
return
533521
}
534522

@@ -539,13 +527,11 @@ export const setup_api_tool_multi_config = async (params: {
539527
updated_config_state.reasoning_effort = new_reasoning_effort.value
540528
config_changed_in_this_step = true
541529
} else {
542-
await edit_configuration(config)
543-
resolve()
530+
resolve(await edit_configuration(config))
544531
return
545532
}
546533
} else {
547-
await edit_configuration(config)
548-
resolve()
534+
resolve(await edit_configuration(config))
549535
return
550536
}
551537

@@ -569,18 +555,17 @@ export const setup_api_tool_multi_config = async (params: {
569555
}
570556
} else {
571557
console.error('Could not find original config in array to update.')
572-
resolve()
558+
resolve(false)
573559
return
574560
}
575561
}
576562

577-
await edit_configuration(updated_config_state)
578-
resolve()
563+
resolve(await edit_configuration(updated_config_state))
579564
})
580565

581566
quick_pick.onDidHide(() => {
582567
if (!is_accepted) {
583-
resolve()
568+
resolve(false)
584569
}
585570
})
586571

@@ -738,5 +723,5 @@ export const setup_api_tool_multi_config = async (params: {
738723
return { value: selected.effort, cancelled: false }
739724
}
740725

741-
await show_configs_quick_pick()
726+
return await show_configs_quick_pick()
742727
}

packages/vscode/src/commands/open-settings-command/setup-api-tool.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const BACK_LABEL = '$(arrow-left) Back'
1717
export const setup_api_tool = async (params: {
1818
context: vscode.ExtensionContext
1919
tool: SupportedTool
20-
}): Promise<void> => {
20+
}): Promise<boolean> => {
2121
const providers_manager = new ApiProvidersManager(params.context)
2222
const model_fetcher = new ModelFetcher()
2323

@@ -26,8 +26,9 @@ export const setup_api_tool = async (params: {
2626

2727
if (!current_config) {
2828
await setup_new_config()
29+
return false
2930
} else {
30-
await update_existing_config(current_config)
31+
return await update_existing_config(current_config)
3132
}
3233

3334
async function setup_new_config() {
@@ -58,7 +59,7 @@ export const setup_api_tool = async (params: {
5859
)
5960
}
6061

61-
async function update_existing_config(config: ToolConfig) {
62+
async function update_existing_config(config: ToolConfig): Promise<boolean> {
6263
const api_provider_label = 'API provider'
6364
const model_label = 'Model'
6465
const temperature_label = 'Temperature'
@@ -180,7 +181,7 @@ export const setup_api_tool = async (params: {
180181
'workbench.action.openSettings',
181182
'codeWebChat.commitMessageInstructions'
182183
)
183-
return
184+
return true
184185
} else if (selection.label == confirmation_threshold_label) {
185186
const new_threshold = await set_confirmation_threshold(
186187
current_threshold
@@ -197,6 +198,7 @@ export const setup_api_tool = async (params: {
197198
await providers_manager.save_commit_messages_tool_config(config)
198199
}
199200
}
201+
return false
200202
}
201203

202204
async function select_provider(): Promise<

packages/vscode/src/view/frontend/home/HomeView/HomeView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export const HomeView: React.FC<Props> = (props) => {
451451
}}
452452
>
453453
<span className="codicon codicon-feedback"></span>{' '}
454-
<span>Review</span>
454+
<span>Rate</span>
455455
</a>
456456
<a href="https://buymeacoffee.com/robertpiosik">
457457
<span className="codicon codicon-coffee"></span>{' '}

0 commit comments

Comments
 (0)