tree-sitter-diff icon indicating copy to clipboard operation
tree-sitter-diff copied to clipboard

Support comments for manually editing hunks

Open ValdezFOmar opened this issue 1 year ago • 1 comments

When you manually edit a hunk with git add --patch file, git creates sort of a 'diff' file with comments (lines starting with # similar to git commit -e) that you can manually edit, but currently those comments are parsed as context nodes.

Example:
# Manual hunk edit mode -- see bottom for a quick guide.
@@ -32,20 +32,19 @@ body {
     max-width: 800px;
     min-height: 100%;
     background-color: var(--bg);
-    padding: 1.5rem 2rem;
+    padding: 0.5rem 2rem 1rem;
     box-shadow: 0 0 40px 40px #070707EE;
 }
 
-
 p {
     text-align: justify;
-    line-height: 1.3;
 }
 
 p,
 ul,
 ol {
     letter-spacing: 0.5px;
+    line-height: 1.3;
 }
 
 :is(ul, ol) li {
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
# If the patch applies cleanly, the edited hunk will immediately be marked for staging.
# If it does not apply cleanly, you will be given an opportunity to
# edit again.  If all lines of the hunk are removed, then the edit is
# aborted and the hunk is left unchanged.
Tree
(context) ; [1:1 - 56]
(location) ; [2:1 - 26]
 (linerange) ; [2:4 - 9]
 (linerange) ; [2:11 - 16]
(context) ; [3:1 - 22]
(context) ; [4:1 - 22]
(context) ; [5:1 - 33]
(deletion) ; [6:1 - 26]
(addition) ; [7:1 - 31]
(context) ; [8:1 - 41]
(context) ; [9:1 - 2]
(deletion) ; [11:1 - 1]
(context) ; [12:1 - 4]
(context) ; [13:1 - 25]
(deletion) ; [14:1 - 22]
(context) ; [15:1 - 2]
(context) ; [17:1 - 3]
(context) ; [18:1 - 4]
(context) ; [19:1 - 5]
(context) ; [20:1 - 27]
(addition) ; [21:1 - 22]
(context) ; [22:1 - 2]
(context) ; [24:1 - 17]
(context) ; [25:1 - 5]
(context) ; [26:1 - 53]
(context) ; [27:1 - 35]
(context) ; [28:1 - 40]
(context) ; [29:1 - 87]
(context) ; [30:1 - 67]
(context) ; [31:1 - 69]
(context) ; [32:1 - 41]

ValdezFOmar avatar Apr 30 '24 03:04 ValdezFOmar

I think this would be ok to add. The # at the line start is unique so it should be unambiguous

the-mikedavis avatar Apr 30 '24 15:04 the-mikedavis