Skip to content

Commit 2862140

Browse files
committed
Triple hash heading to have high priority in when searching for file path
1 parent eb8d69e commit 2862140

4 files changed

Lines changed: 41 additions & 12 deletions

File tree

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/multiple-files-parser.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const parse_multiple_files = (params: {
121121
let in_cdata = false
122122
let backtick_nesting_level = 0
123123
let last_seen_file_path_comment: string | null = null
124+
let last_seen_file_path_was_header = false
124125
let is_markdown_container_block = false
125126
let current_language = ''
126127
let current_xml_tag: string | null = null
@@ -142,6 +143,7 @@ export const parse_multiple_files = (params: {
142143

143144
if (extracted_filename) {
144145
last_seen_file_path_comment = extracted_filename
146+
last_seen_file_path_was_header = false
145147
}
146148

147149
if (!extracted_filename) {
@@ -164,6 +166,7 @@ export const parse_multiple_files = (params: {
164166
const path = name_match[1] || name_match[2] || name_match[3]
165167
if (path) {
166168
last_seen_file_path_comment = path
169+
last_seen_file_path_was_header = false
167170
}
168171
} else {
169172
const parts = after_backticks.split(':')
@@ -175,6 +178,7 @@ export const parse_multiple_files = (params: {
175178
potential_path.includes('.')
176179
) {
177180
last_seen_file_path_comment = potential_path
181+
last_seen_file_path_was_header = false
178182
}
179183
} else {
180184
let extracted_filename: string | null = null
@@ -190,6 +194,7 @@ export const parse_multiple_files = (params: {
190194
}
191195
if (extracted_filename) {
192196
last_seen_file_path_comment = extracted_filename
197+
last_seen_file_path_was_header = false
193198
}
194199
}
195200
}
@@ -274,7 +279,24 @@ export const parse_multiple_files = (params: {
274279
}
275280

276281
let extracted_filename = extract_path_from_line_of_code(line)
282+
const is_header_line = line.trim().startsWith('###')
283+
277284
if (!extracted_filename) {
285+
if (is_header_line) {
286+
const header_content = line.trim().replace(/^###\s+/, '')
287+
const cleaned = header_content.replace(/^[`*]+|[`*]+$/g, '')
288+
const extracted = extract_path_from_line_of_code(cleaned)
289+
if (extracted) {
290+
extracted_filename = extracted
291+
} else if (
292+
(cleaned.includes('/') ||
293+
cleaned.includes('.') ||
294+
cleaned.includes('\\')) &&
295+
!cleaned.includes(' ')
296+
) {
297+
extracted_filename = cleaned
298+
}
299+
}
278300
const trimmed = line.trim()
279301
if (trimmed.startsWith('<!--') && trimmed.endsWith('-->')) {
280302
const potential_path = trimmed.slice(4, -3).trim()
@@ -343,12 +365,17 @@ export const parse_multiple_files = (params: {
343365
}
344366

345367
if (extracted_filename) {
346-
flush_text_block({
347-
text_block: current_text_block,
348-
results
349-
})
350-
current_text_block = ''
351-
last_seen_file_path_comment = extracted_filename
368+
if (last_seen_file_path_was_header && !is_header_line) {
369+
current_text_block += line + '\n'
370+
} else {
371+
flush_text_block({
372+
text_block: current_text_block,
373+
results
374+
})
375+
current_text_block = ''
376+
last_seen_file_path_comment = extracted_filename
377+
last_seen_file_path_was_header = is_header_line
378+
}
352379
} else {
353380
// Check if this line is a plain file path followed by a code block
354381
let is_lone_path_on_this_line = false
@@ -386,6 +413,7 @@ export const parse_multiple_files = (params: {
386413
}
387414
if (is_followed_by_code_block) {
388415
last_seen_file_path_comment = trimmed
416+
last_seen_file_path_was_header = false
389417
is_lone_path_on_this_line = true
390418
}
391419
}
@@ -589,6 +617,7 @@ export const parse_multiple_files = (params: {
589617

590618
if (current_file_name && !current_content.trim()) {
591619
last_seen_file_path_comment = current_file_name
620+
last_seen_file_path_was_header = false
592621
}
593622

594623
current_file_name = ''
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This new file
1+
Lorem ipsum `src/welcome.ts`.

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/path-above-code-block/path-above-code-block.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
**src/hello-world.ts**
1+
### **src/hello-world.ts**
22

3-
This new file
3+
Lorem ipsum `src/welcome.ts`.
44

55
```typescript
66
console.log('Hello world!')

packages/vscode/src/constants/edit-format-instructions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const EDIT_FORMAT_INSTRUCTIONS_WHOLE = `Whenever showing a new or updated file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/counter.py\`, ### Updated file: \`src/counter.py\`, ### Deleted file: \`src/counter.py\`), followed by a markdown code block with full contents—as I have a disability which means I can't type and need to be able to just copy and paste. Example:
1+
export const EDIT_FORMAT_INSTRUCTIONS_WHOLE = `Whenever showing a new or updated file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/hello.py\`, ### Updated file: \`src/hello.py\`, ### Deleted file: \`src/hello.py\`, ### Renamed file: \`src/hello.py\` (new) \`src/welcome.py\` (old)), followed by a markdown code block with full contents—as I have a disability which means I can't type and need to be able to just copy and paste. Example:
22
Updated the greeting text.
33
44
### Updated file: \`src/hello.py\`
@@ -10,7 +10,7 @@ def show_greeting():
1010
print(GREETING)
1111
\`\`\``
1212

13-
export const EDIT_FORMAT_INSTRUCTIONS_TRUNCATED = `Whenever showing a new or updated file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/counter.py\`, ### Updated file: \`src/counter.py\`, ### Deleted file: \`src/counter.py\`), followed by a markdown code block with truncated contents—as a space saving measure unchanged parts should be hidden behind ellipsis comments, e.g. "# ... ". Example:
13+
export const EDIT_FORMAT_INSTRUCTIONS_TRUNCATED = `Whenever showing a new or updated file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/hello.py\`, ### Updated file: \`src/hello.py\`, ### Deleted file: \`src/hello.py\`, ### Renamed file: \`src/hello.py\` (new) \`src/welcome.py\` (old)), followed by a markdown code block with truncated contents—as a space saving measure unchanged parts should be hidden behind ellipsis comments, e.g. "# ... ". Example:
1414
Updated the greeting text.
1515
1616
### Updated file: \`src/hello.py\`
@@ -22,7 +22,7 @@ def show_greeting():
2222
# ... the function remains unchanged
2323
\`\`\``
2424

25-
export const EDIT_FORMAT_INSTRUCTIONS_DIFF = `Whenever showing a new, updated, renamed or deleted file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/counter.py\`, ### Updated file: \`src/counter.py\`, ### Deleted file: \`src/counter.py\`), followed by a unified diff within a markdown code block. Example:
25+
export const EDIT_FORMAT_INSTRUCTIONS_DIFF = `Whenever showing a new, updated, renamed or deleted file, provide brief explanation, then print path in a markdown heading (e.g. ### New file: \`src/hello.py\`, ### Updated file: \`src/hello.py\`, ### Deleted file: \`src/hello.py\`, ### Renamed file: \`src/hello.py\` (new) \`src/welcome.py\` (old)), followed by a unified diff within a markdown code block. Example:
2626
Updated the greeting text.
2727
2828
### Updated file: \`src/hello.py\`

0 commit comments

Comments
 (0)