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

loading Gitsigns using Lazy turns into nil #796

Closed
gersonsosa opened this issue May 19, 2023 · 1 comment · Fixed by #797
Closed

loading Gitsigns using Lazy turns into nil #796

gersonsosa opened this issue May 19, 2023 · 1 comment · Fixed by #797
Labels
bug Something isn't working

Comments

@gersonsosa
Copy link
Contributor

Description

I use lazy.nvim to load Gitsigns lazily using keymaps like this

map("n", "<leader>gb", [[<cmd>Gitsigns toggle_current_line_blame<cr>]], { desc = "Toggle line blame" })

When I start neovim and I trigger above keymap I always get this stack trace, which is not an issue apart from showing up the first time I fire it

Error executing Lua callback: .../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:45: Vim:Error executing Lua callback: ...cal/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/async.lua:105: The coroutine failed with this message: ...l/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/manager.lua:538: attempt to index upvalue 'signs_normal' (a nil value)
stack traceback:
	...l/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/manager.lua: in function 'reset_signs'
	...l/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/actions.lua:1299: in function 'refresh'
	...l/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/actions.lua:201: in function 'f'
	...local/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/cli.lua:101: in function <...local/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/cli.lua:73>
stack traceback:
	[C]: in function 'error'
	...cal/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/async.lua:105: in function 'step'
	...cal/share/nvim/lazy/gitsigns.nvim/lua/gitsigns/async.lua:129: in function 'run'
	...sa/.local/share/nvim/lazy/gitsigns.nvim/lua/gitsigns.lua:101: in function <...sa/.local/share/nvim/lazy/gitsigns.nvim/lua/gitsigns.lua:100>
	[C]: in function 'cmd'
	.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:45: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>
stack traceback:
	[C]: in function 'cmd'
	.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:45: in function <.../share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

I made a simple fix by checking that signs_normal is not nil

Neovim version

NVIM v0.9.0 Build type: Release LuaJIT 2.1.0-beta3 system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.0/share/nvim"

Operating system and version

macOS ventura 13.3.1 (a)

Expected behavior

Gitsigns to load without showing any error message, in fact this works well with other functions such as prev_hunk

Actual behavior

It crashes the first time I use the keymap

Minimal config

vim.o.packpath = '/tmp/nvim/site'

local plugins = {
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
}

for name, url in pairs(plugins) do
  local install_path = '/tmp/nvim/site/pack/test/start/'..name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
}

vim.keymap.set("n", "<leader>gb", [[<cmd>Gitsigns toggle_current_line_blame<cr>]], { noremap = true, silent = true, desc = "Toggle line blame" })

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

  1. nvim --clean -u minimal.lua
  2. use keymap gb

Gitsigns debug messages

cli.run: Running action 'toggle_current_line_blame' with arguments {}
cli.run: Running action 'debug_messages' with arguments {}

@lewis6991
Copy link
Owner

Do not lazy load gitsigns

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

Successfully merging a pull request may close this issue.

2 participants