From 78cf6ee024cbf6a17dc8406555eb131994cd8b63 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com> Date: Mon, 1 Jul 2024 00:14:00 +0300 Subject: [PATCH] feat(cmp): attempt for dynamic width and trimming between fields (#3873) ## What is this PR for? Attempt for dynamic width and trimming between fields. Testing was done on my 15.6 laptop screen so maybe values could be raised in dynamic calculation? Also provides a `vim.g.cmp_fixed_width` for the users to be able to define a fixed width in their personal configuration if they'd like to. ## Does this PR fix an existing issue? Attempts to rectify a concern raised in #3858 ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/plugins/coding.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/coding.lua b/lua/lazyvim/plugins/coding.lua index 4e79d6dda2..ffd743b35d 100644 --- a/lua/lazyvim/plugins/coding.lua +++ b/lua/lazyvim/plugins/coding.lua @@ -54,9 +54,18 @@ return { if icons[item.kind] then item.kind = icons[item.kind] .. item.kind end - if entry.context.filetype == "rust" then - item.menu = nil + + local widths = { + abbr = vim.g.cmp_widths and vim.g.cmp_widths.abbr or 40, + menu = vim.g.cmp_widths and vim.g.cmp_widths.menu or 30, + } + + for key, width in pairs(widths) do + if item[key] and vim.fn.strdisplaywidth(item[key]) > width then + item[key] = vim.fn.strcharpart(item[key], 0, width - 1) .. "…" + end end + return item end, },