Add Completion Window Options (#901)

* Add window.completion.side_padding and window.completion.col_offset

* add col_offset and side_padding options to config/window
This commit is contained in:
Cameron
2022-06-15 04:49:16 +02:00
committed by GitHub
parent 0e65333c7f
commit df6734aa01
4 changed files with 18 additions and 6 deletions

View File

@@ -560,6 +560,16 @@ window.{completion,documentation}.zindex~
The completion window's zindex. The completion window's zindex.
See |nvim_open_win|. See |nvim_open_win|.
*cmp-config.window.completion.col_offset*
window.completion.col_offset~
`number`
Offsets the completion window relative to the cursor.
*cmp-config.window.completion.side_padding*
window.completion.side_padding~
`number`
The ammount of padding to add on the completion window's sides
*cmp-config.window.documentation.max_width* *cmp-config.window.documentation.max_width*
window.documentation.max_width~ window.documentation.max_width~
`number` `number`

View File

@@ -90,6 +90,8 @@ return function()
completion = { completion = {
border = { '', '', '', '', '', '', '', '' }, border = { '', '', '', '', '', '', '', '' },
winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None', winhighlight = 'Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None',
col_offset = 0,
side_padding = 1,
}, },
documentation = { documentation = {
max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)), max_height = math.floor(WIDE_HEIGHT * (WIDE_HEIGHT / vim.o.lines)),

View File

@@ -6,6 +6,8 @@ window.bordered = function(opts)
border = opts.border or 'rounded', border = opts.border or 'rounded',
winhighlight = opts.winhighlight or 'Normal:Normal,FloatBorder:Normal,CursorLine:Visual,Search:None', winhighlight = opts.winhighlight or 'Normal:Normal,FloatBorder:Normal,CursorLine:Visual,Search:None',
zindex = opts.zindex or 1001, zindex = opts.zindex or 1001,
col_offset = opts.col_offset or 0,
side_padding = opts.side_padding or 1
} }
end end

View File

@@ -8,8 +8,6 @@ local keymap = require('cmp.utils.keymap')
local misc = require('cmp.utils.misc') local misc = require('cmp.utils.misc')
local api = require('cmp.utils.api') local api = require('cmp.utils.api')
local SIDE_PADDING = 1
local DEFAULT_HEIGHT = 10 -- @see https://github.com/vim/vim/blob/master/src/popupmenu.c#L45 local DEFAULT_HEIGHT = 10 -- @see https://github.com/vim/vim/blob/master/src/popupmenu.c#L45
---@class cmp.CustomEntriesView ---@class cmp.CustomEntriesView
@@ -65,7 +63,7 @@ custom_entries_view.new = function()
local e = self.entries[i + 1] local e = self.entries[i + 1]
if e then if e then
local v = e:get_view(self.offset, buf) local v = e:get_view(self.offset, buf)
local o = SIDE_PADDING local o = config.get().window.completion.side_padding
local a = 0 local a = 0
for _, field in ipairs(fields) do for _, field in ipairs(fields) do
if field == types.cmp.ItemField.Abbr then if field == types.cmp.ItemField.Abbr then
@@ -200,7 +198,7 @@ custom_entries_view.open = function(self, offset, entries)
relative = 'editor', relative = 'editor',
style = 'minimal', style = 'minimal',
row = math.max(0, row), row = math.max(0, row),
col = math.max(0, col), col = math.max(0, col + completion.col_offset),
width = width, width = width,
height = height, height = height,
border = completion.border, border = completion.border,
@@ -255,12 +253,12 @@ custom_entries_view.draw = function(self)
if e then if e then
local view = e:get_view(self.offset, entries_buf) local view = e:get_view(self.offset, entries_buf)
local text = {} local text = {}
table.insert(text, string.rep(' ', SIDE_PADDING)) table.insert(text, string.rep(' ', config.get().window.completion.side_padding))
for _, field in ipairs(fields) do for _, field in ipairs(fields) do
table.insert(text, view[field].text) table.insert(text, view[field].text)
table.insert(text, string.rep(' ', 1 + self.column_width[field] - view[field].width)) table.insert(text, string.rep(' ', 1 + self.column_width[field] - view[field].width))
end end
table.insert(text, string.rep(' ', SIDE_PADDING)) table.insert(text, string.rep(' ', config.get().window.completion.side_padding))
table.insert(texts, table.concat(text, '')) table.insert(texts, table.concat(text, ''))
end end
end end