Skip to content
New issue

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

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

Already on GitHub? # to your account

bug: Debug vim closes unexpectedly when using shortcuts #324

Closed
3 tasks done
elkesrio opened this issue Mar 6, 2024 · 11 comments
Closed
3 tasks done

bug: Debug vim closes unexpectedly when using shortcuts #324

elkesrio opened this issue Mar 6, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@elkesrio
Copy link

elkesrio commented Mar 6, 2024

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

0.9.4

Operating system/version

MacOS 14.2.1

Describe the bug

When I open oil with the command :Oil everything works perfectly
But, when it's open via a mapping (- or <C-f>), as soon as I modify an oil window (or float) vim closes.
Here is my config :

require("oil").setup({
  use_default_keymaps = true,
  prompt_save_on_select_new_entry = false,
})

local function map(m, k, v)
  vim.keymap.set(m, k, v, { noremap = true })
end

map("n", "-", ":Oil<CR>")
map("n", "<C-f>", ":lua require('oil').toggle_float()<CR>")
map("n", "q", ":lua require('oil').close()<CR>")

I see no logs related to this in ~/.cache/nvim/log
How can I debug such behaviors ?

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

The bug seems related to my config. It's not reproducible with a minimal init.lua

Expected Behavior

Write logs somewhere to be able to debug weird behaviors

Directory structure

Same behavior for different projects

Repro

The bug seems related to my config. It's not reproducible with a minimal `init.lua`

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@elkesrio elkesrio added the bug Something isn't working label Mar 6, 2024
@elkesrio
Copy link
Author

elkesrio commented Mar 6, 2024

Please note that everything works perfectly when the first time I open Oil is not via a mapping:

This scenario works without bugs:

  • open neovim
  • run :Oil
  • close oil window
  • <C-f> (or -)
  • close oil window

@stevearc
Copy link
Owner

stevearc commented Mar 6, 2024

Congratulations, you have found a crash in Neovim! I'll list out some options, in order of least to most effort.

  1. You could try out the nightly version of Neovim and see if that fixes it. It's possible that the root cause of this crash has already been fixed.
  2. You could build Neovim from source with debug symbols, and run it in gdb.
make CMAKE_BUILD_TYPE=Debug
gdb ./build/bin/nvim
run

This should give you some additional information when you hit the crash.
3. Trim your config down to try to figure out exactly what is causing the bad interaction. This will help other people reproduce the issue and should narrow the debugging search dramatically. See :help bisect for tips.

@stevearc stevearc added the question Further information is requested label Mar 6, 2024
@elkesrio
Copy link
Author

elkesrio commented Mar 7, 2024

Thanks @stevearc TIL how to run Neovim in debug mode.

The nightly version of Neovim doesn't fix the problem unfortunately.

I've built Neovim from source with debug symbols and came up with this:

The problem comes from different Autocommands I have in my Neovim config :

The first one is related with ale
image
it tries to get the LSP config of oil window and it fails

The second one is

Error detected while processing TextYankPost Autocommands for "*":
Error executing lua callback: vim/_init_packages.lua:0: module 'vim.highlight' n
ot found:
        no field package.preload['vim.highlight']
        no file './vim/highlight.lua'
        no file '/Users/othmane/neovim/.deps/usr/share/luajit-2.1/vim/highlight.
lua'
        no file '/usr/local/share/lua/5.1/vim/highlight.lua'
        no file '/usr/local/share/lua/5.1/vim/highlight/init.lua'
        no file '/Users/othmane/neovim/.deps/usr/share/lua/5.1/vim/highlight.lua
'
        no file '/Users/othmane/neovim/.deps/usr/share/lua/5.1/vim/highlight/ini
t.lua'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/shar
e/lua/5.1/vim/highlight.lua'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/shar
e/lua/5.1/vim/highlight/init.lua'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/lib/
luarocks/rocks-5.1/vim/highlight.lua'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/lib/
luarocks/rocks-5.1/vim/highlight/init.lua'
        no file './vim/highlight.so'
        no file '/usr/local/lib/lua/5.1/vim/highlight.so'
        no file '/Users/othmane/neovim/.deps/usr/lib/lua/5.1/vim/highlight.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/lib/
lua/5.1/vim/highlight.so'
        no file './vim.so'
        no file '/usr/local/lib/lua/5.1/vim.so'
        no file '/Users/othmane/neovim/.deps/usr/lib/lua/5.1/vim.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file '/Users/othmane/.cache/nvim/packer_hererocks/2.1.1703358377/lib/
