Skip to content

Commit 0bd8ac9

Browse files
committed
Refactor settings menu navigation to use persistent quick pick loops, enhancing user flow
1 parent ccd93eb commit 0bd8ac9

3 files changed

Lines changed: 44 additions & 45 deletions

File tree

packages/vscode/src/view/backend/message-handlers/handle-open-settings/handle-open-settings.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { setup_api_tool } from './setup-api-tool'
77
export const handle_open_settings = async (
88
provider: ViewProvider
99
): Promise<void> => {
10-
const show_main_menu = async () => {
10+
let showMenu = true
11+
while (showMenu) {
1112
const selected = await vscode.window.showQuickPick(
1213
[
1314
{
@@ -20,23 +21,23 @@ export const handle_open_settings = async (
2021
kind: vscode.QuickPickItemKind.Separator
2122
},
2223
{
23-
label: 'Code Completions',
24-
description: 'Get code at cursor from state-of-the-art reasoning models.'
24+
label: '$(tools) Code Completions',
25+
description:
26+
'Get code at cursor from state-of-the-art reasoning models'
2527
},
2628
{
27-
label: 'Edit Context',
29+
label: '$(tools) Edit Context',
2830
description:
29-
'Create and modify files in context based on natural language instructions.'
31+
'Create and modify files in context based on natural language instructions'
3032
},
3133
{
32-
label: 'Intelligent Update',
33-
description:
34-
'Handle "truncated" edit format and fix malformed diffs.'
34+
label: '$(tools) Intelligent Update',
35+
description: 'Handle "truncated" edit format and fix malformed diffs'
3536
},
3637
{
37-
label: 'Commit Messages',
38+
label: '$(tools) Commit Messages',
3839
description:
39-
'Generate meaningful commit messages precisely adhering to your style.'
40+
'Generate meaningful commit messages precisely adhering to your style'
4041
}
4142
],
4243
{
@@ -46,26 +47,27 @@ export const handle_open_settings = async (
4647
)
4748

4849
if (!selected) {
49-
return
50+
showMenu = false
51+
continue
5052
}
5153

5254
switch (selected.label) {
5355
case 'Configure API Providers':
5456
await configure_api_providers(provider)
5557
break
56-
case 'Code Completions':
58+
case '$(tools) Code Completions':
5759
await setup_api_tool_multi_config({
5860
provider,
5961
tool: 'code-completions'
6062
})
6163
break
62-
case 'Edit Context':
64+
case '$(tools) Edit Context':
6365
await setup_api_tool_multi_config({
6466
provider,
6567
tool: 'edit-context'
6668
})
6769
break
68-
case 'Intelligent Update':
70+
case '$(tools) Intelligent Update':
6971
await setup_api_tool_multi_config({
7072
provider,
7173
tool: 'intelligent-update'
@@ -78,10 +80,5 @@ export const handle_open_settings = async (
7880
})
7981
break
8082
}
81-
82-
// Return to main menu after completing any operation
83-
await show_main_menu()
8483
}
85-
86-
await show_main_menu()
8784
}

packages/vscode/src/view/backend/message-handlers/handle-open-settings/setup-api-tool-multi-config.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const setup_api_tool_multi_config = async (params: {
3535
const providers_manager = new ApiProvidersManager(params.provider.context)
3636
const model_fetcher = new ModelFetcher()
3737

38+
const back_label = '$(arrow-left) Back'
39+
3840
const get_tool_methods = (tool: SupportedTool): ToolMethods => {
3941
switch (tool) {
4042
case 'code-completions':
@@ -122,6 +124,7 @@ export const setup_api_tool_multi_config = async (params: {
122124
config?: ToolConfig
123125
index?: number
124126
})[] = [
127+
{ label: back_label },
125128
{
126129
label: '$(add) Add another configuration...'
127130
}
@@ -193,19 +196,14 @@ export const setup_api_tool_multi_config = async (params: {
193196
}
194197

195198
const show_configs_quick_pick = async (): Promise<void> => {
196-
if (current_configs.length == 0) {
197-
await add_configuration()
198-
if (current_configs.length > 0) {
199-
return show_configs_quick_pick()
200-
}
201-
return
202-
}
203-
204199
const quick_pick = vscode.window.createQuickPick()
205200
quick_pick.items = create_config_items()
206201
quick_pick.title = `${tool_methods.get_display_name()} Configurations`
207202
quick_pick.matchOnDescription = true
208-
quick_pick.placeholder = 'Select a configuration to edit or add another one'
203+
quick_pick.placeholder =
204+
current_configs.length > 0
205+
? 'Select a configuration to edit or add another one'
206+
: 'No configurations found. Add one to continue.'
209207

210208
let is_accepted = false
211209

@@ -219,6 +217,12 @@ export const setup_api_tool_multi_config = async (params: {
219217
return
220218
}
221219

220+
if (selected.label === back_label) {
221+
quick_pick.hide()
222+
resolve()
223+
return
224+
}
225+
222226
if (selected.label == '$(add) Add another configuration...') {
223227
quick_pick.hide()
224228
await add_configuration()
@@ -268,10 +272,7 @@ export const setup_api_tool_multi_config = async (params: {
268272
if (current_configs.length == 0) {
269273
is_accepted = true
270274
quick_pick.hide()
271-
await add_configuration()
272-
if (current_configs.length > 0) {
273-
await show_configs_quick_pick()
274-
}
275+
await show_configs_quick_pick()
275276
resolve()
276277
} else {
277278
quick_pick.items = create_config_items()
@@ -323,7 +324,7 @@ export const setup_api_tool_multi_config = async (params: {
323324
})
324325
}
325326

326-
async function add_configuration() {
327+
async function add_configuration(): Promise<void> {
327328
const provider_info = await select_provider()
328329
if (!provider_info) {
329330
return

packages/vscode/src/view/backend/message-handlers/handle-open-settings/setup-api-tool.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const DEFAULT_TEMPERATURE: { [key in SupportedTool]: number } = {
1818

1919
const DEFAULT_CONFIRMATION_THRESHOLD = 20000
2020

21+
const BACK_LABEL = '$(arrow-left) Back'
22+
2123
export const setup_api_tool = async (params: {
2224
provider: ViewProvider
2325
tool: SupportedTool
@@ -69,13 +71,15 @@ export const setup_api_tool = async (params: {
6971
const edit_instructions_label = 'Instructions'
7072
const confirmation_threshold_label = 'Ask for confirmation above'
7173

72-
const show_config_options = async () => {
74+
let showMenu = true
75+
while (showMenu) {
7376
const current_threshold = params.provider.context.globalState.get<number>(
7477
COMMIT_MESSAGES_CONFIRMATION_THRESHOLD_STATE_KEY,
7578
DEFAULT_CONFIRMATION_THRESHOLD
7679
)
7780

7881
const options: vscode.QuickPickItem[] = [
82+
{ label: BACK_LABEL },
7983
{ label: api_provider_label, description: config.provider_name },
8084
{ label: model_label, description: config.model },
8185
{
@@ -113,21 +117,22 @@ export const setup_api_tool = async (params: {
113117
placeHolder: 'Select setting to update'
114118
})
115119

116-
if (!selection) return
120+
if (!selection || selection.label === BACK_LABEL) {
121+
showMenu = false
122+
continue
123+
}
117124

118125
let updated = false
119126

120127
if (selection.label == api_provider_label) {
121128
const provider_info = await select_provider()
122129
if (!provider_info) {
123-
await show_config_options()
124-
return
130+
continue
125131
}
126132

127133
const model = await select_model(provider_info)
128134
if (!model) {
129-
await show_config_options()
130-
return
135+
continue
131136
}
132137

133138
config = {
@@ -148,17 +153,15 @@ export const setup_api_tool = async (params: {
148153
}
149154
const new_model = await select_model(provider_info)
150155
if (!new_model) {
151-
await show_config_options()
152-
return
156+
continue
153157
}
154158
config.model = new_model
155159
config.temperature = DEFAULT_TEMPERATURE[params.tool]
156160
updated = true
157161
} else if (selection.label == temperature_label) {
158162
const new_temperature = await set_temperature(config.temperature)
159163
if (new_temperature === undefined) {
160-
await show_config_options()
161-
return
164+
continue
162165
}
163166
config.temperature = new_temperature
164167
updated = true
@@ -183,9 +186,7 @@ export const setup_api_tool = async (params: {
183186
if (updated) {
184187
await providers_manager.save_commit_messages_tool_config(config)
185188
}
186-
await show_config_options()
187189
}
188-
await show_config_options()
189190
}
190191

191192
async function select_provider(): Promise<

0 commit comments

Comments
 (0)