neovim/test/functional
Sebastian Lyng Johansen 870ca1de52
feat(float): open float relative to mouse #21531
Problem:
No easy way to position a LSP hover window relative to mouse.

Solution:
Introduce another option to the `relative` key in `nvim_open_win()`.

With this PR it should be possible to override the handler and do something
similar to this https://github.com/neovim/neovim/pull/19481#issuecomment-1193248674
to have hover information displayed from the mouse.

Test case:

    ```lua
    local util = require('vim.lsp.util')

    local function make_position_param(window, offset_encoding)
        window = window or 0
        local buf = vim.api.nvim_win_get_buf(window)
        local row, col

        local mouse = vim.fn.getmousepos()
        row = mouse.line
        col = mouse.column

        offset_encoding = offset_encoding or util._get_offset_encoding(buf)
        row = row - 1
        local line = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1]
        if not line then
            return { line = 0, character = 0 }
        end
        if #line < col then
            return { line = 0, character = 0 }
        end

        col = util._str_utfindex_enc(line, col, offset_encoding)

        return { line = row, character = col }
    end

    local make_params = function(window, offset_encoding)
        window = window or 0
        local buf = vim.api.nvim_win_get_buf(window)
        offset_encoding = offset_encoding or util._get_offset_encoding(buf)
        return {
            textDocument = util.make_text_document_params(buf),
            position = make_position_param(window, offset_encoding),
        }
    end

    local hover_timer = nil
    vim.o.mousemoveevent = true

    vim.keymap.set({ '', 'i' }, '<MouseMove>', function()
        if hover_timer then
            hover_timer:close()
        end
        hover_timer = vim.defer_fn(function()
            hover_timer = nil
            local params = make_params()
            vim.lsp.buf_request(
                0,
                'textDocument/hover',
                params,
                vim.lsp.with(vim.lsp.handlers.hover, {
                    silent = true,
                    focusable = false,
                    relative = 'mouse',
                })
            )
        end, 500)
        return '<MouseMove>'
    end, { expr = true })
    ```
2023-01-10 02:22:41 -08:00
..
api fix(statusline): make nvim_eval_statusline() work with %S (#21553) 2022-12-27 18:04:42 +08:00
autocmd fix(tui): more work in the TUI 2022-12-31 13:25:26 +01:00
core feat(lua): store "nvim -l" scriptname in _G.arg[0] 2023-01-07 03:03:38 +01:00
editor test(undo_spec): add more tests for writing in Insert mode 2022-12-09 07:00:27 +08:00
ex_cmds test: add more tests for Unicode 2023-01-09 17:11:39 +08:00
fixtures feat(lua): exit 1 on Lua "-l" script error 2023-01-05 17:10:02 +01:00
legacy docs: fix typos (#21427) 2023-01-04 07:38:48 +08:00
lua feat(ui): add 'statuscolumn' option 2023-01-09 17:12:06 +00:00
options test: simplify platform detection (#21020) 2022-11-22 08:13:30 +08:00
plugin dist: transpile cfilter.vim => cfilter.lua #21662 2023-01-08 12:31:38 -08:00
provider fix(clipboard): show provider warning when not during batch changes #21451 2023-01-03 15:17:54 -08:00
shada test: simplify platform detection (#21020) 2022-11-22 08:13:30 +08:00
terminal test(tui_spec): doesn't use Unicode in cursor_address test (#21703) 2023-01-09 17:02:45 +08:00
treesitter feat: vim.inspect_pos, vim.show_pos, :Inspect 2022-12-17 13:05:31 +01:00
ui feat(float): open float relative to mouse #21531 2023-01-10 02:22:41 -08:00
vimscript feat(lua): exit 1 on Lua "-l" script error 2023-01-05 17:10:02 +01:00
example_spec.lua
helpers.lua fix(tui): more work in the TUI 2022-12-31 13:25:26 +01:00
preload.lua test: remove unused variable (#21552) 2022-12-29 07:20:42 +08:00