Skip to content

Single line change parse issue with "normal" chunk headers #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DavisVaughan opened this issue Apr 27, 2025 · 3 comments
Closed

Single line change parse issue with "normal" chunk headers #36

DavisVaughan opened this issue Apr 27, 2025 · 3 comments

Comments

@DavisVaughan
Copy link

See parkerbxyz/suggest-changes#50 (comment)

The TLDR is that it seems like parse-git-diff can handle @@ -74,2 +74 @@, but for 1 line changes git will omit the ,1 and just report @@ -74 +74 @@ and that causes the regex handling in parse-git-diff to break.

I see the "normal" chunk regex here:

const normalChunkExec =
/^@@\s\-(\d+),?(\d+)?\s\+(\d+),?(\d+)?\s@@\s?(.+)?/.exec(line);

Which gets expanded out here:

const [all, delStart, delLines, addStart, addLines, context] =
normalChunkExec;

I'm no expert here but I think whats happening is that it has an optional capture group for the ,<digit> which should become delLines, but that's missing here so instead the next capture group actually gets put in as delLines, which happens to be addStart, which is 94, so it reports 94 lines in fromFileRange 😢

@yeonjuan
Copy link
Owner

Sorry for the late response. I'll make the correction.

@yeonjuan
Copy link
Owner

yeonjuan commented May 18, 2025

Hi @DavisVaughan , It's not reproduced in v0.0.17. Maybe it was fixed in #34?

(updated) I've noticed that it reproduces in 0.0.16 but not in 0.0.17. Updating the version should resolve it.

  • input
diff --git a/R/hop2.R b/R/hop2.R
index 7f5e285..2658b32 100644
--- a/R/hop2.R
+++ b/R/hop2.R
@@ -94 +94 @@ hop2_vec <- function(.x, .y, .starts, .stops, .f, ..., .ptype = NULL) {
-  vec_simplify(  out, .ptype)
+  vec_simplify(out, .ptype)

  • output
{
  "files": [
    {
      "chunks": [
        {
          "changes": [
            {
              "content": "  vec_simplify(  out, .ptype)",
              "lineBefore": 94,
              "type": "DeletedLine",
            },
            {
              "content": "  vec_simplify(out, .ptype)",
              "lineAfter": 94,
              "type": "AddedLine",
            },
          ],
          "context": "hop2_vec <- function(.x, .y, .starts, .stops, .f, ..., .ptype = NULL) {",
          "fromFileRange": {
            "lines": 1,
            "start": 94,
          },
          "toFileRange": {
            "lines": 1,
            "start": 94,
          },
          "type": "Chunk",
        },
      ],
      "path": "R/hop2.R",
      "type": "ChangedFile",
    },
  ],
  "type": "GitDiff",
}

@DavisVaughan
Copy link
Author

Looks like suggest-changes's tag hasn't been updated since October 2024, even though main has incorporated your update. So it will probably resolve there when they do a new release, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants