Skip to content

Commit 43e8013

Browse files
committed
Refactor intelligent update config selection by moving it to utils and removing default button functionality
1 parent bc4c262 commit 43e8013

4 files changed

Lines changed: 11 additions & 279 deletions

File tree

packages/vscode/src/commands/apply-chat-response-command/response-processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Diff } from './utils/clipboard-parser/extract-diff-patches'
1010
import { apply_git_patch } from './handlers/diff-handler'
1111
import { apply_file_relocations, undo_files } from './utils/file-operations'
1212
import { ModelProvidersManager } from '@/services/model-providers-manager'
13-
import { get_intelligent_update_config } from './utils/config-picker'
13+
import { get_intelligent_update_config } from '@/utils/intelligent-update-utils'
1414
import { PROVIDERS } from '@shared/constants/providers'
1515
import { handle_intelligent_update } from './handlers/intelligent-update-handler'
1616
import { check_for_truncated_fragments } from '@/utils/check-for-truncated-fragments'

packages/vscode/src/commands/apply-chat-response-command/utils/config-picker.ts

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

packages/vscode/src/utils/intelligent-update-utils.ts

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,8 @@ export const get_intelligent_update_config = async (
3838
}
3939

4040
if (!selected_config || show_quick_pick) {
41-
const set_default_button = {
42-
iconPath: new vscode.ThemeIcon('star'),
43-
tooltip: 'Set as default'
44-
}
45-
46-
const unset_default_button = {
47-
iconPath: new vscode.ThemeIcon('star-full'),
48-
tooltip: 'Unset default'
49-
}
50-
5141
const create_items = async () => {
52-
const default_config =
53-
await api_providers_manager.get_default_intelligent_update_config()
54-
5542
return intelligent_update_configs.map((config, index) => {
56-
const buttons = []
57-
58-
const is_default =
59-
default_config &&
60-
default_config.provider_type == config.provider_type &&
61-
default_config.provider_name == config.provider_name &&
62-
default_config.model == config.model
63-
64-
if (is_default) {
65-
buttons.push(unset_default_button)
66-
} else {
67-
buttons.push(set_default_button)
68-
}
69-
7043
return {
7144
label: config.model,
7245
description: `${
@@ -78,16 +51,15 @@ export const get_intelligent_update_config = async (
7851
}`,
7952
config,
8053
index,
81-
id: get_tool_config_id(config),
82-
buttons
54+
id: get_tool_config_id(config)
8355
}
8456
})
8557
}
8658

8759
const quick_pick = vscode.window.createQuickPick()
8860
const items = await create_items()
8961
quick_pick.items = items
90-
quick_pick.title = 'Configuration'
62+
quick_pick.title = 'Configurations'
9163
quick_pick.placeholder =
9264
'Select the Intelligent Update API tool configuration'
9365
quick_pick.matchOnDescription = true
@@ -109,24 +81,6 @@ export const get_intelligent_update_config = async (
10981

11082
return new Promise<{ provider: any; config: ToolConfig } | undefined>(
11183
(resolve) => {
112-
quick_pick.onDidTriggerItemButton(async (event) => {
113-
const item = event.item as any
114-
const button = event.button
115-
const index = item.index
116-
117-
if (button === set_default_button) {
118-
await api_providers_manager.set_default_intelligent_update_config(
119-
intelligent_update_configs[index]
120-
)
121-
quick_pick.items = await create_items()
122-
} else if (button === unset_default_button) {
123-
await api_providers_manager.set_default_intelligent_update_config(
124-
null as any
125-
)
126-
quick_pick.items = await create_items()
127-
}
128-
})
129-
13084
quick_pick.onDidAccept(async () => {
13185
const selected = quick_pick.selectedItems[0] as any
13286
quick_pick.hide()

packages/vscode/src/views/panel/backend/message-handlers/handle-intelligent-update-file-in-preview.ts

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,14 @@ import { Logger } from '@shared/utils/logger'
1111
import { parse_response } from '@/commands/apply-chat-response-command/utils/clipboard-parser'
1212
import { ModelProvidersManager } from '@/services/model-providers-manager'
1313
import { PROVIDERS } from '@shared/constants/providers'
14-
import { process_file } from '@/utils/intelligent-update-utils'
14+
import {
15+
get_intelligent_update_config,
16+
process_file
17+
} from '@/utils/intelligent-update-utils'
1518
import { create_safe_path } from '@/utils/path-sanitizer'
1619
import { dictionary } from '@shared/constants/dictionary'
1720
import axios from 'axios'
1821

19-
const get_default_intelligent_update_config = async (
20-
api_providers_manager: ModelProvidersManager
21-
): Promise<{ provider: any; config: any } | undefined> => {
22-
const intelligent_update_configs =
23-
await api_providers_manager.get_intelligent_update_tool_configs()
24-
25-
if (intelligent_update_configs.length == 0) {
26-
vscode.commands.executeCommand('codeWebChat.settings')
27-
vscode.window.showInformationMessage(
28-
dictionary.information_message.NO_INTELLIGENT_UPDATE_CONFIGURATIONS_FOUND
29-
)
30-
return
31-
}
32-
33-
const selected_config =
34-
await api_providers_manager.get_default_intelligent_update_config()
35-
36-
if (!selected_config) {
37-
vscode.commands.executeCommand('codeWebChat.settings')
38-
vscode.window.showInformationMessage(
39-
dictionary.information_message.NO_DEFAULT_INTELLIGENT_UPDATE_CONFIGURATION
40-
)
41-
return
42-
}
43-
44-
const provider = await api_providers_manager.get_provider(
45-
selected_config.provider_name
46-
)
47-
48-
if (!provider) {
49-
vscode.window.showErrorMessage(
50-
dictionary.error_message.API_PROVIDER_FOR_DEFAULT_CONFIG_NOT_FOUND
51-
)
52-
return
53-
}
54-
55-
return {
56-
provider,
57-
config: selected_config
58-
}
59-
}
60-
6122
export const handle_intelligent_update_file_in_preview = async (
6223
panel_provider: PanelProvider,
6324
message: IntelligentUpdateFileInPreviewMessage
@@ -131,8 +92,10 @@ export const handle_intelligent_update_file_in_preview = async (
13192
const api_providers_manager = new ModelProvidersManager(
13293
panel_provider.context
13394
)
134-
const config_result = await get_default_intelligent_update_config(
135-
api_providers_manager
95+
const config_result = await get_intelligent_update_config(
96+
api_providers_manager,
97+
false,
98+
panel_provider.context
13699
)
137100
if (!config_result) return
138101

0 commit comments

Comments
 (0)