sindrets / diffview.nvim

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

[Bug] DiffviewFileHistory always throws error #394

Closed protiumx closed 1 year ago

protiumx commented 1 year ago

Description

I haven't been able to use this for a while, I always get an error when calling DiffviewFileHistory

Expected behavior

It should show the file git history

Actual behavior

I always get the following error

  Error  Error executing vim.schedule lua callback: ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: The coroutine failed with this message: 
    context: cur_thread=main co_thread=<thread 0x01016d1ab0> co_func=...diffview/scene/views/file_history/file_history_panel.lua:183
...ew.nvim/lua/diffview/scene/views/file_history/render.lua:178: attempt to perform arithmetic on field 'width' (a nil value)
stack traceback:
    ...ew.nvim/lua/diffview/scene/views/file_history/render.lua: in function 'prepare_panel_cache'
    ...ew.nvim/lua/diffview/scene/views/file_history/render.lua:195: in function 'file_history_panel'
    ...diffview/scene/views/file_history/file_history_panel.lua:556: in function 'render'
    .../pack/packer/opt/diffview.nvim/lua/diffview/ui/panel.lua:405: in function 'sync'
    ...diffview/scene/views/file_history/file_history_panel.lua:298: in function 'func'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:366: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:351>
stack traceback:
    [C]: in function 'error'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: in function 'raise'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:207: in function 'step'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:405: in function 'update_entries'
    .../diffview/scene/views/file_history/file_history_view.lua:53: in function <.../diffview/scene/views/file_history/file_history_view.lua:49>
   Error  Error executing vim.schedule lua callback: ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: The coroutine failed with this message: 
    context: cur_thread=main co_thread=<thread 0x0100da62c8> co_func=...diffview/scene/views/file_history/file_history_panel.lua:195
.../pack/packer/opt/diffview.nvim/lua/diffview/renderer.lua:167: attempt to get length of local 'text' (a nil value)
stack traceback:
    .../pack/packer/opt/diffview.nvim/lua/diffview/renderer.lua:167: in function 'add_text'
    ...ew.nvim/lua/diffview/scene/views/file_history/render.lua:204: in function 'file_history_panel'
    ...diffview/scene/views/file_history/file_history_panel.lua:556: in function 'render'
    .../pack/packer/opt/diffview.nvim/lua/diffview/ui/panel.lua:405: in function 'sync'
    ...diffview/scene/views/file_history/file_history_panel.lua:257: in function <...diffview/scene/views/file_history/file_history_panel.lua:195>
    [C]: in function 'xpcall'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:354: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:351>
stack traceback:
    [C]: in function 'error'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:362: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:351>
stack traceback:
    [C]: in function 'error'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: in function 'raise'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:207: in function 'step'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:239: in function 'notify_all'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:214: in function 'step'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:392: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:384>
   Error  Error executing vim.schedule lua callback: ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: The coroutine failed with this message: 
    context: cur_thread=main co_thread=<thread 0x01016032f0> co_func=...diffview/scene/views/file_history/file_history_panel.lua:195
.../pack/packer/opt/diffview.nvim/lua/diffview/renderer.lua:167: attempt to get length of local 'text' (a nil value)
stack traceback:
    .../pack/packer/opt/diffview.nvim/lua/diffview/renderer.lua: in function 'add_text'
    ...ew.nvim/lua/diffview/scene/views/file_history/render.lua:204: in function 'file_history_panel'
    ...diffview/scene/views/file_history/file_history_panel.lua:556: in function 'render'
    .../pack/packer/opt/diffview.nvim/lua/diffview/ui/panel.lua:405: in function 'sync'
    ...diffview/scene/views/file_history/file_history_panel.lua:257: in function 'func'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:366: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:351>
stack traceback:
    [C]: in function 'error'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:179: in function 'raise'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:207: in function 'step'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:239: in function 'notify_all'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:214: in function 'step'
    ...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:392: in function <...ite/pack/packer/opt/diffview.nvim/lua/diffview/async.lua:384>

Steps to reproduce

Call command DiffviewFileHistory or DiffviewFileHistory %

Health check

Output of :checkhealth diffview ``` diffview: require("diffview.health").check() Checking plugin dependencies ~ - OK nvim-web-devicons installed. Checking VCS tools ~ - The plugin requires at least one of the supported VCS tools to be valid. - OK Git found. - OK Git is up-to-date. (2.41.0) - WARNING Configured `hg_cmd` is not executable: 'hg' ```

Log info

Relevant info from :DiffviewLog ``` [INFO 2023-07-09 20:52:03.817 +0200] .../site/pack/packer/opt/diffview.nvim/lua/diffview/lib.lua:74: [command call] :DiffviewFileHistory % [INFO 2023-07-09 20:52:03.906 +0200] ...opt/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:914: [FileHistory] Updating with options: { flags = { "--follow", "-n256", "--diff-merges=first-parent" }, path_args = { "stow/nvim/.config/nvim/lua/config/settings.lua" } } ```

Neovim version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Darwin 22.5.0 arm64

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
vim.fn.mkdir(root, "p")

-- set stdpaths to use root
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "sindrets/diffview.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
      require("diffview").setup({
        -- ##############################################################################
        -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
        -- ##############################################################################
      })
    end,
  },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
require("lazy").sync({ show = false, wait = true })

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################
xuyangy commented 1 year ago

For me, error occurs only when DiffviewFileHistory is followed by a path.

renxzen commented 1 year ago

Can confirm this only happens when DiffviewFileHistory is called with path. DiffviewFileHistory % to view file history of only current file on buffer throws this error.

sindrets commented 1 year ago

This happens when you configure the file history panel win_config to be a column panel (position = "left"|"right") without setting a width. So you likely have configured the panel wrong, but the plugin shouldn't throw an error in this case regardless, so I'll fix that.

To clarify, you likely have something like this in your config:

require("diffview").setup({
  file_history_panel = {
    win_config = {
      position = "left",
      height = 70,
      -- Note `height` is being set here, but it's not used for column panels.
      -- This is described in the docs.
    },
  },
})

What you want is probably:

require("diffview").setup({
  file_history_panel = {
    win_config = {
      position = "left",
      width = 70,
    },
  },
})
protiumx commented 1 year ago

hi @sindrets ! that was the issue, I totally missed out that config when setting the position to left. Maybe a default value could help us avoid others on this problem? I'm closing this, thanks! 🚀

xuyangy commented 12 months ago

@sindrets Calling DiffviewFileHistory with a path e.g., DiffviewFileHistory % still triggers the same error. I use following config:

file_history_panel = {
    log_options = {   -- See ':h diffview-config-log_options'
      git = {
        single_file = {
          diff_merges = "combined",
        },
        multi_file = {
          diff_merges = "first-parent",
        },
      },
      hg = {
        single_file = {},
        multi_file = {},
      },
    },
    win_config = {    -- See ':h diffview-config-win_config'
      position = "bottom",
      height = 16,
      win_opts = {}
    },
  },
sindrets commented 12 months ago

@xuyangy it's definitely not the same error. File a new report using the bug report template.

xuyangy commented 12 months ago

@sindrets indeed not the same error, reported here.