mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
feat(cmp): attempt for dynamic width and trimming between fields
This commit is contained in:
parent
00f53315b5
commit
b129a100c3
1 changed files with 26 additions and 2 deletions
|
|
@ -54,9 +54,33 @@ return {
|
|||
if icons[item.kind] then
|
||||
item.kind = icons[item.kind] .. item.kind
|
||||
end
|
||||
if entry.context.filetype == "rust" then
|
||||
item.menu = nil
|
||||
|
||||
-- Set 'fixed_width' to false if not provided.
|
||||
local fixed_width = vim.g.cmp_fixed_width or false
|
||||
|
||||
-- Set the fixed completion window width.
|
||||
if fixed_width then
|
||||
vim.o.pumwidth = fixed_width
|
||||
end
|
||||
|
||||
-- Get the width of the current window.
|
||||
local win_width = vim.api.nvim_win_get_width(0)
|
||||
|
||||
-- Set the max content width based on either: 'fixed_width'
|
||||
-- or a percentage of the window width, in this case 20%.
|
||||
-- We subtract 10 from 'fixed_width' to leave room for 'kind' fields.
|
||||
local max_content_width = fixed_width and fixed_width - 10 or math.floor(win_width * 0.25)
|
||||
|
||||
-- Truncate the completion entry text if it's longer than the
|
||||
-- max content width. We subtract 3 from the max content width
|
||||
-- to account for the "..." that will be appended to it.
|
||||
if #item.abbr > (max_content_width / 2) then
|
||||
item.abbr = vim.fn.strcharpart(item.abbr, 0, math.floor(max_content_width * 0.7) - 3) .. "..."
|
||||
end
|
||||
if item.menu and #item.menu > (max_content_width / 2) then
|
||||
item.menu = vim.fn.strcharpart(item.menu, 0, math.floor(max_content_width * 0.7) - 3) .. "..."
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue