From b3dbc8eddf5f21c1581c9bbbeb043acc6dda1b75 Mon Sep 17 00:00:00 2001 From: fiplox Date: Sun, 9 Apr 2023 12:42:41 +0200 Subject: [PATCH] feat: make menu fixed size --- lua/plugins/cmp.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index d22091f..abd6403 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -76,9 +76,17 @@ function M.config() ghost_text = true, }, formatting = { - fields = { 'menu', 'abbr', 'kind' }, - format = function(_, item) + fields = { 'abbr', 'kind', 'menu' }, + format = function(entry, item) + local ELLIPSIS_CHAR = '…' + local MAX_LABEL_WIDTH = 20 item.kind = string.format('%s %s', kind_icons[item.kind], item.kind) -- This concatonates the icons with the name of the item kind + + local label = item.abbr + local truncated_label = vim.fn.strcharpart(label, 0, MAX_LABEL_WIDTH) + if truncated_label ~= label then + item.abbr = truncated_label .. ELLIPSIS_CHAR + end return item end, },