From a4f83fd8394c5e7f700758cf21a3429b5e54b737 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sat, 8 Jan 2022 13:33:53 +0900 Subject: [PATCH] Fix #589 --- doc/cmp.txt | 2 ++ lua/cmp/entry.lua | 6 +++--- lua/cmp/types/vim.lua | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/cmp.txt b/doc/cmp.txt index d71b866..9c05f32 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -383,6 +383,8 @@ completion.autocomplete~ formatting.format~ `fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem` The function to customize the completion menu appearance. See |complete-items|. + NOTE: The `vim.CompletedItem` can have special properties `abbr_hl_group`, + `kind_hl_group` and `menu_hl_group`. *cmp-config.formatting.fields* formatting.fields~ diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 6e03496..abcccd3 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -213,17 +213,17 @@ entry.get_view = function(self, suggest_offset, entries_buf) view.abbr.text = item.abbr or '' view.abbr.bytes = #view.abbr.text view.abbr.width = vim.fn.strdisplaywidth(view.abbr.text) - view.abbr.hl_group = self:is_deprecated() and 'CmpItemAbbrDeprecated' or 'CmpItemAbbr' + view.abbr.hl_group = item.abbr_hl_group or (self:is_deprecated() and 'CmpItemAbbrDeprecated' or 'CmpItemAbbr') view.kind = {} view.kind.text = item.kind or '' view.kind.bytes = #view.kind.text view.kind.width = vim.fn.strdisplaywidth(view.kind.text) - view.kind.hl_group = 'CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '') + view.kind.hl_group = item.kind_hl_group or ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '')) view.menu = {} view.menu.text = item.menu or '' view.menu.bytes = #view.menu.text view.menu.width = vim.fn.strdisplaywidth(view.menu.text) - view.menu.hl_group = 'CmpItemMenu' + view.menu.hl_group = item.menu_hl_group or 'CmpItemMenu' view.dup = item.dup end) return view diff --git a/lua/cmp/types/vim.lua b/lua/cmp/types/vim.lua index a2a6cf4..0ae28c6 100644 --- a/lua/cmp/types/vim.lua +++ b/lua/cmp/types/vim.lua @@ -7,6 +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 ---@class vim.Position ---@field public row number