Skip to content

Feature: utility function to remove hunk from FileDiffMetadata #435

@jonatanklosko

Description

@jonatanklosko

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions