You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
feat(diff): use diff-match-patch for better diff handling (#1407)
Refactored diff utility to use diff-match-patch for unified diffapplication, improving reliability and handling of ambiguous hunks.Updated buffer patching and region detection to use new approach.Adjusted tests to match new diff API and behaviors.Added vendor diff_match_patch implementation.Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
Copy file name to clipboardExpand all lines: lua/CopilotChat/instructions/edit_file_unified.lua
+23-57Lines changed: 23 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -2,67 +2,33 @@ return [[
2
2
<editFileInstructions>
3
3
Return edits similar to unified diffs that `diff -U0` would produce.
4
4
5
-
- Always include the first 2 lines with the file paths (no timestamps).
6
-
- Start each hunk of changes with a `@@ ... @@` line.
7
-
- Do not include line numbers in the hunk header.
8
-
- The user's patch tool needs CORRECT patches that apply cleanly against the current contents of the file.
9
-
- Indentation matters in the diffs!
5
+
Make sure you include the first 2 lines with the file paths.
6
+
Don't include timestamps with the file paths.
7
+
Do not use any file path prefixes, just use --- path/to/file and +++ path/to/file.
10
8
11
-
Context lines:
12
-
- For each hunk that contains changes, you MUST always include 2-3 context lines before the change.
13
-
- ALWAYS prefix every context line with a single space character.
14
-
- Context lines MUST ONLY appear BEFORE changes, NEVER after changes.
15
-
- MISSING CONTEXT LINES WILL CAUSE PATCH FAILURES - they are mandatory, not optional.
16
-
- MISSING SPACE PREFIXES WILL CAUSE PATCH FAILURES - they are mandatory, not optional.
9
+
Start each hunk of changes with a `@@` line.
17
10
18
-
Change lines:
19
-
- Mark all lines to be removed or changed with `-`.
20
-
- Mark all new or modified lines with `+`.
21
-
- Only output hunks that specify changes with `+` or `-` lines.
11
+
The user's patch tool needs CORRECT patches that apply cleanly against the current contents of the file!
12
+
Code can start with line number prefixes for reference (e.g., `1: def example():`), but your output MUST NOT include these line number prefixes.
13
+
Think carefully and make sure you include and mark all lines that need to be removed or changed as `-` lines.
14
+
Make sure you mark all new or modified lines with `+`.
15
+
Don't leave out any lines or the diff patch won't apply correctly.
22
16
23
-
Other instructions:
24
-
- Start a new hunk for each section of the file that needs changes.
25
-
- When editing a function, method, loop, etc., replace the entire code block: delete the entire existing version with `-` lines, then add the new, updated version with `+` lines.
26
-
- To move code within a file, use 2 hunks: one to delete it from its current location, one to insert it in the new location.
27
-
- To make a new file, show a diff from `--- /dev/null` to `+++ path/to/new/file.ext`.
17
+
Indentation matters in the diffs!
28
18
29
-
Example:
19
+
Start a new hunk for each section of the file that needs changes.
30
20
31
-
```diff
32
-
--- mathweb/flask/app.py
33
-
+++ mathweb/flask/app.py
34
-
@@ ... @@
35
-
-class MathWeb:
36
-
+import sympy
37
-
+
38
-
+class MathWeb:
39
-
@@ ... @@
40
-
-def is_prime(x):
41
-
- if x < 2:
42
-
- return False
43
-
- for i in range(2, int(math.sqrt(x)) + 1):
44
-
- if x % i == 0:
45
-
- return False
46
-
- return True
47
-
@@ ... @@
48
-
-@app.route('/prime/<int:n>')
49
-
-def nth_prime(n):
50
-
- count = 0
51
-
- num = 1
52
-
- while count < n:
53
-
- num += 1
54
-
- if is_prime(num):
55
-
- count += 1
56
-
- return str(num)
57
-
+@app.route('/prime/<int:n>')
58
-
+def nth_prime(n):
59
-
+ count = 0
60
-
+ num = 1
61
-
+ while count < n:
62
-
+ num += 1
63
-
+ if sympy.isprime(num):
64
-
+ count += 1
65
-
+ return str(num)
66
-
```
21
+
Only output hunks that specify changes with `+` or `-` lines.
22
+
23
+
Output hunks in whatever order makes the most sense.
24
+
Hunks don't need to be in any particular order.
25
+
26
+
When editing a function, method, loop, etc use a hunk to replace the *entire* code block.
27
+
Delete the entire existing version with `-` lines and then add a new, updated version with `+` lines.
28
+
This will help you generate correct code and correct diffs.
29
+
30
+
To move code within a file, use 2 hunks: 1 to delete it from its current location, 1 to insert it in the new location.
31
+
32
+
To make a new file, show a diff from `--- /dev/null` to `+++ path/to/new/file.ext`.