Skip to content

Commit 6fb4af8

Browse files
committed
Refactor API tool configuration event handling and update the README and UI text for clarity
1 parent 5bc8e42 commit 6fb4af8

6 files changed

Lines changed: 47 additions & 38 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Whenever proposing a new or updated file use the Markdown Code Block syntax. Eac
4545

4646
> <small>The prompt and edit format instructions are repeated after the context [for better accuracy](https://cookbook.openai.com/examples/gpt4-1_prompting_guide#:~:text=If%20you%20have%20long%20context%20in%20your%20prompt%2C%20ideally%20place%20your%20instructions%20at%20both%20the%20beginning%20and%20end%20of%20the%20provided%20context%2C%20as%20we%20found%20this%20to%20perform%20better%20than%20only%20above%20or%20below.).</small>
4747
48-
The generated response can then be applied to the codebase with confidence.
48+
The generated response can then be applied to the codebase using advanced built-in parsers.
4949

5050
## <span style="background-color: #fbb100; color: black; padding: 0.2em 0.6em; border-radius: 999px">Chatbot initialization</span>
5151

‎packages/shared/src/constants/dictionary.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const dictionary = {
1313
code_completions_mode_unavailable_with_text_selection:
1414
'Remove text selection',
1515
code_completions_mode_unavailable_without_active_editor:
16-
'Place cursor in editor',
16+
'Place cursor for completion',
1717
search: 'Search history',
1818
websocket_not_connected: 'Install or reload the browser extension',
1919
for_history_hint: '(⇅ for history)',

‎packages/ui/src/components/editor/ChatInput/ChatInput.module.scss‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,14 @@
9494
&__inner {
9595
display: flex;
9696
text-align: center;
97-
padding: var(--padding-2px) var(--padding-10px) var(--padding-2px)
97+
align-items: center;
98+
padding: var(--padding-3px) var(--padding-10px) var(--padding-3px)
9899
var(--padding-8px);
99100
font-weight: 500;
100101
color: var(--vscode-activityWarningBadge-foreground);
101102
background-color: var(--vscode-activityWarningBadge-background);
102-
white-space: nowrap;
103103
border-radius: var(--border-radius-999px);
104+
margin: 0 var(--padding-8px);
104105

105106
&::before {
106107
content: '⚠';

‎packages/vscode/src/services/model-providers-manager.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { SECRET_STORAGE_MODEL_PROVIDERS_KEY } from '@/constants/secret-storage-keys'
1414

1515
export const api_tool_config_emitter = new EventEmitter()
16+
export const API_TOOLS_UPDATED_EVENT = 'api-tools-updated'
1617

1718
export type BuiltInProvider = {
1819
type: 'built-in'
@@ -82,7 +83,7 @@ export class ModelProvidersManager {
8283
JSON.stringify(providers)
8384
)
8485
this._providers = providers
85-
api_tool_config_emitter.emit('api-tools-updated')
86+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
8687
} catch (error) {
8788
console.error('Error saving providers to secret storage:', error)
8889
throw error
@@ -145,7 +146,7 @@ export class ModelProvidersManager {
145146
DEFAULT_CODE_COMPLETIONS_CONFIGURATION_STATE_KEY,
146147
config
147148
)
148-
api_tool_config_emitter.emit('api-tools-updated')
149+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
149150
}
150151

151152
public async save_code_completions_tool_configs(
@@ -155,7 +156,7 @@ export class ModelProvidersManager {
155156
TOOL_CONFIG_CODE_COMPLETIONS_STATE_KEY,
156157
configs
157158
)
158-
api_tool_config_emitter.emit('api-tools-updated')
159+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
159160
}
160161

161162
public async get_edit_context_tool_configs(): Promise<EditContextConfigs> {
@@ -172,7 +173,7 @@ export class ModelProvidersManager {
172173
TOOL_CONFIG_EDIT_CONTEXT_STATE_KEY,
173174
configs
174175
)
175-
api_tool_config_emitter.emit('api-tools-updated')
176+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
176177
}
177178

178179
public async get_commit_messages_tool_configs(): Promise<CommitMessagesConfigs> {
@@ -205,7 +206,7 @@ export class ModelProvidersManager {
205206
DEFAULT_COMMIT_MESSAGES_CONFIGURATION_STATE_KEY,
206207
config
207208
)
208-
api_tool_config_emitter.emit('api-tools-updated')
209+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
209210
}
210211

211212
public async save_commit_messages_tool_configs(
@@ -215,7 +216,7 @@ export class ModelProvidersManager {
215216
TOOL_CONFIG_COMMIT_MESSAGES_STATE_KEY,
216217
configs
217218
)
218-
api_tool_config_emitter.emit('api-tools-updated')
219+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
219220
}
220221

221222
public async get_intelligent_update_tool_configs(): Promise<IntelligentUpdateConfigs> {
@@ -250,7 +251,7 @@ export class ModelProvidersManager {
250251
DEFAULT_INTELLIGENT_UPDATE_CONFIGURATION_STATE_KEY,
251252
config
252253
)
253-
api_tool_config_emitter.emit('api-tools-updated')
254+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
254255
}
255256

256257
public async save_intelligent_update_tool_configs(
@@ -260,7 +261,7 @@ export class ModelProvidersManager {
260261
TOOL_CONFIG_INTELLIGENT_UPDATE_STATE_KEY,
261262
configs
262263
)
263-
api_tool_config_emitter.emit('api-tools-updated')
264+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
264265
}
265266

266267
/**
@@ -407,6 +408,6 @@ export class ModelProvidersManager {
407408
)
408409
}
409410

410-
api_tool_config_emitter.emit('api-tools-updated')
411+
api_tool_config_emitter.emit(API_TOOLS_UPDATED_EVENT)
411412
}
412413
}

‎packages/vscode/src/views/panel/backend/view-provider.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ import {
7575
import { CHATBOTS } from '@shared/constants/chatbots'
7676
import { HOME_VIEW_TYPES, HomeViewType } from '../types/home-view-type'
7777
import { ApiMode, WebMode } from '@shared/types/modes'
78-
import { api_tool_config_emitter } from '@/services/model-providers-manager'
78+
import {
79+
API_TOOLS_UPDATED_EVENT,
80+
api_tool_config_emitter
81+
} from '@/services/model-providers-manager'
7982
import { code_review_promise_resolve } from '@/commands/apply-chat-response-command/utils/review'
8083
import { Logger } from '@shared/utils/logger'
8184
import { CancelTokenSource } from 'axios'
@@ -156,10 +159,8 @@ export class ViewProvider implements vscode.WebviewViewProvider {
156159
''
157160
)
158161

159-
api_tool_config_emitter.on('api-tools-updated', () => {
160-
if (this._webview_view) {
161-
void handle_get_api_tool_configurations(this)
162-
}
162+
api_tool_config_emitter.on(API_TOOLS_UPDATED_EVENT, () => {
163+
void handle_get_api_tool_configurations(this)
163164
})
164165

165166
this.chat_edit_format = this.context.workspaceState.get<EditFormat>(

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,37 @@ import {
3434
handle_edit_intelligent_update_configuration,
3535
handle_set_default_intelligent_update_configuration
3636
} from './message-handlers'
37+
import {
38+
API_TOOLS_UPDATED_EVENT,
39+
api_tool_config_emitter
40+
} from '@/services/model-providers-manager'
3741

3842
export class SettingsProvider {
39-
private _panel: vscode.WebviewPanel | undefined
40-
private readonly _disposables: vscode.Disposable[] = []
43+
private _webview_panel: vscode.WebviewPanel | undefined
4144

4245
constructor(
4346
private readonly _extensionUri: vscode.Uri,
4447
public readonly context: vscode.ExtensionContext
45-
) {}
48+
) {
49+
api_tool_config_emitter.on(API_TOOLS_UPDATED_EVENT, () => {
50+
void handle_get_code_completions_configurations(this)
51+
void handle_get_edit_context_configurations(this)
52+
void handle_get_intelligent_update_configurations(this)
53+
void handle_get_commit_messages_configurations(this)
54+
})
55+
}
4656

4757
public createOrShow() {
4858
const column = vscode.window.activeTextEditor
4959
? vscode.window.activeTextEditor.viewColumn
5060
: undefined
5161

52-
if (this._panel) {
53-
this._panel.reveal(column)
62+
if (this._webview_panel) {
63+
this._webview_panel.reveal(column)
5464
return
5565
}
5666

57-
this._panel = vscode.window.createWebviewPanel(
67+
this._webview_panel = vscode.window.createWebviewPanel(
5868
'codeWebChatSettings',
5969
'Settings',
6070
column || vscode.ViewColumn.One,
@@ -64,18 +74,15 @@ export class SettingsProvider {
6474
}
6575
)
6676

67-
this._panel.onDidDispose(
68-
() => {
69-
this._panel = undefined
70-
this._disposables.forEach((d) => d.dispose())
71-
},
72-
null,
73-
this._disposables
74-
)
77+
this._webview_panel.onDidDispose(() => {
78+
this._webview_panel = undefined
79+
}, null)
7580

76-
this._panel.webview.html = this._getHtmlForWebview(this._panel.webview)
81+
this._webview_panel.webview.html = this._getHtmlForWebview(
82+
this._webview_panel.webview
83+
)
7784

78-
this._panel.webview.onDidReceiveMessage(
85+
this._webview_panel.webview.onDidReceiveMessage(
7986
(message: FrontendMessage) => {
8087
switch (message.command) {
8188
case 'GET_MODEL_PROVIDERS':
@@ -173,14 +180,13 @@ export class SettingsProvider {
173180
break
174181
}
175182
},
176-
null,
177-
this._disposables
183+
null
178184
)
179185
}
180186

181187
public postMessage(message: BackendMessage) {
182-
if (this._panel) {
183-
this._panel.webview.postMessage(message)
188+
if (this._webview_panel) {
189+
this._webview_panel.webview.postMessage(message)
184190
}
185191
}
186192

0 commit comments

Comments
 (0)