From 88783a67e96d1d0c03645f7ff803ce4cc531008e Mon Sep 17 00:00:00 2001 From: Mike Smith <10135646+mikesmithgh@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:22:04 -0400 Subject: [PATCH] feat: add col_offset option for doc view --- doc/cmp.txt | 3 ++- lua/cmp/config/default.lua | 1 + lua/cmp/types/cmp.lua | 1 + lua/cmp/view/docs_view.lua | 13 +++++++------ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/cmp.txt b/doc/cmp.txt index d2c095cd5..b5e72856a 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -629,10 +629,11 @@ window.completion.scrolloff~ Specify the window's scrolloff option. See |'scrolloff'|. - *cmp-config.window.completion.col_offset* + *cmp-config.window.{completion,documentation}.col_offset* window.completion.col_offset~ `number` Offsets the completion window relative to the cursor. + Offsets the documentation window relative to the completion window. *cmp-config.window.completion.side_padding* window.completion.side_padding~ diff --git a/lua/cmp/config/default.lua b/lua/cmp/config/default.lua index 525952033..beb7f8945 100644 --- a/lua/cmp/config/default.lua +++ b/lua/cmp/config/default.lua @@ -105,6 +105,7 @@ return function() max_width = math.floor((WIDE_HEIGHT * 2) * (vim.o.columns / (WIDE_HEIGHT * 2 * 16 / 9))), border = { '', '', '', ' ', '', '', '', ' ' }, winhighlight = 'FloatBorder:NormalFloat', + col_offset = 0, }, }, } diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index 9535e4676..46b1c897c 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -118,6 +118,7 @@ cmp.ItemField = { ---@field public max_height integer|nil ---@field public scrolloff integer|nil ---@field public scrollbar boolean|true +---@field public col_offset integer|nil ---@class cmp.ConfirmationConfig ---@field public default_behavior cmp.ConfirmBehavior diff --git a/lua/cmp/view/docs_view.lua b/lua/cmp/view/docs_view.lua index 7db651b18..1d638f1fd 100644 --- a/lua/cmp/view/docs_view.lua +++ b/lua/cmp/view/docs_view.lua @@ -58,10 +58,11 @@ docs_view.open = function(self, e, view) end -- 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), { - max_width = max_width - border_info.horiz, - max_height = documentation.max_height - border_info.vert, - }) + local width, height = vim.lsp.util._make_floating_popup_size( + vim.api.nvim_buf_get_lines(self.window:get_buffer(), 0, -1, false), { + max_width = max_width - border_info.horiz, + max_height = documentation.max_height - border_info.vert, + }) if width <= 0 or height <= 0 then return self:close() end @@ -95,7 +96,7 @@ docs_view.open = function(self, e, view) width = width, height = height, row = view.row, - col = col, + col = col + documentation.col_offset, border = documentation.border, zindex = documentation.zindex or 50, } @@ -103,7 +104,7 @@ docs_view.open = function(self, e, view) -- Correct left-col for scrollbar existence. if left then - style.col = style.col - self.window:info().scrollbar_offset + style.col = col - self.window:info().scrollbar_offset - documentation.col_offset self.window:open(style) end end