Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add col_offset option for doc view #1528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/cmp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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~
Expand Down
1 change: 1 addition & 0 deletions lua/cmp/config/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions lua/cmp/types/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lua/cmp/view/docs_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,15 +96,15 @@ 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,
}
self.window:open(style)

-- 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
Expand Down