Skip to content

Commit f510705

Browse files
committed
fix: calculate max width for docs window
1 parent 2aacbee commit f510705

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lua/blink/cmp/windows/documentation.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,27 @@ function docs.show_item(item)
7272
vim.cmd('syntax clear')
7373
vim.api.nvim_buf_set_lines(docs.win:get_buf(), 0, -1, false, {})
7474
end)
75+
76+
-- calculate longest line clamped to config.max_width
77+
local max_width = 0
78+
for _, l in ipairs(doc_lines) do
79+
local len = #l
80+
if len > max_width then
81+
if len >= config.max_width then
82+
max_width = config.max_width
83+
break
84+
end
85+
max_width = len
86+
end
87+
end
88+
7589
-- use the built-in markdown styling
7690
-- NOTE: according to https://github.com/Saghen/blink.cmp/pull/33#issuecomment-2400195950
7791
-- it's possible for this to fail so we call it safely
7892
local stylize_success = pcall(
7993
function()
8094
vim.lsp.util.stylize_markdown(docs.win:get_buf(), doc_lines, {
81-
max_width = config.max_width,
95+
max_width = max_width,
8296
max_height = config.max_height,
8397
})
8498
end

0 commit comments

Comments
 (0)