sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.57k stars 101 forks source link

fix: replace deprecated table operations for neovim v0.10 #489

Closed mikesmithgh closed 1 month ago

mikesmithgh commented 2 months ago

Resolves #488.

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!

FunctionalHacker commented 2 months ago

Just tested this on my machine, works well!

serranomorante commented 2 months ago

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

mikesmithgh commented 2 months ago

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

ctretyak commented 2 months ago

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

LinoWhy commented 2 months ago

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>
serranomorante commented 2 months ago

diffview-issue.webm

mikesmithgh commented 2 months ago

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

TL;DR;


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 commented 1 month ago

Thank you!

I made a small change where I opted to use the old implementation of tbl_flatten() from Neovim because unlike the iter(...):flatten() alternative, it handles lists with holes.

Awesome! 😎