Allow window.documentation.max_{width, height} to be set to 0 (#1394)

To allow for using all available screen space, as we can omit a
max_height/max_width when creating a documentation popup). I've found this
to be useful with neovim-gtk's native GUI completion menus.
This commit is contained in:
Lyude 2024-03-22 03:38:43 -04:00 committed by GitHub
parent 43b460a2bd
commit b356f2c80c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

View file

@ -728,12 +728,14 @@ window.completion.scrollbar~
*cmp-config.window.documentation.max_width*
window.documentation.max_width~
`number`
The documentation window's max width.
The documentation window's max width, can be set to 0 to use all available
space.
*cmp-config.window.documentation.max_height*
window.documentation.max_height~
`number`
The documentation window's max height.
The documentation window's max height, can be set to 0 to use all available
space.
*cmp-config.experimental.ghost_text*
experimental.ghost_text~

View file

@ -38,7 +38,10 @@ docs_view.open = function(self, e, view)
local border_info = window.get_border_info({ style = documentation })
local right_space = vim.o.columns - (view.col + view.width) - 1
local left_space = view.col - 1
local max_width = math.min(documentation.max_width, math.max(left_space, right_space))
local max_width = math.max(left_space, right_space)
if documentation.max_width > 0 then
max_width = math.min(documentation.max_width, max_width)
end
-- Update buffer content if needed.
if not self.entry or e.id ~= self.entry.id then
@ -52,20 +55,26 @@ docs_view.open = function(self, e, view)
vim.cmd([[syntax clear]])
vim.api.nvim_buf_set_lines(self.window:get_buffer(), 0, -1, false, {})
end)
vim.lsp.util.stylize_markdown(self.window:get_buffer(), documents, {
local opts = {
max_width = max_width - border_info.horiz,
max_height = documentation.max_height,
})
}
if documentation.max_height > 0 then
opts.max_height = documentation.max_height
end
vim.lsp.util.stylize_markdown(self.window:get_buffer(), documents, opts)
end
-- Set buffer as not modified, so it can be removed without errors
vim.api.nvim_buf_set_option(self.window:get_buffer(), 'modified', false)
-- Calculate window size.
local width, height = vim.lsp.util._make_floating_popup_size(vim.api.nvim_buf_get_lines(self.window:get_buffer(), 0, -1, false), {
local opts = {
max_width = max_width - border_info.horiz,
max_height = documentation.max_height - border_info.vert,
})
}
if documentation.max_height > 0 then
opts.max_height = documentation.max_height - border_info.vert
end
local width, height = vim.lsp.util._make_floating_popup_size(vim.api.nvim_buf_get_lines(self.window:get_buffer(), 0, -1, false), opts)
if width <= 0 or height <= 0 then
return self:close()
end