-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: add golang.org/x/text/diff package #23113
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
Comments
We could vendor in The |
@dsnet I tried. but it seems to me that it doesn't help multi-line cases.
output:
|
Oh, I understand.
output:
|
It seems to make more sense to encourage experimentation outside and then consider whether to bring a particular outside one in. There are also tests that run diff, and it would be nice to unify them. Note that cmp is a lot bigger than just this one diff issue. |
Putting on hold for a more specific proposal--should we use cmp, or introduce something new? |
I have made some progress on a text diff implementation that I think would be appropriate for the standard library. |
Isn't a diffing algorithm primarily about determining how to conform one sequence of symbols into another sequence of symbols regardless of whether it is text or not? It seems to me that we should expose a higher level diffing algorithm for any sequence of symbols and make the "text diff implementation" just use that under the hood. The API of func(nx, ny int, f func(i, j) bool) []Operation where The diffing algorithm in
where I believe this issue, #41980, and #45200 should all ideally share the same diffing algorithm. \cc @josharian |
It's not necessarily true that arbitrary sequences and text files should use the same algorithms. They turn out to be somewhat different. How does cmp/internal/diff get used by diff itself? |
Retitling to make clear that we should add this in a way that everyone can import it. Still on hold. |
Is there a description of the algorithm that you're thinking of? The Eugene Myers algorithm that I believe @josharian implemented (and which inspired
The main way is to provide diffing for two Go slices, where the symbols being compared are two arbitrary Go values. It is also used by
|
And taking this even farther, for natural language text, it is better for each symbol to be a Unicode grapheme cluster. |
Many test code are something like:
However, these kind of code are pretty useless when we expected multi-line values.
For example,
So, I propose to support diff algorithm for making error messages human-readable.
The simplest implementation is executing the
diff
command. It doesn't work on windows.But we can use fallback, so it can be a good starting point.
I'm not sure that supporting the "diff" package officially is worth doing.
But "internal" packages seem harmless.
The text was updated successfully, but these errors were encountered: