From b356f2c80cb6c5bae2a65d7f9c82dd5c3fdd6038 Mon Sep 17 00:00:00 2001 From: Lyude Date: Fri, 22 Mar 2024 03:38:43 -0400 Subject: [PATCH] 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. --- doc/cmp.txt | 6 ++++-- lua/cmp/view/docs_view.lua | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/doc/cmp.txt b/doc/cmp.txt index 6d809a0..110c9f0 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -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~ diff --git a/lua/cmp/view/docs_view.lua b/lua/cmp/view/docs_view.lua index 3947e33..4c22b29 100644 --- a/lua/cmp/view/docs_view.lua +++ b/lua/cmp/view/docs_view.lua @@ -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