mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 04:41:16 -05:00
refactor: improve NewUnifiedDiffStrategy with enhanced formatting and error handling
- Cleaned up formatting in the parseUnifiedDiff method to ensure consistent indentation and spacing. - Updated documentation to clarify format requirements for generating unified diffs. - Added error handling for cases where no hunks are found in the provided diff, improving robustness. - Enhanced overall readability of the code by standardizing comments and structure.
This commit is contained in:
@@ -102,7 +102,7 @@ export class NewUnifiedDiffStrategy implements DiffStrategy {
|
|||||||
) {
|
) {
|
||||||
hunks.push(currentHunk)
|
hunks.push(currentHunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { hunks }
|
return { hunks }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ If you need to move code within a file, create two hunks: one to delete the code
|
|||||||
|
|
||||||
To create a new file, show a diff from "--- /dev/null" to "+++ path/to/new/file.ext".
|
To create a new file, show a diff from "--- /dev/null" to "+++ path/to/new/file.ext".
|
||||||
|
|
||||||
Here’s an example of the desired format:
|
Format Requirements:
|
||||||
|
|
||||||
\`\`\`diff
|
\`\`\`diff
|
||||||
--- mathweb/flask/app.py
|
--- mathweb/flask/app.py
|
||||||
@@ -171,6 +171,10 @@ Here’s an example of the desired format:
|
|||||||
|
|
||||||
Be precise, consistent, and follow these rules carefully to generate correct diffs!
|
Be precise, consistent, and follow these rules carefully to generate correct diffs!
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- path: (required) The path of the file to apply the diff to (relative to the current working directory ${cwd})
|
||||||
|
- diff: (required) The diff content in unified format to apply to the file.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
<apply_diff>
|
<apply_diff>
|
||||||
<path>File path here</path>
|
<path>File path here</path>
|
||||||
@@ -191,6 +195,10 @@ Your diff here
|
|||||||
const originalLines = originalContent.split("\n")
|
const originalLines = originalContent.split("\n")
|
||||||
let result = [...originalLines]
|
let result = [...originalLines]
|
||||||
|
|
||||||
|
if (!parsedDiff.hunks.length) {
|
||||||
|
return { success: false, error: "No hunks found in diff" }
|
||||||
|
}
|
||||||
|
|
||||||
for (const hunk of parsedDiff.hunks) {
|
for (const hunk of parsedDiff.hunks) {
|
||||||
const contextStr = prepareSearchString(hunk.changes)
|
const contextStr = prepareSearchString(hunk.changes)
|
||||||
const { index: matchPosition, confidence } = findBestMatch(contextStr, result)
|
const { index: matchPosition, confidence } = findBestMatch(contextStr, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user