Skip to content

Commit 32cf855

Browse files
committed
Refactor settings management to handle editContextSystemInstructions, commitMessageInstructions, geminiUserId, and clearChecksInWorkspaceBehavior via dedicated backend message handlers
1 parent f3ca11f commit 32cf855

18 files changed

Lines changed: 278 additions & 101 deletions

‎packages/ui/src/components/editor/settings/Section/Section.module.scss‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
var(--padding-60px) + var(--padding-4px)
2323
); // to align with the sidebar title
2424
padding-bottom: var(--padding-10px);
25+
padding-left: var(--padding-12px);
26+
padding-right: var(--padding-12px);
2527
background-color: var(--vscode-editor-background);
2628
transition: box-shadow var(--transition-duration-250)
2729
var(--transition-timing-function);

‎packages/vscode/package.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@
570570
}
571571
}
572572
},
573+
"codeWebChat.editContextSystemInstructions": {
574+
"type": "string",
575+
"scope": "resource",
576+
"description": "System instructions for the Edit Context API tool.",
577+
"default": "You're a helpful coding assistant."
578+
},
573579
"codeWebChat.chatPresetsForAskAboutContext": {
574580
"type": "array",
575581
"default": [

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const extract_workspace_and_path = (params: {
6767
}
6868

6969
export const has_real_code = (content: string): boolean => {
70-
if (content.trim() === '') {
70+
if (content.trim() == '') {
7171
return true
7272
}
7373
const lines = content.split('\n')
@@ -104,21 +104,19 @@ export const parse_response = (params: {
104104
const processed_response = params.response.replace(/``````/g, '```\n```')
105105

106106
const hunk_header_regex = /^(@@\s+-\d+(?:,\d+)?\s+\+\d+(?:,\d+)?\s+@@)/m
107+
const has_diff_lines_regex = /^[+-] /m
107108

108109
if (
109-
processed_response.includes('```diff') ||
110-
processed_response.includes('```patch') ||
111-
processed_response.startsWith('--- ') ||
112-
processed_response.startsWith('diff --git') ||
113-
hunk_header_regex.test(processed_response)
110+
hunk_header_regex.test(processed_response) &&
111+
has_diff_lines_regex.test(processed_response)
114112
) {
115113
const patches_or_text = extract_diffs({
116114
clipboard_text: processed_response,
117115
is_single_root: is_single_root_folder_workspace
118116
})
119117
if (patches_or_text.length) {
120118
return patches_or_text.map((item) => {
121-
if ('type' in item && item.type === 'text') {
119+
if ('type' in item && item.type == 'text') {
122120
return item
123121
}
124122
return { type: 'diff', ...item }

‎packages/vscode/src/views/panel/backend/message-handlers/handle-edit-context.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,14 @@ const perform_context_editing = async (params: {
356356
content = `${loop_pre_context_instructions}\n${files}\n${loop_post_context_instructions}`
357357
}
358358

359+
const system_instructions = vscode.workspace
360+
.getConfiguration('codeWebChat')
361+
.get<string>('editContextSystemInstructions')
362+
359363
const messages = [
360364
{
361365
role: 'system',
362-
content: "You're a helpful coding assistant."
366+
content: system_instructions
363367
},
364368
{
365369
role: 'user',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_clear_checks_in_workspace_behavior = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const value = config.get<'ignore-open-editors' | 'uncheck-all'>(
9+
'clearChecksInWorkspaceBehavior',
10+
'ignore-open-editors'
11+
)
12+
provider.postMessage({
13+
command: 'CLEAR_CHECKS_IN_WORKSPACE_BEHAVIOR',
14+
value
15+
})
16+
}
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 { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_commit_message_instructions = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const instructions = config.get<string>('commitMessageInstructions') || ''
9+
provider.postMessage({
10+
command: 'COMMIT_MESSAGE_INSTRUCTIONS',
11+
instructions
12+
})
13+
}
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 { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_edit_context_system_instructions = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const instructions = config.get<string>('editContextSystemInstructions') || ''
9+
provider.postMessage({
10+
command: 'EDIT_CONTEXT_SYSTEM_INSTRUCTIONS',
11+
instructions
12+
})
13+
}
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 { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
4+
export const handle_get_gemini_user_id = async (
5+
provider: SettingsProvider
6+
): Promise<void> => {
7+
const config = vscode.workspace.getConfiguration('codeWebChat')
8+
const geminiUserId = config.get<number | null>('geminiUserId') ?? null
9+
provider.postMessage({
10+
command: 'GEMINI_USER_ID',
11+
geminiUserId
12+
})
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { UpdateClearChecksInWorkspaceBehaviorMessage } from '@/views/settings/types/messages'
4+
5+
export const handle_update_clear_checks_in_workspace_behavior = async (
6+
provider: SettingsProvider,
7+
message: UpdateClearChecksInWorkspaceBehaviorMessage
8+
): Promise<void> => {
9+
await vscode.workspace
10+
.getConfiguration('codeWebChat')
11+
.update(
12+
'clearChecksInWorkspaceBehavior',
13+
message.value,
14+
vscode.ConfigurationTarget.Global
15+
)
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode'
2+
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { UpdateCommitMessageInstructionsMessage } from '@/views/settings/types/messages'
4+
5+
export const handle_update_commit_message_instructions = async (
6+
provider: SettingsProvider,
7+
message: UpdateCommitMessageInstructionsMessage
8+
): Promise<void> => {
9+
await vscode.workspace
10+
.getConfiguration('codeWebChat')
11+
.update(
12+
'commitMessageInstructions',
13+
message.instructions,
14+
vscode.ConfigurationTarget.Global
15+
)
16+
}

0 commit comments

Comments
 (0)