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

[Bug] Attempt to index nil when pressing <CR> on first line of keymap popup #469

Open Diomendius opened 4 months ago

Diomendius commented 4 months ago

Description

When <CR> is pressed with the cursor on the first line of the g? keymap overview, a Lua error is triggered by an attempt to index the nil variable context at help_panel.lua:85: https://github.com/sindrets/diffview.nvim/blob/3dc498c9777fe79156f3d32dddd483b8b3dbd95f/lua/diffview/ui/panels/help_panel.lua#L80-L96

Pressing <CR> on any other line does not trigger the error.

Expected behavior

The keypress should be ignored without error.

Actual behavior

This error appears:

E5108: Error executing lua: ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:85: attempt to index field 'context' (a nil value)
stack traceback:
        ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:85: in function 'apply_cmd'
        ...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:109: in function <...gins/diffview.nvim/lua/diffview/ui/panels/help_panel.lua:108>

Steps to reproduce

  1. nvim --clean -u mini.lua
  2. Create a dummy Git repo with :!git init, or :cd to an existing one.
  3. :DiffviewOpen
  4. g?
  5. Leaving the cursor at the top of the popup window, press <CR>

Health check

Output of :checkhealth diffview ``` 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.44.0) - WARNING Configured `hg_cmd` is not executable: 'hg' ```

Log info

No response

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742

Operating system and version

Linux 6.7.8-arch1-1 x86_64 GNU/Linux

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 ###
-- ############################################################################