A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/issues/17207 below:

Algorithm option of `vim.diff` does not work. · Issue #17207 · neovim/neovim · GitHub

Neovim version (nvim -v)

v0.6.1

Vim (not Nvim) behaves the same?

vim (not Nvim) does not have vim.diff

Operating system/version

Linux etak 5.16.2-arch1-1 #1 SMP PREEMPT Thu, 20 Jan 2022 16:18:29 +0000 x86_64 GNU/Linux

Terminal name/version

# GNOME Terminal 3.42.2 using VTE 0.66.2 +BIDI +GNUTLS +ICU +SYSTEMD

$TERM environment variable

xterm-256color

Installation

pacman -S neovim

How to reproduce the issue

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?

Expected behavior

vim.diff(a, b, {algorithm = "myers"}) and vim.diff(a, b, {algorithm = "patience"}) should produce different results on relevant files.

Actual behavior

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