lua/5.1/vim.so'
stack traceback:
        [C]: in function 'require'
        vim/_init_packages.lua: in function '__index'
        /Users/othmane/.config/nvim/lua/highlights.lua:26: in function </Users/o
thmane/.config/nvim/lua/highlights.lua:25>

The code causing this is :

vim.api.nvim_create_autocmd("TextYankPost", {
	group = num_au,
	callback = function()
		vim.highlight.on_yank({ higroup = "Visual", timeout = 120 }) # <= the failing line 26
	end,
})

For a reason that I ignore, it doesn't find the module vim.highlight in the context of an oil window 🤔

Removing ale and the TextYankPost code resolves the problem in the debug mode, but it stays in non debug mode 🤯

Do you have an explanation of this behaviour ?

@github-actions github-actions bot removed the question Further information is requested label Mar 7, 2024
@stevearc
Copy link
Owner

stevearc commented Mar 8, 2024

Hmmm...how are you running the nvim that you built? Are you using GDB or running it directly? Also, the issues that you're seeing with ALE and vim.highlight might be due to mismatched runtime files. You might need to tell it to use the nightly runtime files like so:

VIMRUNTIME=/path/to/neovim/runtime /path/to/neovim/build/bin/nvim

I think that the errors that you posted are unrelated to the original crash. We really need to find either a minimal configuration that repros the issue, or a stack trace from GDB. If running neovim that was built in debug mode doesn't produce the error, then it's possible that some difference in the compilation between debug and release modes changes the root cause. You can also try building in release mode with debug symbols to see if that will cause it to repro:

make CMAKE_BUILD_TYPE=RelWithDebInfo

@stevearc stevearc added the question Further information is requested label Mar 8, 2024
@elkesrio
Copy link
Author

elkesrio commented Mar 9, 2024

You're right, the issues that I'm seeing with ALE and vim.highlight are related to mismatched runtime files. I fixed those by setting VIMRUNTIME.

I'm using LLDB (GDB is not supported on apple silicon) this way:

VIMRUNTIME=/opt/homebrew/Cellar/neovim/0.9.5/share/nvim/runtime lldb ./build/bin/nvim

The following tests are all run in LLDB with different vim versions and build types

Using Vim 0.9.5

Debug mode

Everything works perfectly

RelWithDebugInfo mode

The exact same behavior described in the issue 🎉 :
It works perfectly when I open oil without mapping and closes unexpectedly when it's run via a mapping.
The problem is that I still have no logs (or they are in a log file that I can't find)
image

Using the nightly version

Debug mode

I now have this error. But it happens even when I run oil directly without mapping

image

RelWithDebugInfo mode

Same as Debug mode

@github-actions github-actions bot removed the question Further information is requested label Mar 9, 2024
@stevearc
Copy link
Owner

After you get the crash and you are back at the lldb prompt, try running bt or bt all to get the backtrace (source).

The error in nightly is again because the VIMRUNTIME is not set to the nightly runtime dir

@stevearc stevearc added the question Further information is requested label Mar 11, 2024
@elkesrio
Copy link
Author

It doesn't work, the process has already been stopped

image

@github-actions github-actions bot removed the question Further information is requested label Mar 12, 2024
@stevearc
Copy link
Owner

Does it seem likely to you that this could be the issue? #221 (comment)

@elkesrio
Copy link
Author

No. I just did the following and had the bug still:

  • Open neovim
  • Open oil floating window with <C-f> mapping
  • create a file
  • Tap <ESC>
  • Vim closes

@stevearc
Copy link
Owner

When you say "create a file", what steps are you actually taking? Is it:

  • Enter insert mode
  • Create a new line and add the text "foo"
  • <Esc>
  • :w
  • Press o to confirm

Or is it some subset or different set of actions?
The reason I thought it might be the linked issue is that vim is exiting with status code 0, which should only happen if we issue a :q somewhere. Some ideas you can try:

  • ensure you've updated oil because I did fix the linked issue and maybe it's related
  • As part of your repro, run :tabnew after opening Neovim. If the issue is a stray call to :quit then it will only close the current tab instead of closing Neovim.
  • monkey patch vim.cmd.quit and vim.cmd.quitall to see if they're getting called from somewhere
  • right before you tap <ESC> and close vim, I assume you're in insert mode? You could do <C-o>:imap <Esc> to see if there's any mapping that will run or <C-o>:au InsertLeave to see if there is any autocmd that will run.

@stevearc stevearc added the question Further information is requested label Mar 14, 2024
@elkesrio
Copy link
Author

I updated oil and everything worked 🔥
Thanks a lot @stevearc

@github-actions github-actions bot removed the question Further information is requested label Mar 14, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants