bug?
0rtz opened this issue · 8 comments
Hello, thank you for the plugin. However, there is one thing that is weird to me. After i close the preview window with already existing before hidden buffer, the buffer is unloaded. As i understand noone reported this before, which is wierd, is it possible to fix this? Im on the latest neovim master.
Hey, thanks for the submission.
I'm a little unsure of what you mean though. Could you maybe elaborate?
@rmagatti Okay. Here is a gif of what i mean:
You see after i close goto-preview window with a definition of the TEST
macro, previously loaded buffer common.h
is unloaded.
Files i use to reproduce:
init.vim
with clangd language server, vim-plug and lsp-config plugin
call plug#begin()
Plug 'neovim/nvim-lspconfig'
Plug 'rmagatti/goto-preview'
call plug#end()
lua << EOF
require'lspconfig'.clangd.setup{}
require('goto-preview').setup{}
EOF
nnoremap gf <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap gpd <cmd>lua require('goto-preview').goto_preview_definition()<CR>
nnoremap gP <cmd>lua require('goto-preview').close_all_win()<CR>
common.h
#define TEST 1
test.c
#include "common.h"
int main (int argc, char *argv[])
{
int a = 1 + TEST;
return 0;
}
neovim commit i pulled yesterday: b51b0aecc969040641da29dbd7cf28e419972f15
Assuming you're closing the preview window through the goto-preview mapping. This is what the documentation about the function I use to close it says.
-- Closes the window (like |:close| with a |window-ID|).
--- @param window window #Window handle, or 0 for current window
--- @param force boolean #Behave like `:close!` The last window of a
--- buffer with unwritten changes can be closed. The
--- buffer will become hidden, even if 'hidden' is
--- not set.
function vim.api.nvim_win_close(window, force) end
And this is how I'm calling it.
vim.api.nvim_win_close(win_handle, true)
I'm adding an option to not force close in a PR as I think this is likely the cause of what you're seeing, i.e I think your buffer is becoming hidden.
@0xrz would you mind testing out the changes by installing with the branch of the PR linked here and setting force_close = false
in the setup?
@rmagatti i pulled add-force-close-option
, tried to set force_close = false
but it doesn't fix anything for me, <cmd>lua require('goto-preview').close_all_win()<CR>
still unloads buffer after preview window is closed 🤷♂️
Im not really sure what this force
parameter of nvim_win_close
do, but i found out that https://github.com/rmagatti/goto-preview/blob/main/lua/goto-preview/lib.lua#L130 bufhidden
option can be changed from wipe
to hide
, that way existing buffer won't be unloaded, imo it seems to be the correct behaviour.
Oh interesting. Good find. I'll add an option for that to too.