Skip to content

Commit c4a399a

Browse files
committed
Refactor default configuration handlers into a unified implementation with type-based routing
1 parent 73cdf44 commit c4a399a

6 files changed

Lines changed: 74 additions & 100 deletions

‎packages/vscode/src/views/settings/backend/message-handlers/handle-set-default-code-completions-configuration.ts‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎packages/vscode/src/views/settings/backend/message-handlers/handle-set-default-commit-messages-configuration.ts‎

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
2+
import {
3+
ModelProvidersManager,
4+
get_tool_config_id,
5+
ToolConfig
6+
} from '@/services/model-providers-manager'
7+
8+
export const handle_set_default_configuration = async (
9+
provider: SettingsProvider,
10+
configuration_id: string | null,
11+
type:
12+
| 'code-completions'
13+
| 'intelligent-update'
14+
| 'commit-messages'
15+
| 'prune-context'
16+
): Promise<void> => {
17+
const providers_manager = new ModelProvidersManager(provider.context)
18+
19+
let get_configs: () => Promise<ToolConfig[]>
20+
let set_default_config: (config: ToolConfig | null) => Promise<void>
21+
22+
switch (type) {
23+
case 'code-completions':
24+
get_configs = () => providers_manager.get_code_completions_tool_configs()
25+
set_default_config = (c) =>
26+
providers_manager.set_default_code_completions_config(c)
27+
break
28+
case 'intelligent-update':
29+
get_configs = () =>
30+
providers_manager.get_intelligent_update_tool_configs()
31+
set_default_config = (c) =>
32+
providers_manager.set_default_intelligent_update_config(c)
33+
break
34+
case 'commit-messages':
35+
get_configs = () => providers_manager.get_commit_messages_tool_configs()
36+
set_default_config = (c) =>
37+
providers_manager.set_default_commit_messages_config(c)
38+
break
39+
case 'prune-context':
40+
get_configs = () => providers_manager.get_prune_context_tool_configs()
41+
set_default_config = (c) =>
42+
providers_manager.set_default_prune_context_config(c)
43+
break
44+
}
45+
46+
if (configuration_id === null) {
47+
await set_default_config(null)
48+
return
49+
}
50+
51+
const configs = await get_configs()
52+
const config_to_set_as_default = configs.find(
53+
(c) => get_tool_config_id(c) === configuration_id
54+
)
55+
56+
if (config_to_set_as_default) {
57+
await set_default_config(config_to_set_as_default)
58+
}
59+
}

‎packages/vscode/src/views/settings/backend/message-handlers/handle-set-default-intelligent-update-configuration.ts‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎packages/vscode/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ export * from './handle-delete-model-provider'
55
export * from './handle-edit-custom-model-provider'
66
export * from './handle-edit-model-provider-key'
77
export * from './handle-reorder-configuration'
8-
export * from './handle-set-default-code-completions-configuration'
9-
export * from './handle-set-default-commit-messages-configuration'
8+
export * from './handle-set-default-configuration'
109
export * from './handle-get-edit-context-system-instructions'
1110
export * from './handle-update-edit-context-system-instructions'
1211
export * from './handle-get-edit-format-instructions'
1312
export * from './handle-update-edit-format-instructions'
14-
export * from './handle-set-default-intelligent-update-configuration'
1513
export * from './handle-get-commit-message-instructions'
1614
export * from './handle-update-commit-message-instructions'
1715
export * from './handle-get-commit-message-auto-accept-after'

‎packages/vscode/src/views/settings/backend/settings-provider.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import {
2525
handle_get_checkpoint_lifespan,
2626
handle_reorder_configuration,
2727
handle_reorder_model_providers,
28-
handle_set_default_code_completions_configuration,
29-
handle_set_default_commit_messages_configuration,
30-
handle_set_default_intelligent_update_configuration,
28+
handle_set_default_configuration,
3129
handle_update_check_new_files,
3230
handle_update_clear_checks_in_workspace_behavior,
3331
handle_update_are_automatic_checkpoints_disabled,
@@ -133,7 +131,11 @@ export class SettingsProvider {
133131
} else if (
134132
message.command == 'SET_DEFAULT_CODE_COMPLETIONS_CONFIGURATION'
135133
) {
136-
await handle_set_default_code_completions_configuration(this, message)
134+
await handle_set_default_configuration(
135+
this,
136+
message.configuration_id,
137+
'code-completions'
138+
)
137139
} else if (message.command == 'GET_EDIT_CONTEXT_CONFIGURATIONS') {
138140
await handle_get_configurations(this, 'edit-context')
139141
} else if (message.command == 'REORDER_EDIT_CONTEXT_CONFIGURATIONS') {
@@ -179,9 +181,10 @@ export class SettingsProvider {
179181
} else if (
180182
message.command == 'SET_DEFAULT_INTELLIGENT_UPDATE_CONFIGURATION'
181183
) {
182-
await handle_set_default_intelligent_update_configuration(
184+
await handle_set_default_configuration(
183185
this,
184-
message
186+
message.configuration_id,
187+
'intelligent-update'
185188
)
186189
} else if (message.command == 'GET_PRUNE_CONTEXT_CONFIGURATIONS') {
187190
await handle_get_configurations(this, 'prune-context')
@@ -216,7 +219,11 @@ export class SettingsProvider {
216219
} else if (
217220
message.command == 'SET_DEFAULT_COMMIT_MESSAGES_CONFIGURATION'
218221
) {
219-
await handle_set_default_commit_messages_configuration(this, message)
222+
await handle_set_default_configuration(
223+
this,
224+
message.configuration_id,
225+
'commit-messages'
226+
)
220227
} else if (message.command == 'GET_COMMIT_MESSAGE_INSTRUCTIONS') {
221228
await handle_get_commit_message_instructions(this)
222229
} else if (message.command == 'UPDATE_COMMIT_MESSAGE_INSTRUCTIONS') {

0 commit comments

Comments
 (0)