Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit f9f729e

Browse files
committed
feat: wrap on hover window(#63)
1 parent 5d8a885 commit f9f729e

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

lua/completion/hover.lua

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,22 +265,31 @@ function M.modifyCallback()
265265
local bufnr, winnr
266266
-- modified to open hover window align to popupmenu
267267

268-
local position = vim.fn.pum_getpos()
269-
-- Set max width option to avoid overlapping with popup menu
270-
local total_column = api.nvim_get_option('columns')
271-
local align
272-
if position['col'] < total_column/2 then
273-
align = 'right'
274-
else
275-
align = 'left'
276-
end
277-
bufnr, winnr = fancy_floating_markdown(markdown_lines, {
278-
pad_left = 1; pad_right = 1;
279-
col = position['col']; width = position['width']; row = position['row']-1;
280-
align = align
281-
})
282-
M.winnr = winnr
268+
local position = vim.fn.pum_getpos()
269+
-- Set max width option to avoid overlapping with popup menu
270+
local total_column = api.nvim_get_option('columns')
271+
local align
272+
if position['col'] < total_column/2 then
273+
align = 'right'
274+
else
275+
align = 'left'
276+
end
277+
bufnr, winnr = fancy_floating_markdown(markdown_lines, {
278+
pad_left = 1; pad_right = 1;
279+
col = position['col']; width = position['width']; row = position['row']-1;
280+
align = align
281+
})
282+
M.winnr = winnr
283+
283284
vim.lsp.util.close_preview_autocmd({"CursorMoved", "BufHidden", "InsertCharPre"}, winnr)
285+
local hover_len = #vim.api.nvim_buf_get_lines(bufnr,0,-1,false)[1]
286+
local win_width = vim.api.nvim_win_get_width(0)
287+
print(hover_len, win_width)
288+
if hover_len > win_width then
289+
vim.api.nvim_win_set_width(winnr,math.min(hover_len,win_width))
290+
vim.api.nvim_win_set_height(winnr,math.ceil(hover_len/win_width))
291+
vim.wo[winnr].wrap = true
292+
end
284293
return bufnr, winnr
285294
end)
286295
else

0 commit comments

Comments
 (0)