diffview.nvim icon indicating copy to clipboard operation
diffview.nvim copied to clipboard

fix: replace deprecated table operations for neovim v0.10

Open mikesmithgh opened this issue 2 months ago • 7 comments

Neovim nightly deprecated some table operations resulting in diffview.nvim crashes. I've moved the operations islist and flatten to the utils package so that we can apply the appropriate function depending on the Neovim version.

Please let me know what you think, thanks!

closes #488

mikesmithgh avatar Apr 24 '24 12:04 mikesmithgh

Just tested this on my machine, works well!

FunctionalHacker avatar Apr 25 '24 12:04 FunctionalHacker

Can you try with the command DiffviewFileHistory %? I believe it doesn't work after this change.

serranomorante avatar Apr 29 '24 19:04 serranomorante

DiffviewFileHistory % @serranomorante I tried DiffviewFileHistory % and it looks like it working for me. Are you seeing an error?

mikesmithgh avatar Apr 30 '24 02:04 mikesmithgh

I am using Neogit, that uses diffview.nvim. I have the same problem on markdowns (.md) files only. Other diffs are OK (.json, etc)

ctretyak avatar Apr 30 '24 05:04 ctretyak

DiffviewFileHistory % @serranomorante I tried DiffviewFileHistory % and it looks like it working for me. Are you seeing an error?

@mikesmithgh I meet the same issue, with the following error:

   Error  14:17:56 msg_show.lua_error   DiffviewFileHistory % Error executing luv callback:
...al/share/nvim/lazy/diffview.nvim/lua/diffview/logger.lua:382: attempt to call method 'gsub' (a nil value)
stack traceback:
	...al/share/nvim/lazy/diffview.nvim/lua/diffview/logger.lua:382: in function <...al/share/nvim/lazy/diffview.nvim/lua/diffview/logger.lua:380>
	vim/shared.lua: in function 'tbl_map'
	...al/share/nvim/lazy/diffview.nvim/lua/diffview/logger.lua:380: in function 'log_job'
	...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:345: in function <...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:308>
	[C]: in function 'wait'
	...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:408: in function 'sync'
	...cal/share/nvim/lazy/diffview.nvim/lua/diffview/utils.lua:349: in function 'exec_sync'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:687: in function 'is_single_file'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:696: in function 'file_history_dry_run'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:820: in function 'file_history_options'
	...local/share/nvim/lazy/diffview.nvim/lua/diffview/lib.lua:93: in function 'file_history'
	...ocal/share/nvim/lazy/diffview.nvim/lua/diffview/init.lua:139: in function 'file_history'
	....local/share/nvim/lazy/diffview.nvim/plugin/diffview.lua:34: in function <....local/share/nvim/lazy/diffview.nvim/plugin/diffview.lua:27>
   Error  14:18:28 msg_show.lua_error Error executing Lua callback: ...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:416: Synchronous job timed out!
stack traceback:
	[C]: in function 'error'
	...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:416: in function 'sync'
	...cal/share/nvim/lazy/diffview.nvim/lua/diffview/utils.lua:349: in function 'exec_sync'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:687: in function 'is_single_file'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:696: in function 'file_history_dry_run'
	...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:820: in function 'file_history_options'
	...local/share/nvim/lazy/diffview.nvim/lua/diffview/lib.lua:93: in function 'file_history'
	...ocal/share/nvim/lazy/diffview.nvim/lua/diffview/init.lua:139: in function 'file_history'
	....local/share/nvim/lazy/diffview.nvim/plugin/diffview.lua:34: in function <....local/share/nvim/lazy/diffview.nvim/plugin/diffview.lua:27>

LinoWhy avatar Apr 30 '24 06:04 LinoWhy

@serranomorante @LinoWhy @ctretyak thank you for pointing this out.

TL;DR;

  • The original error for this issue using deprecated calls no longer seems to appear in nvim nightly. You could try updating to the latest version of nvim nightly and revert back to sindrets/main.
  • I added a fix for flatten so this branch should work

My branch accidentally reverted to main that is why I did not see the error. So, that is one thing to point out. It seems like the latest nightly nvim may no longer be crashing due to the deprecated usage. So, you may not need to point to this branch unless you would like to test this functionality.

The issue appeared to be related to flatten.

vim.iter({ 1, { 2 }, { { 3 } } }):flatten():totable()
-- result: { 1, 2, { 3 } }

vs

vim.iter({ 1, { 2 }, { { 3 } } }):flatten(math.huge):totable()
-- result: { 1, 2, 3 }

flatten defaults to the depth of 1 so it was not fully flattening the list like vim.tbl_flatten. I added a fix for this by using math.huge as the depth so that is properly flattens the arguments.

mikesmithgh avatar Apr 30 '24 12:04 mikesmithgh