diff options
author | zeertzjq <zeertzjq@outlook.com> | 2021-08-27 19:19:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-27 04:19:17 -0700 |
commit | f6e662bbe913614c5dc701648c088d13fc7c060e (patch) | |
tree | 7d43663e5983065a3c675938fe0fe1f13f4dd26b /runtime/lua/vim/lsp/util.lua | |
parent | 274a3504a790a799b28ee89c75e29fb4dbdff41f (diff) | |
download | rneovim-f6e662bbe913614c5dc701648c088d13fc7c060e.tar.gz rneovim-f6e662bbe913614c5dc701648c088d13fc7c060e.tar.bz2 rneovim-f6e662bbe913614c5dc701648c088d13fc7c060e.zip |
feat(lsp): get_border_size(): support repeating border char list #15474
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index a4b3298fd8..a4c8b69f6c 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -43,7 +43,9 @@ local loclist_type_map = { ---@private --- Check the border given by opts or the default border for the additional --- size it adds to a float. ----@returns size of border in height and width +---@param opts (table, optional) options for the floating window +--- - border (string or table) the border +---@returns (table) size of border in the form of { height = height, width = width } local function get_border_size(opts) local border = opts and opts.border or default_border local height = 0 @@ -52,12 +54,16 @@ local function get_border_size(opts) if type(border) == 'string' then local border_size = {none = {0, 0}, single = {2, 2}, double = {2, 2}, rounded = {2, 2}, solid = {2, 2}, shadow = {1, 1}} if border_size[border] == nil then - error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" - .. vim.inspect(border)) + error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border))) end height, width = unpack(border_size[border]) else + if 8 % #border ~= 0 then + error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border))) + end + ---@private local function border_width(id) + id = (id - 1) % #border + 1 if type(border[id]) == "table" then -- border specified as a table of <character, highlight group> return vim.fn.strdisplaywidth(border[id][1]) @@ -65,9 +71,11 @@ local function get_border_size(opts) -- border specified as a list of border characters return vim.fn.strdisplaywidth(border[id]) end - error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" .. vim.inspect(border)) + error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border))) end + ---@private local function border_height(id) + id = (id - 1) % #border + 1 if type(border[id]) == "table" then -- border specified as a table of <character, highlight group> return #border[id][1] > 0 and 1 or 0 @@ -75,7 +83,7 @@ local function get_border_size(opts) -- border specified as a list of border characters return #border[id] > 0 and 1 or 0 end - error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" .. vim.inspect(border)) + error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border))) end height = height + border_height(2) -- top height = height + border_height(6) -- bottom |