Skip to content

Commit e592af8

Browse files
committed
Add a settings section to configure edit format instructions
1 parent 29dbd51 commit e592af8

10 files changed

Lines changed: 171 additions & 2 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@
574574
"type": "string",
575575
"scope": "resource",
576576
"description": "System instructions for the Edit Context API tool.",
577-
"default": "You're a helpful coding assistant."
577+
"default": "You're a helpful coding assistant. Don't introduce redundant comments in code."
578578
},
579579
"codeWebChat.chatPresetsForAskAboutContext": {
580580
"type": "array",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_edit_format_instructions = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const instructions = config.get('editFormatInstructions') as {
9+
whole: string
10+
truncated: string
11+
diff: string
12+
}
13+
provider.postMessage({
14+
command: 'EDIT_FORMAT_INSTRUCTIONS',
15+
instructions
16+
})
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateEditFormatInstructionsMessage } from '@/views/settings/types/messages'
3+
4+
export const handle_update_edit_format_instructions = async (
5+
message: UpdateEditFormatInstructionsMessage
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
await config.update(
9+
'editFormatInstructions',
10+
message.instructions,
11+
vscode.ConfigurationTarget.Global
12+
)
13+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export * from './handle-add-edit-context-configuration'
2323
export * from './handle-edit-edit-context-configuration'
2424
export * from './handle-get-edit-context-system-instructions'
2525
export * from './handle-update-edit-context-system-instructions'
26+
export * from './handle-get-edit-format-instructions'
27+
export * from './handle-update-edit-format-instructions'
2628
export * from './handle-get-intelligent-update-configurations'
2729
export * from './handle-reorder-intelligent-update-configurations'
2830
export * from './handle-delete-intelligent-update-configuration'

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
handle_get_context_size_warning_threshold,
2727
handle_get_edit_context_configurations,
2828
handle_get_edit_context_system_instructions,
29+
handle_get_edit_format_instructions,
2930
handle_get_gemini_user_id,
3031
handle_get_intelligent_update_configurations,
3132
handle_get_model_providers,
@@ -42,6 +43,7 @@ import {
4243
handle_update_commit_message_instructions,
4344
handle_update_context_size_warning_threshold,
4445
handle_update_edit_context_system_instructions,
46+
handle_update_edit_format_instructions,
4547
handle_update_gemini_user_id
4648
} from './message-handlers'
4749

@@ -165,6 +167,12 @@ export class SettingsProvider {
165167
case 'UPDATE_EDIT_CONTEXT_SYSTEM_INSTRUCTIONS':
166168
await handle_update_edit_context_system_instructions(message)
167169
break
170+
case 'GET_EDIT_FORMAT_INSTRUCTIONS':
171+
await handle_get_edit_format_instructions(this)
172+
break
173+
case 'UPDATE_EDIT_FORMAT_INSTRUCTIONS':
174+
await handle_update_edit_format_instructions(message)
175+
break
168176
case 'GET_INTELLIGENT_UPDATE_CONFIGURATIONS':
169177
await handle_get_intelligent_update_configurations(this)
170178
break
@@ -257,6 +265,7 @@ export class SettingsProvider {
257265
void handle_get_commit_messages_configurations(this)
258266
void handle_get_edit_context_configurations(this)
259267
void handle_get_edit_context_system_instructions(this)
268+
void handle_get_edit_format_instructions(this)
260269
void handle_get_intelligent_update_configurations(this)
261270
void handle_get_context_size_warning_threshold(this)
262271
void handle_get_commit_message_instructions(this)

‎packages/vscode/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { Section } from '@ui/components/editor/settings/Section'
99
import { Textarea } from '@ui/components/editor/common/Textarea'
1010
import {
1111
ConfigurationForClient,
12-
ProviderForClient
12+
ProviderForClient,
13+
EditFormatInstructions
1314
} from '@/views/settings/types/messages'
1415
import { GeneralSection } from './sections/GeneralSection'
1516
import { PresetsSection } from './sections/PresetsSection'
@@ -61,6 +62,7 @@ type Props = {
6162
commit_message_instructions: string
6263
context_size_warning_threshold: number
6364
gemini_user_id: number | null
65+
edit_format_instructions: EditFormatInstructions
6466
clear_checks_in_workspace_behavior: 'ignore-open-editors' | 'uncheck-all'
6567

6668
// handlers
@@ -71,6 +73,9 @@ type Props = {
7173
set_commit_messages_configs: (configs: ConfigurationForClient[]) => void
7274
on_context_size_warning_threshold_change: (threshold: number) => void
7375
on_commit_instructions_change: (instructions: string) => void
76+
on_edit_format_instructions_change: (
77+
instructions: EditFormatInstructions
78+
) => void
7479
on_edit_context_system_instructions_change: (instructions: string) => void
7580
on_gemini_user_id_change: (id: number | null) => void
7681
on_clear_checks_in_workspace_behavior_change: (
@@ -276,6 +281,10 @@ export const Home: React.FC<Props> = (props) => {
276281
ref={(el) => (section_refs.current['presets'] = el)}
277282
gemini_user_id={props.gemini_user_id}
278283
on_gemini_user_id_change={props.on_gemini_user_id_change}
284+
edit_format_instructions={props.edit_format_instructions}
285+
on_edit_format_instructions_change={
286+
props.on_edit_format_instructions_change
287+
}
279288
on_stuck_change={presets_on_stuck_change}
280289
/>
281290
<Section

‎packages/vscode/src/views/settings/frontend/Home/sections/PresetsSection.tsx‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@ import { forwardRef, useEffect, useState } from 'react'
22
import { Input } from '@ui/components/editor/common/Input'
33
import { Item } from '@ui/components/editor/settings/Item'
44
import { Section } from '@ui/components/editor/settings/Section'
5+
import { Textarea } from '@ui/components/editor/common/Textarea'
6+
import { EditFormatInstructions } from '@/views/settings/types/messages'
57

68
type Props = {
79
gemini_user_id: number | null
10+
edit_format_instructions: EditFormatInstructions
811
on_gemini_user_id_change: (id: number | null) => void
12+
on_edit_format_instructions_change: (
13+
instructions: EditFormatInstructions
14+
) => void
915
on_stuck_change: (is_stuck: boolean) => void
1016
}
1117

1218
export const PresetsSection = forwardRef<HTMLDivElement, Props>(
1319
(props, ref) => {
1420
const [gemini_user_id_str, set_gemini_user_id_str] = useState('')
21+
const [instructions, set_instructions] = useState<EditFormatInstructions>({
22+
whole: '',
23+
truncated: '',
24+
diff: ''
25+
})
1526

1627
useEffect(() => {
1728
set_gemini_user_id_str(
@@ -21,6 +32,12 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
2132
)
2233
}, [props.gemini_user_id])
2334

35+
useEffect(() => {
36+
if (props.edit_format_instructions) {
37+
set_instructions(props.edit_format_instructions)
38+
}
39+
}, [props.edit_format_instructions])
40+
2441
useEffect(() => {
2542
const handler = setTimeout(() => {
2643
if (gemini_user_id_str == '') {
@@ -47,6 +64,23 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
4764
props.gemini_user_id
4865
])
4966

67+
useEffect(() => {
68+
const handler = setTimeout(() => {
69+
if (
70+
props.edit_format_instructions &&
71+
JSON.stringify(instructions) !==
72+
JSON.stringify(props.edit_format_instructions)
73+
) {
74+
props.on_edit_format_instructions_change(instructions)
75+
}
76+
}, 500)
77+
return () => clearTimeout(handler)
78+
}, [
79+
instructions,
80+
props.on_edit_format_instructions_change,
81+
props.edit_format_instructions
82+
])
83+
5084
return (
5185
<Section
5286
ref={ref}
@@ -66,6 +100,45 @@ export const PresetsSection = forwardRef<HTMLDivElement, Props>(
66100
/>
67101
}
68102
/>
103+
<Item
104+
title="'Whole' Edit Format Instructions"
105+
description="Instructions for generating code in 'whole' edit format."
106+
slot_placement="below"
107+
slot={
108+
<Textarea
109+
value={instructions.whole}
110+
on_change={(value) =>
111+
set_instructions((prev) => ({ ...prev, whole: value }))
112+
}
113+
/>
114+
}
115+
/>
116+
<Item
117+
title="'Truncated' Edit Format Instructions"
118+
description="Instructions for generating code in 'truncated' edit format."
119+
slot_placement="below"
120+
slot={
121+
<Textarea
122+
value={instructions.truncated}
123+
on_change={(value) =>
124+
set_instructions((prev) => ({ ...prev, truncated: value }))
125+
}
126+
/>
127+
}
128+
/>
129+
<Item
130+
title="'Diff' Edit Format Instructions"
131+
description="Instructions for generating code in 'diff' edit format."
132+
slot_placement="below"
133+
slot={
134+
<Textarea
135+
value={instructions.diff}
136+
on_change={(value) =>
137+
set_instructions((prev) => ({ ...prev, diff: value }))
138+
}
139+
/>
140+
}
141+
/>
69142
</Section>
70143
)
71144
}

‎packages/vscode/src/views/settings/frontend/Settings.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const Settings = () => {
3030
settings_hook.intelligent_update_configs !== undefined &&
3131
settings_hook.commit_message_instructions !== undefined &&
3232
settings_hook.context_size_warning_threshold !== undefined &&
33+
settings_hook.edit_format_instructions !== undefined &&
3334
settings_hook.gemini_user_id !== undefined &&
3435
settings_hook.clear_checks_in_workspace_behavior !== undefined
3536
)
@@ -63,6 +64,7 @@ export const Settings = () => {
6364
settings_hook.context_size_warning_threshold!
6465
}
6566
commit_message_instructions={settings_hook.commit_message_instructions!}
67+
edit_format_instructions={settings_hook.edit_format_instructions!}
6668
gemini_user_id={settings_hook.gemini_user_id!}
6769
clear_checks_in_workspace_behavior={
6870
settings_hook.clear_checks_in_workspace_behavior!
@@ -83,6 +85,9 @@ export const Settings = () => {
8385
on_edit_context_system_instructions_change={
8486
settings_hook.handle_edit_context_system_instructions_change
8587
}
88+
on_edit_format_instructions_change={
89+
settings_hook.handle_edit_format_instructions_change
90+
}
8691
on_clear_checks_in_workspace_behavior_change={
8792
settings_hook.handle_clear_checks_in_workspace_behavior_change
8893
}

‎packages/vscode/src/views/settings/frontend/hooks/use-settings.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from 'react'
22
import {
33
BackendMessage,
4+
EditFormatInstructions,
45
ConfigurationForClient,
56
ProviderForClient,
67
FrontendMessage
@@ -31,6 +32,9 @@ export const use_settings = (vscode: any) => {
3132
] = useState<string | undefined>(undefined)
3233
const [context_size_warning_threshold, set_context_size_warning_threshold] =
3334
useState<number | undefined>(undefined)
35+
const [edit_format_instructions, set_edit_format_instructions] = useState<
36+
EditFormatInstructions | undefined
37+
>(undefined)
3438
const [gemini_user_id, set_gemini_user_id] = useState<
3539
number | null | undefined
3640
>(undefined)
@@ -49,6 +53,7 @@ export const use_settings = (vscode: any) => {
4953
post_message(vscode, { command: 'GET_INTELLIGENT_UPDATE_CONFIGURATIONS' })
5054
post_message(vscode, { command: 'GET_COMMIT_MESSAGE_INSTRUCTIONS' })
5155
post_message(vscode, { command: 'GET_CONTEXT_SIZE_WARNING_THRESHOLD' })
56+
post_message(vscode, { command: 'GET_EDIT_FORMAT_INSTRUCTIONS' })
5257
post_message(vscode, { command: 'GET_GEMINI_USER_ID' })
5358
post_message(vscode, { command: 'GET_CLEAR_CHECKS_IN_WORKSPACE_BEHAVIOR' })
5459
}, [vscode])
@@ -81,6 +86,9 @@ export const use_settings = (vscode: any) => {
8186
case 'CONTEXT_SIZE_WARNING_THRESHOLD':
8287
set_context_size_warning_threshold(message.threshold)
8388
break
89+
case 'EDIT_FORMAT_INSTRUCTIONS':
90+
set_edit_format_instructions(message.instructions)
91+
break
8492
case 'GEMINI_USER_ID':
8593
set_gemini_user_id(message.geminiUserId)
8694
break
@@ -205,6 +213,14 @@ export const use_settings = (vscode: any) => {
205213
threshold
206214
})
207215

216+
const handle_edit_format_instructions_change = (
217+
instructions: EditFormatInstructions
218+
) =>
219+
post_message(vscode, {
220+
command: 'UPDATE_EDIT_FORMAT_INSTRUCTIONS',
221+
instructions
222+
})
223+
208224
const handle_gemini_user_id_change = (geminiUserId: number | null) =>
209225
post_message(vscode, {
210226
command: 'UPDATE_GEMINI_USER_ID',
@@ -233,6 +249,7 @@ export const use_settings = (vscode: any) => {
233249
commit_message_instructions,
234250
edit_context_system_instructions,
235251
context_size_warning_threshold,
252+
edit_format_instructions,
236253
gemini_user_id,
237254
clear_checks_in_workspace_behavior,
238255
handle_reorder_providers,
@@ -250,6 +267,7 @@ export const use_settings = (vscode: any) => {
250267
handle_edit_context_system_instructions_change,
251268
handle_open_editor_settings,
252269
handle_context_size_warning_threshold_change,
270+
handle_edit_format_instructions_change,
253271
handle_gemini_user_id_change,
254272
handle_clear_checks_in_workspace_behavior_change
255273
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export type ConfigurationForClient = {
1414
is_default?: boolean
1515
}
1616

17+
export type EditFormatInstructions = {
18+
whole: string
19+
truncated: string
20+
diff: string
21+
}
22+
1723
// === FROM FRONTEND TO BACKEND ===
1824
export interface GetModelProvidersMessage {
1925
command: 'GET_MODEL_PROVIDERS'
@@ -168,6 +174,15 @@ export interface UpdateEditContextSystemInstructionsMessage {
168174
instructions: string
169175
}
170176

177+
export interface GetEditFormatInstructionsMessage {
178+
command: 'GET_EDIT_FORMAT_INSTRUCTIONS'
179+
}
180+
181+
export interface UpdateEditFormatInstructionsMessage {
182+
command: 'UPDATE_EDIT_FORMAT_INSTRUCTIONS'
183+
instructions: EditFormatInstructions
184+
}
185+
171186
export interface SettingsUiReadyMessage {
172187
command: 'SETTINGS_UI_READY'
173188
}
@@ -237,6 +252,8 @@ export type FrontendMessage =
237252
| UpdateCommitMessageInstructionsMessage
238253
| GetEditContextSystemInstructionsMessage
239254
| UpdateEditContextSystemInstructionsMessage
255+
| GetEditFormatInstructionsMessage
256+
| UpdateEditFormatInstructionsMessage
240257
| SettingsUiReadyMessage
241258
| GetContextSizeWarningThresholdMessage
242259
| UpdateContextSizeWarningThresholdMessage
@@ -279,6 +296,11 @@ export interface EditContextSystemInstructionsMessage {
279296
instructions: string
280297
}
281298

299+
export interface EditFormatInstructionsMessage {
300+
command: 'EDIT_FORMAT_INSTRUCTIONS'
301+
instructions: EditFormatInstructions
302+
}
303+
282304
export interface ContextSizeWarningThresholdMessage {
283305
command: 'CONTEXT_SIZE_WARNING_THRESHOLD'
284306
threshold: number
@@ -307,6 +329,7 @@ export type BackendMessage =
307329
| CommitMessagesConfigurationsMessage
308330
| CommitMessageInstructionsMessage
309331
| EditContextSystemInstructionsMessage
332+
| EditFormatInstructionsMessage
310333
| ContextSizeWarningThresholdMessage
311334
| GeminiUserIdMessage
312335
| ClearChecksInWorkspaceBehaviorMessage

0 commit comments

Comments
 (0)