@@ -20,8 +20,8 @@ export const handle_edit_code_completions_configuration = async (
2020) : Promise < void > => {
2121 const providers_manager = new ModelProvidersManager ( provider . context )
2222 const model_fetcher = new ModelFetcher ( )
23- let configs = await providers_manager . get_code_completions_tool_configs ( )
24- let config_index = configs . findIndex (
23+ const configs = await providers_manager . get_code_completions_tool_configs ( )
24+ const config_index = configs . findIndex (
2525 ( c ) => get_tool_config_id ( c ) === message . configuration_id
2626 )
2727
@@ -32,19 +32,21 @@ export const handle_edit_code_completions_configuration = async (
3232 return
3333 }
3434
35- let config_to_edit = configs [ config_index ]
35+ const config_to_edit = configs [ config_index ]
36+ const updated_config = { ...config_to_edit }
3637
3738 type EditOption = 'Provider' | 'Model' | 'Temperature' | 'Reasoning Effort'
3839
39- const show_quick_pick = async ( ) : Promise < boolean > => {
40+ // eslint-disable-next-line no-constant-condition
41+ while ( true ) {
4042 const items : vscode . QuickPickItem [ ] = [
41- { label : 'Provider' , detail : config_to_edit . provider_name } ,
42- { label : 'Model' , detail : config_to_edit . model } ,
43- { label : 'Temperature' , detail : `${ config_to_edit . temperature } ` } ,
43+ { label : 'Provider' , detail : updated_config . provider_name } ,
44+ { label : 'Model' , detail : updated_config . model } ,
45+ { label : 'Temperature' , detail : `${ updated_config . temperature } ` } ,
4446 {
4547 label : 'Reasoning Effort' ,
4648 description : 'Requires supporting model' ,
47- detail : config_to_edit . reasoning_effort ?? 'auto'
49+ detail : updated_config . reasoning_effort ?? 'auto'
4850 }
4951 ]
5052
@@ -54,10 +56,9 @@ export const handle_edit_code_completions_configuration = async (
5456 } )
5557
5658 if ( ! selected_item ) {
57- return false
59+ break
5860 }
5961
60- const updated_config = { ...config_to_edit }
6162 const selected_option = selected_item . label as EditOption
6263
6364 switch ( selected_option ) {
@@ -66,74 +67,53 @@ export const handle_edit_code_completions_configuration = async (
6667 if ( new_provider ) {
6768 updated_config . provider_name = new_provider . provider_name
6869 updated_config . provider_type = new_provider . provider_type
69- } else {
70- return await show_quick_pick ( )
7170 }
7271 break
7372 }
7473 case 'Model' : {
7574 const new_model = await edit_model_for_config (
76- config_to_edit ,
75+ updated_config ,
7776 providers_manager ,
7877 model_fetcher
7978 )
80- if ( new_model !== undefined && new_model !== config_to_edit . model ) {
79+ if ( new_model !== undefined ) {
8180 updated_config . model = new_model
82- } else {
83- // User cancelled or didn't change the model
84- return await show_quick_pick ( )
8581 }
86-
8782 break
8883 }
8984 case 'Temperature' : {
90- const new_temp = await edit_temperature_for_config ( config_to_edit )
85+ const new_temp = await edit_temperature_for_config ( updated_config )
9186 if ( new_temp !== undefined ) {
9287 updated_config . temperature = new_temp
93- } else {
94- return await show_quick_pick ( )
9588 }
9689 break
9790 }
9891 case 'Reasoning Effort' : {
9992 const new_effort = await edit_reasoning_effort_for_config ( )
10093 if ( new_effort !== undefined ) {
10194 updated_config . reasoning_effort = new_effort as any
102- } else {
103- return await show_quick_pick ( )
10495 }
10596 break
10697 }
10798 }
99+ }
108100
109- const new_id = get_tool_config_id ( updated_config )
110- if (
111- new_id !== message . configuration_id &&
112- configs . some ( ( c ) => get_tool_config_id ( c ) === new_id )
113- ) {
114- vscode . window . showErrorMessage (
115- dictionary . error_message . CONFIGURATION_ALREADY_EXISTS
116- )
117- return await show_quick_pick ( )
118- }
119-
120- const updated_configs = [ ...configs ]
121- updated_configs [ config_index ] = updated_config
122- await providers_manager . save_code_completions_tool_configs ( updated_configs )
123-
124- if (
125- selected_option === 'Model' &&
126- updated_config . model !== config_to_edit . model
127- ) {
128- configs = updated_configs
129- message . configuration_id = new_id
130- config_index = configs . findIndex ( ( c ) => get_tool_config_id ( c ) === new_id )
131- config_to_edit = configs [ config_index ]
132- return await show_quick_pick ( )
133- }
101+ if ( JSON . stringify ( config_to_edit ) === JSON . stringify ( updated_config ) ) {
102+ return
103+ }
134104
135- return true
105+ const new_id = get_tool_config_id ( updated_config )
106+ if (
107+ new_id !== message . configuration_id &&
108+ configs . some ( ( c ) => get_tool_config_id ( c ) === new_id )
109+ ) {
110+ vscode . window . showErrorMessage (
111+ dictionary . error_message . CONFIGURATION_ALREADY_EXISTS
112+ )
113+ return
136114 }
137115
138- await show_quick_pick ( )
116+ const updated_configs = [ ...configs ]
117+ updated_configs [ config_index ] = updated_config
118+ await providers_manager . save_code_completions_tool_configs ( updated_configs )
139119}
0 commit comments