Skip to content

Commit 9877d43

Browse files
committed
Simplify git symbol replacement by removing unused parameters and improving commit message parsing
1 parent 721f62a commit 9877d43

5 files changed

Lines changed: 10 additions & 60 deletions

File tree

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,8 @@ export const handle_copy_prompt = async (params: {
111111
let processed_instructions = instructions
112112

113113
if (processed_instructions.includes('#Changes:')) {
114-
const is_no_context_web_mode =
115-
params.panel_provider.mode == MODE.WEB &&
116-
params.panel_provider.web_prompt_type == 'no-context'
117-
118114
processed_instructions = await replace_changes_symbol({
119-
instruction: processed_instructions,
120-
workspace_provider: params.panel_provider.workspace_provider,
121-
is_no_context_web_mode
115+
instruction: processed_instructions
122116
})
123117
}
124118

@@ -139,7 +133,7 @@ export const handle_copy_prompt = async (params: {
139133
processed_instructions = await replace_saved_context_placeholder({
140134
instruction: processed_instructions,
141135
context: params.panel_provider.context,
142-
workspace_provider: params.panel_provider.workspace_provider,
136+
workspace_provider: params.panel_provider.workspace_provider
143137
})
144138
}
145139

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ const perform_context_editing = async (params: {
258258

259259
if (processed_instructions.includes('#Changes:')) {
260260
processed_instructions = await replace_changes_symbol({
261-
instruction: processed_instructions,
262-
workspace_provider: params.file_tree_provider
261+
instruction: processed_instructions
263262
})
264263
}
265264

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@/views/panel/backend/utils/replace-git-symbols'
1212
import { Preset } from '@shared/types/preset'
1313
import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixes'
14-
import { MODE } from '@/views/panel/types/main-view-mode'
1514
import { dictionary } from '@shared/constants/dictionary'
1615
import {
1716
EDIT_FORMAT_INSTRUCTIONS_WHOLE,
@@ -102,14 +101,8 @@ export const handle_preview_preset = async (
102101
let processed_instructions = instructions
103102

104103
if (processed_instructions.includes('#Changes:')) {
105-
const is_no_context_web_mode =
106-
panel_provider.mode == MODE.WEB &&
107-
panel_provider.web_prompt_type == 'no-context'
108-
109104
processed_instructions = await replace_changes_symbol({
110-
instruction: processed_instructions,
111-
workspace_provider: panel_provider.workspace_provider,
112-
is_no_context_web_mode
105+
instruction: processed_instructions
113106
})
114107
}
115108

@@ -130,7 +123,7 @@ export const handle_preview_preset = async (
130123
processed_instructions = await replace_saved_context_placeholder({
131124
instruction: processed_instructions,
132125
context: panel_provider.context,
133-
workspace_provider: panel_provider.workspace_provider,
126+
workspace_provider: panel_provider.workspace_provider
134127
})
135128
}
136129

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,8 @@ export const handle_send_prompt = async (params: {
185185

186186
let processed_instructions = instructions
187187
if (processed_instructions.includes('#Changes:')) {
188-
const is_no_context_web_mode =
189-
params.panel_provider.mode == MODE.WEB &&
190-
params.panel_provider.web_prompt_type == 'no-context'
191-
192188
processed_instructions = await replace_changes_symbol({
193-
instruction: processed_instructions,
194-
workspace_provider: params.panel_provider.workspace_provider,
195-
is_no_context_web_mode
189+
instruction: processed_instructions
196190
})
197191
}
198192

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

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ const build_changes_markdown = (
8484

8585
export const replace_changes_symbol = async (params: {
8686
instruction: string
87-
after_context?: boolean
88-
workspace_provider: WorkspaceProvider
89-
is_no_context_web_mode?: boolean
9087
}): Promise<string> => {
9188
const matches = params.instruction.match(
9289
/#Changes:([^\s,;:.!?]+(?:\/[^\s,;:.!?]+)?)/
@@ -97,20 +94,6 @@ export const replace_changes_symbol = async (params: {
9794

9895
const branch_spec = matches[1]
9996

100-
if (params.after_context) {
101-
let branch_name = branch_spec
102-
const multi_root_match = branch_spec.match(/^([^/]+)\/(.+)$/)
103-
104-
if (multi_root_match) {
105-
branch_name = multi_root_match[2]
106-
}
107-
108-
return params.instruction.replace(
109-
new RegExp(`#Changes:${branch_spec}`, 'g'),
110-
`(Changes against ${branch_name} branch)`
111-
)
112-
}
113-
11497
const multi_root_match = branch_spec.match(/^([^/]+)\/(.+)$/)
11598

11699
if (multi_root_match) {
@@ -354,18 +337,8 @@ const build_commit_changes_markdown = (
354337

355338
export const replace_commit_symbol = async (params: {
356339
instruction: string
357-
after_context?: boolean
358340
}): Promise<string> => {
359-
const regex = /#Commit:([^:]+):([a-fA-F0-9]+)\s*(?:"([^"]*)")?/g
360-
if (params.after_context) {
361-
return params.instruction.replace(
362-
regex,
363-
(_match, _folder_name, _commit_hash, commit_message) => {
364-
if (commit_message) return `(Commit: ${commit_message})`
365-
return '(Commit)'
366-
}
367-
)
368-
}
341+
const regex = /#Commit:([^:]+):([a-fA-F0-9]+)\s*(?:"((?:[^"\\]|\\.)*)")?/g
369342

370343
let result_instruction = params.instruction
371344
const matches = [...result_instruction.matchAll(regex)]
@@ -379,7 +352,7 @@ export const replace_commit_symbol = async (params: {
379352
const full_match = match[0]
380353
const folder_name = match[1]
381354
const commit_hash = match[2]
382-
const commit_message = match[3]
355+
const commit_message = match[3]?.replace(/\\(.)/g, '$1')
383356

384357
const target_folder = workspace_folders.find(
385358
(folder) => folder.name === folder_name
@@ -452,13 +425,10 @@ const build_context_at_commit_xml = (
452425

453426
export const replace_context_at_commit_symbol = async (params: {
454427
instruction: string
455-
after_context?: boolean
456428
workspace_provider: WorkspaceProvider
457429
}): Promise<string> => {
458-
const regex = /#ContextAtCommit:([^:]+):([a-fA-F0-9]+)\s*(?:"([^"]*)")?/g
459-
if (params.after_context) {
460-
return params.instruction.replace(regex, '<archive/>')
461-
}
430+
const regex =
431+
/#ContextAtCommit:([^:]+):([a-fA-F0-9]+)\s*(?:"((?:[^"\\]|\\.)*)")?/g
462432

463433
let result_instruction = params.instruction
464434
const matches = [...result_instruction.matchAll(regex)]

0 commit comments

Comments
 (0)