aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorGrace Petryk <gracepetryk99@gmail.com>2023-09-10 01:02:23 -0700
committerGitHub <noreply@github.com>2023-09-10 10:02:23 +0200
commit5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0 (patch)
tree58a9fb5ab1b61d9d2d416636a0bc600b1c9fa484 /runtime/lua/vim/lsp/util.lua
parentbb38c066a96512cf8cb2ef2e733494b5bbdfa3fd (diff)
downloadrneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.tar.gz
rneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.tar.bz2
rneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.zip
feat(lsp): improve control over placement of floating windows (#24494)
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index a6d17afa1b..e76fd15612 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1087,6 +1087,12 @@ end
--- - focusable (string or table) override `focusable`
--- - zindex (string or table) override `zindex`, defaults to 50
--- - relative ("mouse"|"cursor") defaults to "cursor"
+--- - anchor_bias ("auto"|"above"|"below") defaults to "auto"
+--- - "auto": place window based on which side of the cursor has more lines
+--- - "above": place the window above the cursor unless there are not enough lines
+--- to display the full window height.
+--- - "below": place the window below the cursor unless there are not enough lines
+--- to display the full window height.
---@return table Options
function M.make_floating_popup_options(width, height, opts)
validate({
@@ -1105,7 +1111,20 @@ function M.make_floating_popup_options(width, height, opts)
or vim.fn.winline() - 1
local lines_below = vim.fn.winheight(0) - lines_above
- if lines_above < lines_below then
+ local anchor_bias = opts.anchor_bias or 'auto'
+
+ local anchor_below
+
+ if anchor_bias == 'below' then
+ anchor_below = (lines_below > lines_above) or (height <= lines_below)
+ elseif anchor_bias == 'above' then
+ local anchor_above = (lines_above > lines_below) or (height <= lines_above)
+ anchor_below = not anchor_above
+ else
+ anchor_below = lines_below > lines_above
+ end
+
+ if anchor_below then
anchor = anchor .. 'N'
height = math.min(lines_below, height)
row = 1
@@ -1635,7 +1654,8 @@ end
---
---@param contents table of lines to show in window
---@param syntax string of syntax to set for opened buffer
----@param opts table with optional fields (additional keys are passed on to |nvim_open_win()|)
+---@param opts table with optional fields (additional keys are filtered with |vim.lsp.util.make_floating_popup_options()|
+--- before they are passed on to |nvim_open_win()|)
--- - height: (integer) height of floating window
--- - width: (integer) width of floating window
--- - wrap: (boolean, default true) wrap long lines