-
Notifications
You must be signed in to change notification settings - Fork 283
fix(pick): prevent invalid buffer when opening mini.files #2157
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the PR! Although this technically fixes the #2156, I'd ask if you want to find the culprit here. As this is very strange to expect errors after explicitly checking that Writing a test case would possible make this easier. My guess is that this has to do with 'mini.files' being default explorer. |
|
Yes, without mini.files the problem does not occur. My guess is that mini.files is "in progress", creating or refreshing its buffers. I just don't understand why it doesn't happen when mini.starter is visible. I will look into it. |
|
I modified mini.files a little to prevent an explicit H.track_dir_edit = function(data)
-- Make early returns
if vim.api.nvim_get_current_buf() ~= data.buf then return end
if vim.b.minifiles_processed_dir then
-- Smartly delete directory buffer if already visited
local alt_buf = vim.fn.bufnr('#')
if alt_buf ~= data.buf and vim.fn.buflisted(alt_buf) == 1 then vim.api.nvim_win_set_buf(0, alt_buf) end
return -- COMMENTED return vim.api.nvim_buf_delete(data.buf, { force = true })
end
local path = vim.api.nvim_buf_get_name(0)
if vim.fn.isdirectory(path) ~= 1 then return end
-- Make directory buffer disappear when it is not needed
vim.bo.bufhidden = 'wipe'
vim.b.minifiles_processed_dir = true
-- Open directory without history
vim.schedule(function() MiniFiles.open(path, false) end)
endI added some print statements. The scenario: Open nvim with init.lua, press mini.files in track dir for data.buf 1
mini.files in track dir, no early return
mini.files in track dir, return, not a directory /home/user/.config/repro/init.lua
mini.pick in default chose
mini.files in track dir for data.buf 3
mini.files in track dir, no early return
mini.files still in track dir, marking vim.b.minifiles_processed_dir
mini.pick advance before stop -- NOTE: mini.files does not yet appear....
mini.pick set curwin
mini.files in track dir for data.buf 3
mini.files in track dir, no early return
mini.files in track dir, has vim.b.minifiles_processed_dir, alt buf is 1
---
--- Without modification, crashes here...
---
--- Happy path:
mini.files in track dir for data.buf 4
mini.files in track dir, no early return
mini.files in track dir, return, not a directory minifiles://4//home/user/.config/reproThe So, the fix could also be in mini.files, by not deleting the buffer and just return instead. Perhaps the explicit delete is not necessary anyways, because of I think its best to fix in mini.files, to not crash on an external |
The buffer deleting is for the following use case:
It is probably not a big deal and a rare use case, but at least trying to account for that is reasonable. And, of course, needs tests both here and 'mini.extra'. |
ff224a3 to
dca9884
Compare
|
I unfortunately cannot reproduce the buffer deleting scenario you described. Testing with Still todo: A test in mini.extra |
|
Fixes: #2156
I think it's a timing problem, as the error does not occur when the starter is visible.
It's very strange though: The window is valid. I tested that even the buffer is valid. Still,
nvim_set_current_wincrashes.