diff options
author | Grace Petryk <gracepetryk99@gmail.com> | 2023-09-10 01:02:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-10 10:02:23 +0200 |
commit | 5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0 (patch) | |
tree | 58a9fb5ab1b61d9d2d416636a0bc600b1c9fa484 /test/functional/plugin/lsp/utils_spec.lua | |
parent | bb38c066a96512cf8cb2ef2e733494b5bbdfa3fd (diff) | |
download | rneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.tar.gz rneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.tar.bz2 rneovim-5e3cf9fb4bc7f236c858f609ca83c57fb1779ab0.zip |
feat(lsp): improve control over placement of floating windows (#24494)
Diffstat (limited to 'test/functional/plugin/lsp/utils_spec.lua')
-rw-r--r-- | test/functional/plugin/lsp/utils_spec.lua | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp/utils_spec.lua b/test/functional/plugin/lsp/utils_spec.lua index c91fffa90f..f544255d81 100644 --- a/test/functional/plugin/lsp/utils_spec.lua +++ b/test/functional/plugin/lsp/utils_spec.lua @@ -1,4 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local feed = helpers.feed local eq = helpers.eq local exec_lua = helpers.exec_lua @@ -85,4 +87,98 @@ describe('vim.lsp.util', function() eq(expected, stylize_markdown(lines, opts)) end) end) + + describe("make_floating_popup_options", function () + + local function assert_anchor(anchor_bias, expected_anchor) + local opts = exec_lua([[ + local args = { ... } + local anchor_bias = args[1] + return vim.lsp.util.make_floating_popup_options(30, 10, { anchor_bias = anchor_bias }) + ]], anchor_bias) + + eq(expected_anchor, string.sub(opts.anchor, 1, 1)) + end + + local screen + before_each(function () + helpers.clear() + screen = Screen.new(80, 80) + screen:attach() + feed("79i<CR><Esc>") -- fill screen with empty lines + end) + + describe('when on the first line it places window below', function () + before_each(function () + feed('gg') + end) + + it('for anchor_bias = "auto"', function () + assert_anchor('auto', 'N') + end) + + it('for anchor_bias = "above"', function () + assert_anchor('above', 'N') + end) + + it('for anchor_bias = "below"', function () + assert_anchor('below', 'N') + end) + end) + + describe('when on the last line it places window above', function () + before_each(function () + feed('G') + end) + + it('for anchor_bias = "auto"', function () + assert_anchor('auto', 'S') + end) + + it('for anchor_bias = "above"', function () + assert_anchor('above', 'S') + end) + + it('for anchor_bias = "below"', function () + assert_anchor('below', 'S') + end) + end) + + describe('with 20 lines above, 59 lines below', function () + before_each(function () + feed('gg20j') + end) + + it('places window below for anchor_bias = "auto"', function () + assert_anchor('auto', 'N') + end) + + it('places window above for anchor_bias = "above"', function () + assert_anchor('above', 'S') + end) + + it('places window below for anchor_bias = "below"', function () + assert_anchor('below', 'N') + end) + end) + + describe('with 59 lines above, 20 lines below', function () + before_each(function () + feed('G20k') + end) + + it('places window above for anchor_bias = "auto"', function () + assert_anchor('auto', 'S') + end) + + it('places window above for anchor_bias = "above"', function () + assert_anchor('above', 'S') + end) + + it('places window below for anchor_bias = "below"', function () + assert_anchor('below', 'N') + end) + end) + end) + end) |