mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
fix(lsp): handle using array as open_floating_preview title (#33016)
This commit is contained in:
@@ -2101,7 +2101,7 @@ Lua module: vim.lsp.util *lsp-util*
|
|||||||
• {border}? (`string|(string|[string,string])[]`) override
|
• {border}? (`string|(string|[string,string])[]`) override
|
||||||
`border`
|
`border`
|
||||||
• {zindex}? (`integer`) override `zindex`, defaults to 50
|
• {zindex}? (`integer`) override `zindex`, defaults to 50
|
||||||
• {title}? (`string`)
|
• {title}? (`string|[string,string][]`)
|
||||||
• {title_pos}? (`'left'|'center'|'right'`)
|
• {title_pos}? (`'left'|'center'|'right'`)
|
||||||
• {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`)
|
• {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`)
|
||||||
• {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) Adjusts
|
• {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) Adjusts
|
||||||
|
@@ -1411,10 +1411,16 @@ function M._make_floating_popup_size(contents, opts)
|
|||||||
width = math.min(width, screen_width - border_width)
|
width = math.min(width, screen_width - border_width)
|
||||||
|
|
||||||
-- Make sure that the width is large enough to fit the title.
|
-- Make sure that the width is large enough to fit the title.
|
||||||
if opts.title then
|
local title_length = 0
|
||||||
width = math.max(width, vim.fn.strdisplaywidth(opts.title))
|
local chunks = type(opts.title) == 'string' and { { opts.title } } or opts.title or {}
|
||||||
|
for _, chunk in
|
||||||
|
ipairs(chunks --[=[@as [string, string][]]=])
|
||||||
|
do
|
||||||
|
title_length = title_length + vim.fn.strdisplaywidth(chunk[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
width = math.max(width, title_length)
|
||||||
|
|
||||||
if wrap_at then
|
if wrap_at then
|
||||||
wrap_at = math.min(wrap_at, width)
|
wrap_at = math.min(wrap_at, width)
|
||||||
end
|
end
|
||||||
@@ -1490,7 +1496,7 @@ end
|
|||||||
--- @field offset_y? integer
|
--- @field offset_y? integer
|
||||||
--- @field border? string|(string|[string,string])[] override `border`
|
--- @field border? string|(string|[string,string])[] override `border`
|
||||||
--- @field zindex? integer override `zindex`, defaults to 50
|
--- @field zindex? integer override `zindex`, defaults to 50
|
||||||
--- @field title? string
|
--- @field title? string|[string,string][]
|
||||||
--- @field title_pos? 'left'|'center'|'right'
|
--- @field title_pos? 'left'|'center'|'right'
|
||||||
---
|
---
|
||||||
--- (default: `'cursor'`)
|
--- (default: `'cursor'`)
|
||||||
|
@@ -3529,7 +3529,7 @@ describe('LSP', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('considers title when computing width', function()
|
it('considers string title when computing width', function()
|
||||||
eq(
|
eq(
|
||||||
{ 17, 2 },
|
{ 17, 2 },
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
@@ -3542,6 +3542,20 @@ describe('LSP', function()
|
|||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('considers [string,string][] title when computing width', function()
|
||||||
|
eq(
|
||||||
|
{ 17, 2 },
|
||||||
|
exec_lua(function()
|
||||||
|
return {
|
||||||
|
vim.lsp.util._make_floating_popup_size(
|
||||||
|
{ 'foo', 'bar' },
|
||||||
|
{ title = { { 'A very ', 'Normal' }, { 'long title', 'Normal' } } }
|
||||||
|
),
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('lsp.util.trim.trim_empty_lines', function()
|
describe('lsp.util.trim.trim_empty_lines', function()
|
||||||
|
Reference in New Issue
Block a user