fix(float)!: always anchor to corner of window including border #15832

N, W, S, E are all inclusive, i.e., always anchor to the exact corner of the
window (including border). This line may also need change in this case (change
0 to -1):

This is most consistent and easiest to reason about, especially with GUIs whose
border do not need to have width/height of 1/1 in cell units.

Fix #15789
This commit is contained in:
zeertzjq
2021-10-03 08:36:24 +08:00
committed by GitHub
parent c5e8c39102
commit b3e815094b
5 changed files with 295 additions and 83 deletions

View File

@@ -2022,83 +2022,6 @@ describe('LSP', function()
end)
end)
describe('lsp.util.make_floating_popup_options', function()
before_each(function()
exec_lua [[
local bufnr = vim.uri_to_bufnr("file:///fake/uri")
local winheight = vim.fn.winheight(0)
for i = 1, winheight do
vim.api.nvim_buf_set_lines(bufnr, 0, 0, false, {''})
end
vim.api.nvim_win_set_buf(0, bufnr)
vim.api.nvim_win_set_cursor(0, {winheight, 0})
]]
end)
local function popup_row(opts)
return exec_lua([[
return vim.lsp.util.make_floating_popup_options(...).row
]], 2, 2, opts)
end
local err_pattern = "^Error executing lua: %.%.%./util%.lua:0: invalid floating preview border: .*%. :help vim%.api%.nvim_open_win%(%)$"
it('calculates default border height correctly', function()
eq(0, popup_row())
end)
it('calculates string border height correctly', function()
eq(0, popup_row({border = 'none'}))
eq(-2, popup_row({border = 'single'}))
eq(-2, popup_row({border = 'double'}))
eq(-2, popup_row({border = 'rounded'}))
eq(-2, popup_row({border = 'solid'}))
eq(-1, popup_row({border = 'shadow'}))
end)
it('error on invalid string border', function()
matches(err_pattern, pcall_err(popup_row, {border = ''}))
matches(err_pattern, pcall_err(popup_row, {border = 'invalid'}))
end)
it('error on invalid array border length', function()
matches(err_pattern, pcall_err(popup_row, {border = {}}))
matches(err_pattern, pcall_err(popup_row, {border = {'', '', ''}}))
matches(err_pattern, pcall_err(popup_row, {border = {'', '', '', '', ''}}))
end)
it('error on invalid array border member type', function()
matches(err_pattern, pcall_err(popup_row, {border = {0}}))
end)
it('calculates 8-array border height correctly', function()
eq(0, popup_row({border = {'', '', '', '', '', '', '', ''}}))
eq(-2, popup_row({border = {'', '~', '', '~', '', '~', '', '~'}}))
eq(-1, popup_row({border = {'', '', '', '~', '', '~', '', ''}}))
eq(0, popup_row({border = {'', '', '', {'~', 'NormalFloat'}, '', '', '', {'~', 'NormalFloat'}}}))
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}, '', '', '', {'~', 'NormalFloat'}, '', ''}}))
end)
it('calculates 4-array border height correctly', function()
eq(0, popup_row({border = {'', '', '', ''}}))
eq(-2, popup_row({border = {'', '~', '', '~'}}))
eq(0, popup_row({border = {'', '', '', {'~', 'NormalFloat'}}}))
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}, '', ''}}))
end)
it('calculates 2-array border height correctly', function()
eq(0, popup_row({border = {'', ''}}))
eq(-2, popup_row({border = {'', '~'}}))
eq(-2, popup_row({border = {'', {'~', 'NormalFloat'}}}))
end)
it('calculates 1-array border height correctly', function()
eq(0, popup_row({border = {''}}))
eq(-2, popup_row({border = {'~'}}))
eq(-2, popup_row({border = {{'~', 'NormalFloat'}}}))
end)
end)
describe('lsp.util._make_floating_popup_size', function()
before_each(function()
exec_lua [[ contents =