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
WIP: Omit plus and minus in string diffs, except in text mode #270
Conversation
oldLine.prependLinesWith(this.clone().diffRemovedLine('-')); | ||
newLine.prependLinesWith(this.clone().diffAddedLine('+')); | ||
}, | ||
fallback: function () {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it would be nice of magicPen.alt
allowed omitting fallback: function () {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen in the unexpected-pdf ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just wouldn't do anything in that mode. It'd just assume that you wanted to fall back to NOOP :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the fallback default to a noop then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in magicpen 5.6.0, updated to it on the branch.
I'm okay with putting all the formatting in a style. But I would like the actual diffing to happen somewhere else. Think: spilling computation from presentation. I'll get back to you with more feedback, probably tonight. |
I like the main idea of loosing the |
Great, that's the main thing at this point :)
I thought that we already sort of had that in the shape of |
Okay I'll take a second look at what's going on. I still think it is possible to achieve this without using prependLinesWith. |
@sunesimonsen Thanks, ironically enough I'm beginning to think it's a bit dirty to manipulate the contents of a pen. Feel free to push to the branch if you get anywhere ofc :) |
I agree, I would probably have made it immutable today 😁 |
var type = options.type || 'WordsWithSpace'; | ||
var diffLines = []; | ||
var lastPart; | ||
stringDiff.diffLines(actual, expected).forEach(function (part) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part I don't really like, the style does the actual diff computation instead of being handed the diff. I know that the API from the outside would be convenient by letting the style taking care of it, but I just think it is misplaced. I would prefer:
var diff = utils.stringDiff(actual, expected)
pen.appendDiff(diff)
It is mainly about separation of concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would of cause mean that we would need to change the output of the utils.stringDiff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the the diff formatting codes looks a bit weird, maybe it would also help to just start over. Make a utils.stringDiff that produces a data structure that contains lines of tokens. Then hand that output to a magicpen style that would format it the way we want. Then it should also be possible to get rid of `prependLinesWith'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shit I don't know, maybe we should just allow magicpen to do these crazy things, magicpen-prism is in the same space. It just feels a bit wrong, but what ever :-) Could I take a stab at fixing up the formatting code?
I realize that I'm having a conversation with myself and convincing myself of going in new directions :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shit this is much more complicated than I remembered :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify things if we only used diffAddedLine
, diffRemovedLine
with one line and not multiple lines. Then we would be able to move the -/+
signs to these methods:
expect.addStyle('diffAddedLine', function (line) {
this.alt({ text: '+' });
this.green(line);
});
expect.addStyle('diffRemovedLine', function (line) {
this.alt({ text: '-' });
this.red(line);
});
expect.addStyle('diffUnchangedLine', function (line){
this.alt({ text: ' ' });
this.text(line)
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also what I arrived at. I attempted it once, but got stuck when I ran into the "internal" diff that the handling of replace
d chunks does.
I'm not going to block this improvement with a cleanup of the 👍 |
I'm not at all satisfied with the state this is in myself, but you're right that the cleanup might be better handled as a separate task. Let's discuss that here: #272 Merging. |
…tringDiffs WIP: Omit plus and minus in string diffs, except in text mode
Inspiration: https://github.com/so-fancy/diff-so-fancy