Merge pull request #14726 from folke/lsp_single_popup_per_buffer

fix(lsp): max 1 floating preview per buffer. Fixes #11508
This commit is contained in:
Michael Lingelbach 2021-06-06 03:22:10 -07:00 committed by GitHub
commit 4ce61742cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1375,6 +1375,13 @@ function M.open_floating_preview(contents, syntax, opts)
end
end
-- check if another floating preview already exists for this buffer
-- and close it if needed
local existing_float = npcall(api.nvim_buf_get_var, bufnr, "lsp_floating_preview")
if existing_float and api.nvim_win_is_valid(existing_float) then
api.nvim_win_close(existing_float, true)
end
local floating_bufnr = api.nvim_create_buf(false, true)
local do_stylize = syntax == "markdown" and opts.stylize_markdown
@ -1420,6 +1427,7 @@ function M.open_floating_preview(contents, syntax, opts)
if opts.focus_id then
api.nvim_win_set_var(floating_winnr, opts.focus_id, bufnr)
end
api.nvim_buf_set_var(bufnr, "lsp_floating_preview", floating_winnr)
return floating_bufnr, floating_winnr
end