yeonjuan / parse-git-diff

parse git diff
MIT License
28 stars 3 forks source link

feat: add `context` to Chunk #14

Closed TheCommieAxolotl closed 1 year ago

TheCommieAxolotl commented 1 year ago

Adds a Chunk.context entry with the context of the Chunk

e.g.

diff --git a/rename.js b/rename.js
index aa39060..0e05564 100644
--- a/rename.js
+++ b/rename.js
@@ -4 +4,5 @@ function hello() {
   // hello world
+  console.log("hello world");

will result in a chunk with

{
    // ...
    context: "function hello() {",
    // ...
}
TheCommieAxolotl commented 1 year ago

@yeonjuan Just in case you missed it.

yeonjuan commented 1 year ago

Hi @TheCommieAxolotl , Thanks for the PR. I have a question. Why we add the context to the result? Could you explain more?

TheCommieAxolotl commented 1 year ago

Thanks @yeonjuan, I'm using your package under the hood in an upcoming project of mine and I would like to display the context of diff chunks to the user to help them better understand where their code is. I was thinking about just writing my own parser to run as well as yours but I saw you were using a regex and it would be easy for me to contribute.

yeonjuan commented 1 year ago

@TheCommieAxolotl I got it. I think it's a bug. The result should contain "function hello() {" as a UnchangedLine (rather than add context). I'll work on it!

TheCommieAxolotl commented 1 year ago

@yeonjuan So you would just add an UnchangedLine to the beginning of the chunk?

yeonjuan commented 1 year ago

@TheCommieAxolotl Yes Right, the result should contain all lines!

TheCommieAxolotl commented 1 year ago

@yeonjuan I think you may be misunderstanding. The "context" isn't always part of the chunk, sometimes it can refer to a line several hundreds of lines above the current chunk and is just shown for orientation.

yeonjuan commented 1 year ago

@TheCommieAxolotl

@yeonjuan I think you may be misunderstanding. The "context" isn't always part of the chunk, sometimes it can refer to a line several hundreds of lines above the current chunk and is just shown for orientation.

Yes right, But I don't think we need new node type. Isn't this just the unchanged line output from the git-diff command?

TheCommieAxolotl commented 1 year ago

@yeonjuan No, it is a separate part of the diff output. If you don't want to add a new entry to the chunk I understand but I think adding it as an UnchangedLine is incorrect behavior.

yeonjuan commented 1 year ago

-

yeonjuan commented 1 year ago

@TheCommieAxolotl You're right. I was misunderstanding, the string following the "@@" is not just representing the Unchaned Line. I'll do some more testing and review, thanks.