v0.6.1
vim (not Nvim) does not have vim.diff
Linux etak 5.16.2-arch1-1 #1 SMP PREEMPT Thu, 20 Jan 2022 16:18:29 +0000 x86_64 GNU/Linux
# GNOME Terminal 3.42.2 using VTE 0.66.2 +BIDI +GNUTLS +ICU +SYSTEMD
xterm-256color
pacman -S neovim
According to :h vim.diff
, the optional argument algorithm
enables switching between different supported diffing algorithms. So I've decided to experiment it with the following two files found there../file
public class File1 {
public int sub (int a, int b)
{
// TOOD: JIRA1234
if ( isNull(a, b) )
{
return null
}
log();
return a - b;
}
public int mul (int a, int b)
{
if ( isNull(a, b) )
{
return null;
}
log();
return a * b;
}
}
./other
public class File1 {
public int add (int a, int b)
{
log();
return a + b;
}
public int sub (int a, int b)
{
if (a == b)
{
return 0;
}
log();
return a - b;
// TOOD: JIRA1234
}
}
I can check that the default myers
and patience
algorithm produce different results with the following:
$ nvim --clean -d ./file ./other # admire diff
:set diffopt+=algorithm:patience " admire change
But I could not reproduce the difference with vim.diff
. For instance, with the following file added:./test_diff.vim
lua <<EOF function TestVimDiff(algo) io.input(io.open("file", "r")) local a = io.read("*a") io.close() io.input(io.open("other", "r")) local b = io.read("*a") io.close() print(vim.diff(a, b, {algorithm=algo})) end EOF
The following experiment yielded unsatisfactory results:
$ nvim --clean
:source test_diff.vim
:lua TestVimDiff("myers") " ok: the myers diff is printed.
:lua TestVimDiff("patience") " not ok: the myers diff is printed again.
Why? Have I missed anything about the way vim.diff
should be invoked? Or is this a bug?
vim.diff(a, b, {algorithm = "myers"})
and vim.diff(a, b, {algorithm = "patience"})
should produce different results on relevant files.
vim.diff(a, b, {algorithm = "myers"})
and vim.diff(a, b, {algorithm = "patience"})
produce the same results even on relevant files.
(btw I'm noticing that grep algorithm
over test/functional/lua/xdiff_spec.lua yields no match. Is this the relevant test file? If yes, maybe the above two example files can be useful as algorithm tests?)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4