mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 12:45:17 -07:00
Merge 4bda502014
into 02bc40c194
This commit is contained in:
commit
6806b87ecc
@ -1618,18 +1618,16 @@ function M.open_floating_preview(contents, syntax, opts)
|
|||||||
api.nvim_buf_set_var(bufnr, 'lsp_floating_preview', floating_winnr)
|
api.nvim_buf_set_var(bufnr, 'lsp_floating_preview', floating_winnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
local augroup_name = ('closing_floating_preview_%d'):format(floating_winnr)
|
local augroup_name = 'nvim_closing_floating_preview'
|
||||||
local ok =
|
if vim.fn.exists(('#%s'):format(augroup_name)) == 0 then
|
||||||
pcall(api.nvim_get_autocmds, { group = augroup_name, pattern = tostring(floating_winnr) })
|
|
||||||
if not ok then
|
|
||||||
api.nvim_create_autocmd('WinClosed', {
|
api.nvim_create_autocmd('WinClosed', {
|
||||||
group = api.nvim_create_augroup(augroup_name, {}),
|
group = api.nvim_create_augroup(augroup_name, { clear = true }),
|
||||||
pattern = tostring(floating_winnr),
|
callback = function(args)
|
||||||
callback = function()
|
if
|
||||||
if api.nvim_buf_is_valid(bufnr) then
|
tonumber(args.match) == vim.b[bufnr].lsp_floating_preview and api.nvim_buf_is_valid(bufnr)
|
||||||
|
then
|
||||||
vim.b[bufnr].lsp_floating_preview = nil
|
vim.b[bufnr].lsp_floating_preview = nil
|
||||||
end
|
end
|
||||||
api.nvim_del_augroup_by_name(augroup_name)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -267,38 +267,38 @@ describe('vim.lsp.util', function()
|
|||||||
|
|
||||||
eq(56, opts.height)
|
eq(56, opts.height)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('vim.lsp.util.open_floating_preview', function()
|
describe('open_floating_preview', function()
|
||||||
local var_name = 'lsp_floating_preview'
|
before_each(function()
|
||||||
local curbuf = api.nvim_get_current_buf()
|
n.clear()
|
||||||
|
Screen.new(10, 10)
|
||||||
|
feed('9i<CR><Esc>G4k')
|
||||||
|
end)
|
||||||
|
|
||||||
it('clean bufvar after fclose', function()
|
local var_name = 'lsp_floating_preview'
|
||||||
exec_lua(function()
|
local curbuf = api.nvim_get_current_buf()
|
||||||
vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
|
|
||||||
end)
|
|
||||||
eq(true, api.nvim_win_is_valid(api.nvim_buf_get_var(curbuf, var_name)))
|
|
||||||
command('fclose')
|
|
||||||
eq(
|
|
||||||
'Key not found: lsp_floating_preview',
|
|
||||||
pcall_err(api.nvim_buf_get_var, curbuf, var_name)
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('clean bufvar after CursorMoved', function()
|
it('clean bufvar after fclose', function()
|
||||||
local result = exec_lua(function()
|
exec_lua(function()
|
||||||
vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
|
vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
|
||||||
local winnr = vim.b[vim.api.nvim_get_current_buf()].lsp_floating_preview
|
|
||||||
local result = vim.api.nvim_win_is_valid(winnr)
|
|
||||||
vim.api.nvim_feedkeys(vim.keycode('G'), 'txn', false)
|
|
||||||
return result
|
|
||||||
end)
|
|
||||||
eq(true, result)
|
|
||||||
eq(
|
|
||||||
'Key not found: lsp_floating_preview',
|
|
||||||
pcall_err(api.nvim_buf_get_var, curbuf, var_name)
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
eq(true, api.nvim_win_is_valid(api.nvim_buf_get_var(curbuf, var_name)))
|
||||||
|
command('fclose')
|
||||||
|
eq('Key not found: lsp_floating_preview', pcall_err(api.nvim_buf_get_var, curbuf, var_name))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('clean bufvar after CursorMoved', function()
|
||||||
|
local result = exec_lua(function()
|
||||||
|
vim.lsp.util.open_floating_preview({ 'test' }, '', { height = 5, width = 2 })
|
||||||
|
local winnr = vim.b[vim.api.nvim_get_current_buf()].lsp_floating_preview
|
||||||
|
local result = vim.api.nvim_win_is_valid(winnr)
|
||||||
|
vim.api.nvim_feedkeys(vim.keycode('G'), 'txn', false)
|
||||||
|
return result
|
||||||
|
end)
|
||||||
|
eq(true, result)
|
||||||
|
eq('Key not found: lsp_floating_preview', pcall_err(api.nvim_buf_get_var, curbuf, var_name))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user