Closed xu-cheng closed 1 year ago
Same here, exactly same stack traceback.
@folke I want to report that the latest changes don't fix the problem. If you try the original repro, you will see the problem persists except with a slight different error message:
Error message in case 1:
Error detected while processing BufEnter Autocommands for "<buffer=20>":
E5108: Error executing lua ...mp/test/.repro/plugins/trouble.nvim/lua/trouble/view.lua:341: Vim:E444
: Cannot close last window
stack traceback:
[C]: in function 'nvim_win_close'
...mp/test/.repro/plugins/trouble.nvim/lua/trouble/view.lua:341: in function 'on_enter'
...mp/test/.repro/plugins/trouble.nvim/lua/trouble/init.lua:220: in function 'action'
[string ":lua"]:1: in main chunk
Error message in case 2:
Error detected while processing BufEnter Autocommands for "*":
E5108: Error executing lua vim/_editor.lua:0: BufEnter Autocommands for "*"..script nvim_exec2() cal
led at BufEnter Autocommands for "*":0: Vim(quit):E37: No write since last change
stack traceback:
[C]: in function 'nvim_exec2'
vim/_editor.lua: in function 'cmd'
...mp/test/.repro/plugins/trouble.nvim/lua/trouble/view.lua:271: in function 'on_win_enter'
...mp/test/.repro/plugins/trouble.nvim/lua/trouble/init.lua:189: in function 'action'
[string ":lua"]:1: in main chunk
The latest commit is used in the test:
Loaded (6)
~ β lazy.nvim 1.38ms ο‘ init.lua
~ β noice.nvim 0.4ms ξ« start
~ β nui.nvim 0.15ms ο noice.nvim
~ β nvim-notify 0.12ms ο noice.nvim
~ β tokyonight.nvim 0.16ms ξ« start
~ β trouble.nvim 0.14ms ξ« start
~ dir /private/tmp/test/.repro/plugins/trouble.nvim
~ url https://github.com/folke/trouble.nvim
~ branch main
~ commit 23c1327
~ readme README.md
~ help |trouble.nvim.txt|
~
Just leaving a comment to say I get the exact same thing (but only if I have Trouble set to auto-open, which would be my preference).
For people Googling; I don't know if this is a valid/logical fix. But this works for me:
diff --git a/lua/trouble/renderer.lua b/lua/trouble/renderer.lua
index 1c1ff07..1332ae1 100644
--- a/lua/trouble/renderer.lua
+++ b/lua/trouble/renderer.lua
@@ -33,7 +33,11 @@ end
---@param view TroubleView
function renderer.render(view, opts)
opts = opts or {}
- local buf = vim.api.nvim_win_get_buf(view.parent)
+ local win_id = view.parent
+ if not vim.api.nvim_win_is_valid(win_id) then
+ return
+ end
+ local buf = vim.api.nvim_win_get_buf(win_id)
providers.get(view.parent, buf, function(items, messages)
local auto_jump = vim.tbl_contains(config.options.auto_jump, opts.mode)
if opts.on_open and #items == 1 and auto_jump and not opts.auto then
diff --git a/lua/trouble/view.lua b/lua/trouble/view.lua
index 69a1b71..66c0568 100644
--- a/lua/trouble/view.lua
+++ b/lua/trouble/view.lua
@@ -338,13 +338,16 @@ function View:close()
if vim.api.nvim_win_is_valid(self.parent) then
vim.api.nvim_set_current_win(self.parent)
end
- vim.api.nvim_win_close(self.win, {})
+ if #vim.api.nvim_list_wins() > 2 then
+ vim.api.nvim_win_close(self.win, {})
+ else
+ vim.cmd('quit')
+ end
end
if vim.api.nvim_buf_is_valid(self.buf) then
vim.api.nvim_buf_delete(self.buf, {})
end
end
-
function View.create(opts)
opts = opts or {}
if opts.win then
Did you check docs and existing issues?
Neovim version (nvim -v)
NVIM v0.9.0
Operating system/version
macOS 13.4
Describe the bug
We observe the following error when quit the last buffer and trouble list is opened
There are multiple ways to reproduce this bug:
noice.nvim
is also installed. Uninstalling thenoice.nvim
fixes the issue.:q
to quit the buffer will also cause the error. This happens even iftrouble.nvim
is the only installed plugin.A similar issue is reported at #253.
Steps To Reproduce
Case 1
:Trouble
to open the trouble list.:q
to close the buffer.Case 2
noice
plugin.:Trouble
to open the trouble list.:q
to close the buffer.Press ENTER or type command to continue
. Press Enter.Expected Behavior
The vim quits without error when closing last buffer.
Repro