Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Diomendius opened this issue Mar 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Diomendius
Copy link

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:

function HelpPanel:apply_cmd()
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
local comp = self.components.comp:get_comp_on_line(row)
if comp then
local mapping = comp.context.mapping
local last_winid = vim.fn.win_getid(vim.fn.winnr("#"))
if mapping then
api.nvim_win_call(last_winid, function()
api.nvim_feedkeys(utils.t(mapping[2]), "m", false)
end)
self:close()
end
end
end

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 ###
-- ############################################################################
@Diomendius Diomendius added the bug Something isn't working label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant