Prerequisites
Proposal
Provide diffRemoveHunk(diff, index) utility function to remove a specific hunk from FileDiffMetadata.
It may be tempting to simply remove the hunk manually from the FileDiffMetadata data structure, however it contains a number of inferred/dependent fields, such as unifiedLineCount, splitLineCount, and those may need to be recomputed after removing the hunk. The library user could figure out which fields need to be updated, but even then, a future release of the library may add a new computed field, and that would break the user logic. To avoid brittle code, the user should assume that FileDiffMetadata is read-only and therefore having utility functions like diffRemoveHunk provides a way to manipulate it reliably.
Motivation and context
Currently diffAcceptRejectHunk is available, however in some cases it may be desirable to remove the hunk altogether. Specifically, if the diff comes from a git diff, one may want to reload the diff once hunk is accepted/resolved, and in such case diffRemoveHunk would allow updating state optimistically.
Also see prior discussion in #427 (comment).
Prerequisites
Proposal
Provide
diffRemoveHunk(diff, index)utility function to remove a specific hunk fromFileDiffMetadata.It may be tempting to simply remove the hunk manually from the
FileDiffMetadatadata structure, however it contains a number of inferred/dependent fields, such asunifiedLineCount,splitLineCount, and those may need to be recomputed after removing the hunk. The library user could figure out which fields need to be updated, but even then, a future release of the library may add a new computed field, and that would break the user logic. To avoid brittle code, the user should assume thatFileDiffMetadatais read-only and therefore having utility functions likediffRemoveHunkprovides a way to manipulate it reliably.Motivation and context
Currently
diffAcceptRejectHunkis available, however in some cases it may be desirable to remove the hunk altogether. Specifically, if the diff comes from agit diff, one may want to reload the diff once hunk is accepted/resolved, and in such casediffRemoveHunkwould allow updating state optimistically.Also see prior discussion in #427 (comment).