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
Better diff algorithm #15
Comments
Porting EDIT: The above is a joke. |
Another alternative that looks like it might do what you want is |
We're already using |
Other sources of inspiration: https://crates.io/crates/wu-diff |
I believe this should be done in two steps. For the input: diffing the input like sed would do for: s/input// So basically: ruplacer foo_bar lol_rofl Input: I love foo_bar eggs. IN: diff input / Intermediary |
Interesting. This way instead of showing the reality of the diff, we show back to the user what he meant. Example:
The second option may give a more verbose output, but it will help if a complex regex with captured groups is used. |
Sadly going through an intermediary string still does not work: impl BetterReplacement {
fn print_self(&self) {
let changeset = Changeset::new(&self.start, &self.middle, "");
// ...
let changeset = Changeset::new(&self.middle, &self.end, "");
// ...
}
}
let start = "I love foo and eggs";
let middle = "I love and eggs";
let end = "I love bar and eggs";
let replacement = BetterReplacement{ start, middle, end};
replacement.print_self() Gives this result (where _ represent what gets colored);
I think the only way to move forward is to compute the changed indexed "by hand" when ruplacing |
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
Instead of computing the new line and then trying to guess the diff, we compute the positions where the string needs to change and use that to both print the diffs and compute the new string Fix #15
OK, so I managed to write a POC in Python. It's in the python-poc branch if you want to check it out All that's left to do is to rewrite in in Rust :) |
Phew - it's done. All that's left is tidying up the history of the |
This thread mentions |
Right now if you replace
foo_bar
byspam_eggs
, the underscore won't get colored when printing the diff.I've tried and fail to fix the algorithm, so maybe we should use an other diff library instead.
Maybe this one: https://docs.rs/diff/0.1.11/diff/index.html ?
Or we port diff-so-fancy from Perl to Rust :P
The text was updated successfully, but these errors were encountered: