Skip to content

Commit 41774cc

Browse files
committed
Refactor the edit format instructions logic to fetch configuration settings and display them as tooltips in the UI
1 parent 3abca56 commit 41774cc

10 files changed

Lines changed: 55 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Large language models (LLMs) are trained on vast datasets targeting many use cas
2424

2525
Because the model is only as smart as examples it has seen in its pre-training, the possible coverage of real-world coding scenarios when approached at a high level is fundamentally limited.
2626

27-
Therefore, CWC is designed in a way that aligns with LLMs' true capabilities—that is, code generation in a controlled signal-to-noise ratio environment. By you, the engineer.
27+
Therefore, CWC is designed to align with LLMs' true capabilities—that is, code generation in a controlled signal-to-noise ratio environment. Controlled by you, the engineer.
2828

2929
💅 **The workflow**
3030

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type EditFormat = 'truncated' | 'whole' | 'diff'
1+
export type EditFormat = 'whole' | 'truncated' | 'diff'

‎packages/vscode/src/commands/checkpoints-command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export const checkpoints_command = (
695695
quick_pick.items = [
696696
{
697697
id: 'add-new',
698-
label: '$(add) Add new checkpoint',
698+
label: '$(add) New checkpoint',
699699
alwaysShow: true
700700
},
701701
...(revert_item ? [revert_item] : []),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ViewProvider } from '@/views/panel/backend/panel-provider'
2+
import * as vscode from 'vscode'
3+
import { EditFormat } from '@shared/types/edit-format'
4+
5+
export const handle_get_edit_format_instructions = (
6+
provider: ViewProvider
7+
): void => {
8+
const config = vscode.workspace.getConfiguration('codeWebChat')
9+
const instructions = config.get<Record<EditFormat, string>>(
10+
'editFormatInstructions'
11+
)
12+
provider.send_message({
13+
command: 'EDIT_FORMAT_INSTRUCTIONS',
14+
instructions: instructions!
15+
})
16+
}

‎packages/vscode/src/views/panel/backend/message-handlers/handle-show-prompt-template-quick-pick.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type PromptTemplate = {
88
template: string
99
}
1010

11-
const ADD_NEW_TEMPLATE_LABEL = '$(add) Add new prompt template'
11+
const ADD_NEW_TEMPLATE_LABEL = '$(add) New prompt template'
1212

1313
export const handle_show_prompt_template_quick_pick = async (
1414
provider: ViewProvider

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './handle-edit-context'
2424
export * from './handle-code-completion'
2525
export * from './handle-get-edit-format'
2626
export * from './handle-at-sign-quick-pick'
27+
export * from './handle-get-edit-format-instructions'
2728
export * from './handle-get-mode-web'
2829
export * from './handle-get-mode-api'
2930
export * from './handle-save-mode-web'

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
handle_edit_context,
3131
handle_code_completion,
3232
handle_get_edit_format,
33+
handle_get_edit_format_instructions,
3334
handle_at_sign_quick_pick,
3435
handle_get_mode_web,
3536
handle_save_mode_web,
@@ -184,6 +185,10 @@ export class ViewProvider implements vscode.WebviewViewProvider {
184185
this.send_presets_to_webview(this._webview_view.webview)
185186
}
186187

188+
if (event.affectsConfiguration('codeWebChat.editFormatInstructions')) {
189+
handle_get_edit_format_instructions(this)
190+
}
191+
187192
const all_api_config_keys = [
188193
'codeWebChat.configurationsForEditContext',
189194
'codeWebChat.configurationsForCodeCompletions'
@@ -432,6 +437,8 @@ export class ViewProvider implements vscode.WebviewViewProvider {
432437
handle_get_mode_api(this)
433438
} else if (message.command == 'SAVE_API_MODE') {
434439
await handle_save_mode_api(this, message.mode)
440+
} else if (message.command == 'GET_EDIT_FORMAT_INSTRUCTIONS') {
441+
handle_get_edit_format_instructions(this)
435442
} else if (message.command == 'GET_EDIT_FORMAT') {
436443
handle_get_edit_format(this)
437444
} else if (message.command == 'SAVE_EDIT_FORMAT') {

‎packages/vscode/src/views/panel/frontend/Main/Main.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const Main: React.FC<Props> = (props) => {
6565
useState<string[]>()
6666
const [token_count, set_token_count] = useState<number>(0)
6767
const [chat_edit_format, set_chat_edit_format] = useState<EditFormat>()
68+
const [edit_format_instructions, set_edit_format_instructions] =
69+
useState<Record<EditFormat, string>>()
6870
const [api_edit_format, set_api_edit_format] = useState<EditFormat>()
6971
const [caret_position_to_set, set_caret_position_to_set] = useState<
7072
number | undefined
@@ -130,6 +132,9 @@ export const Main: React.FC<Props> = (props) => {
130132
set_chat_edit_format(message.chat_edit_format)
131133
set_api_edit_format(message.api_edit_format)
132134
break
135+
case 'EDIT_FORMAT_INSTRUCTIONS':
136+
set_edit_format_instructions(message.instructions)
137+
break
133138
case 'GIT_STATE_CHANGED':
134139
set_has_changes_to_commit(message.has_changes_to_commit)
135140
break
@@ -165,6 +170,7 @@ export const Main: React.FC<Props> = (props) => {
165170
{ command: 'GET_CURRENT_TOKEN_COUNT' },
166171
{ command: 'GET_INSTRUCTIONS' },
167172
{ command: 'GET_EDIT_FORMAT' },
173+
{ command: 'GET_EDIT_FORMAT_INSTRUCTIONS' },
168174
{ command: 'GET_API_TOOL_CONFIGURATIONS' },
169175
{ command: 'CHECK_CLIPBOARD_FOR_APPLY' },
170176
{ command: 'REQUEST_GIT_STATE' }
@@ -577,7 +583,8 @@ export const Main: React.FC<Props> = (props) => {
577583
is_in_code_completions_mode === undefined ||
578584
instructions === undefined ||
579585
chat_edit_format === undefined ||
580-
api_edit_format === undefined
586+
api_edit_format === undefined ||
587+
edit_format_instructions === undefined
581588
) {
582589
return <></>
583590
}
@@ -622,6 +629,7 @@ export const Main: React.FC<Props> = (props) => {
622629
on_api_mode_change={props.on_api_mode_change}
623630
chat_edit_format={chat_edit_format}
624631
api_edit_format={api_edit_format}
632+
edit_format_instructions={edit_format_instructions}
625633
on_chat_edit_format_change={handle_chat_edit_format_change}
626634
on_api_edit_format_change={handle_api_edit_format_change}
627635
on_presets_reorder={handle_presets_reorder}

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Props = {
5959
api_edit_format: EditFormat
6060
on_chat_edit_format_change: (edit_format: EditFormat) => void
6161
on_api_edit_format_change: (edit_format: EditFormat) => void
62+
edit_format_instructions: Record<EditFormat, string>
6263
on_presets_reorder: (reordered_presets: Preset[]) => void
6364
on_preset_edit: (preset_name: string) => void
6465
on_preset_duplicate: (preset_name: string) => void
@@ -342,19 +343,22 @@ export const MainView: React.FC<Props> = (props) => {
342343
value: 'whole',
343344
label: 'whole',
344345
title:
345-
'The model will output modified files in full. The best quality, especially from smaller models. Changed fragments are not clearly visible in a web chat interface.'
346+
'Whole instructions added to every message: ' +
347+
props.edit_format_instructions.whole
346348
},
347349
{
348350
value: 'truncated',
349351
label: 'truncated',
350352
title:
351-
'The model will skip unchanged fragments in modified files. Changes are clearly visible but requires Intelligent Update API tool to apply. Smaller, fast models like Gemini Flash are sufficient.'
353+
'Truncated instructions added to every message: ' +
354+
props.edit_format_instructions.truncated
352355
},
353356
{
354357
value: 'diff',
355358
label: 'diff',
356359
title:
357-
'The model will output patches. Less readable, cheap to generate and fast to apply. Models may struggle with diff correctness - might use the Intelligent Update API tool in a fallback mechanism.'
360+
'Diff instructions added to every message: ' +
361+
props.edit_format_instructions.diff
358362
}
359363
]}
360364
selected_value={

‎packages/vscode/src/views/panel/types/messages.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export interface GetEditFormat extends BaseMessage {
5050
command: 'GET_EDIT_FORMAT'
5151
}
5252

53+
export interface GetEditFormatInstructionsMessage extends BaseMessage {
54+
command: 'GET_EDIT_FORMAT_INSTRUCTIONS'
55+
}
56+
5357
export interface SaveEditFormatMessage extends BaseMessage {
5458
command: 'SAVE_EDIT_FORMAT'
5559
edit_format: EditFormat
@@ -303,6 +307,7 @@ export type FrontendMessage =
303307
| GetInstructionsMessage
304308
| SaveInstructionsMessage
305309
| GetEditFormat
310+
| GetEditFormatInstructionsMessage
306311
| SaveEditFormatMessage
307312
| GetConnectionStatusMessage
308313
| GetDonationsVisibilityMessage
@@ -376,6 +381,11 @@ export interface EditFormatMessage extends BaseMessage {
376381
api_edit_format: EditFormat
377382
}
378383

384+
export interface EditFormatInstructionsMessage extends BaseMessage {
385+
command: 'EDIT_FORMAT_INSTRUCTIONS'
386+
instructions: Record<EditFormat, string>
387+
}
388+
379389
export interface PresetsMessage extends BaseMessage {
380390
command: 'PRESETS'
381391
presets: { [T in WebMode]: Preset[] }
@@ -543,6 +553,7 @@ export type BackendMessage =
543553
| FocusChatInputMessage
544554
| ConnectionStatusMessage
545555
| EditFormatMessage
556+
| EditFormatInstructionsMessage
546557
| ApiToolConfigurationsMessage
547558
| DonationsVisibilityMessage
548559
| PresetsMessage

0 commit comments

Comments
 (0)