Skip to content

Commit c30dd01

Browse files
committed
Refactor #Changes: placeholder replacement to conditionally include file contents based on whether the prompt mode is 'no-context'
1 parent 65b9397 commit c30dd01

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

‎packages/vscode/src/views/panel/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,14 @@ export const handle_copy_prompt = async (params: {
103103
let post_context_instructions = instructions
104104

105105
if (instructions.includes('#Changes:')) {
106+
const is_no_context_web_mode =
107+
params.panel_provider.mode == MODE.WEB &&
108+
params.panel_provider.web_prompt_type == 'no-context'
109+
106110
pre_context_instructions = await replace_changes_placeholder({
107111
instruction: pre_context_instructions,
108-
workspace_provider: params.panel_provider.workspace_provider
112+
workspace_provider: params.panel_provider.workspace_provider,
113+
is_no_context_web_mode
109114
})
110115
post_context_instructions = await replace_changes_placeholder({
111116
instruction: post_context_instructions,

‎packages/vscode/src/views/panel/backend/message-handlers/handle-preview-preset.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@/views/panel/backend/utils/replace-git-placeholders'
1111
import { Preset } from '@shared/types/preset'
1212
import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixes'
13+
import { MODE } from '@/views/panel/types/main-view-mode'
1314
import { dictionary } from '@shared/constants/dictionary'
1415

1516
export const handle_preview_preset = async (
@@ -98,9 +99,14 @@ export const handle_preview_preset = async (
9899
let post_context_instructions = instructions
99100

100101
if (pre_context_instructions.includes('#Changes:')) {
102+
const is_no_context_web_mode =
103+
panel_provider.mode == MODE.WEB &&
104+
panel_provider.web_prompt_type == 'no-context'
105+
101106
pre_context_instructions = await replace_changes_placeholder({
102107
instruction: pre_context_instructions,
103-
workspace_provider: panel_provider.workspace_provider
108+
workspace_provider: panel_provider.workspace_provider,
109+
is_no_context_web_mode
104110
})
105111
post_context_instructions = await replace_changes_placeholder({
106112
instruction: post_context_instructions,

‎packages/vscode/src/views/panel/backend/message-handlers/handle-send-prompt.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,14 @@ export const handle_send_prompt = async (params: {
179179
let pre_context_instructions = instructions
180180
let post_context_instructions = instructions
181181
if (pre_context_instructions.includes('#Changes:')) {
182+
const is_no_context_web_mode =
183+
params.panel_provider.mode == MODE.WEB &&
184+
params.panel_provider.web_prompt_type == 'no-context'
185+
182186
pre_context_instructions = await replace_changes_placeholder({
183187
instruction: pre_context_instructions,
184-
workspace_provider: params.panel_provider.workspace_provider
188+
workspace_provider: params.panel_provider.workspace_provider,
189+
is_no_context_web_mode
185190
})
186191
post_context_instructions = await replace_changes_placeholder({
187192
instruction: post_context_instructions,

‎packages/vscode/src/views/panel/backend/utils/replace-git-placeholders.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { dictionary } from '@shared/constants/dictionary'
1010
const build_changes_xml = (
1111
diff: string,
1212
cwd: string,
13-
workspace_provider: WorkspaceProvider
13+
workspace_provider: WorkspaceProvider,
14+
is_no_context_web_mode?: boolean
1415
): string => {
1516
// Split diff into per-file sections. Each section starts with 'diff --git '.
1617
const file_diffs = diff.split(/^diff --git /m).filter((d) => d.trim() != '')
@@ -52,7 +53,7 @@ const build_changes_xml = (
5253
changes_content += `<diff>\n<![CDATA[\n${full_file_diff}\n]]>\n</diff>\n`
5354

5455
const absolute_path = path.join(cwd, file_path)
55-
if (checked_files.has(absolute_path)) {
56+
if (!is_no_context_web_mode && checked_files.has(absolute_path)) {
5657
const workspace_root =
5758
workspace_provider.get_workspace_root_for_file(absolute_path)
5859
let display_path: string
@@ -101,7 +102,8 @@ const build_changes_xml = (
101102
export const replace_changes_placeholder = async (params: {
102103
instruction: string
103104
after_context?: boolean
104-
workspace_provider: WorkspaceProvider
105+
workspace_provider: WorkspaceProvider,
106+
is_no_context_web_mode?: boolean
105107
}): Promise<string> => {
106108
const matches = params.instruction.match(
107109
/#Changes:([^\s,;:.!?]+(?:\/[^\s,;:.!?]+)?)/
@@ -181,7 +183,8 @@ export const replace_changes_placeholder = async (params: {
181183
const replacement_text = build_changes_xml(
182184
diff,
183185
target_folder.uri.fsPath,
184-
params.workspace_provider
186+
params.workspace_provider,
187+
params.is_no_context_web_mode
185188
)
186189
return params.instruction.replace(
187190
new RegExp(`#Changes:${branch_spec}`, 'g'),
@@ -249,7 +252,8 @@ export const replace_changes_placeholder = async (params: {
249252
const replacement_text = build_changes_xml(
250253
diff,
251254
repository.rootUri.fsPath,
252-
params.workspace_provider
255+
params.workspace_provider,
256+
params.is_no_context_web_mode
253257
)
254258
return params.instruction.replace(
255259
new RegExp(`#Changes:${branch_name}`, 'g'),

0 commit comments

Comments
 (0)