feat: allow more completion highlight control (#1972)
* feat(view): allow hl_group to be a table * feat: improve table field naming
This commit is contained in:
committed by
GitHub
parent
88661b7cbf
commit
29fb485457
@@ -260,7 +260,7 @@ end
|
||||
---Return view information.
|
||||
---@param suggest_offset integer
|
||||
---@param entries_buf integer The buffer this entry will be rendered into.
|
||||
---@return { abbr: { text: string, bytes: integer, width: integer, hl_group: string }, kind: { text: string, bytes: integer, width: integer, hl_group: string }, menu: { text: string, bytes: integer, width: integer, hl_group: string } }
|
||||
---@return { abbr: { text: string, bytes: integer, width: integer, hl_group: string|table }, kind: { text: string, bytes: integer, width: integer, hl_group: string|table }, menu: { text: string, bytes: integer, width: integer, hl_group: string|table } }
|
||||
entry.get_view = function(self, suggest_offset, entries_buf)
|
||||
local item = self:get_vim_item(suggest_offset)
|
||||
return self.cache:ensure('get_view:' .. tostring(entries_buf), entry._get_view, self, item, entries_buf)
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
---@field public empty 1|nil
|
||||
---@field public dup 1|nil
|
||||
---@field public id any
|
||||
---@field public abbr_hl_group string|nil
|
||||
---@field public kind_hl_group string|nil
|
||||
---@field public menu_hl_group string|nil
|
||||
---@field public abbr_hl_group string|table|nil
|
||||
---@field public kind_hl_group string|table|nil
|
||||
---@field public menu_hl_group string|table|nil
|
||||
|
||||
---@class vim.Position 1-based index
|
||||
---@field public row integer
|
||||
|
||||
@@ -70,13 +70,28 @@ custom_entries_view.new = function()
|
||||
if field == types.cmp.ItemField.Abbr then
|
||||
a = o
|
||||
end
|
||||
vim.api.nvim_buf_set_extmark(buf, custom_entries_view.ns, i, o, {
|
||||
end_line = i,
|
||||
end_col = o + v[field].bytes,
|
||||
hl_group = v[field].hl_group,
|
||||
hl_mode = 'combine',
|
||||
ephemeral = true,
|
||||
})
|
||||
|
||||
if type(v[field].hl_group) == 'table' then
|
||||
for _, extmark in ipairs(v[field].hl_group) do
|
||||
local hl_start, hl_end = unpack(extmark.range)
|
||||
vim.api.nvim_buf_set_extmark(buf, custom_entries_view.ns, i, o + hl_start, {
|
||||
end_line = i,
|
||||
end_col = o + hl_end,
|
||||
hl_group = extmark[1],
|
||||
hl_eol = false,
|
||||
ephemeral = true,
|
||||
})
|
||||
end
|
||||
else
|
||||
vim.api.nvim_buf_set_extmark(buf, custom_entries_view.ns, i, o, {
|
||||
end_line = i,
|
||||
end_col = o + v[field].bytes,
|
||||
hl_group = v[field].hl_group,
|
||||
hl_mode = 'combine',
|
||||
ephemeral = true,
|
||||
})
|
||||
end
|
||||
|
||||
o = o + v[field].bytes + (self.column_width[field] - v[field].width) + 1
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user