Files
neovim/runtime/doc
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
..
2022-12-11 18:41:26 -08:00
2023-01-09 17:12:06 +00:00
2022-11-10 09:05:25 +00:00
2022-12-08 16:33:38 +01:00
2021-09-10 08:48:27 +02:00
2022-02-27 11:56:30 +01:00
2023-01-01 15:05:13 +01:00
2023-01-01 15:05:13 +01:00
2023-01-01 15:05:13 +01:00
2023-01-03 10:07:43 +00:00
2023-01-01 15:05:13 +01:00
2023-01-03 10:07:43 +00:00
2023-01-01 15:05:13 +01:00
2023-01-01 15:05:13 +01:00
2023-01-04 07:38:48 +08:00
2023-01-05 17:10:02 +01:00
2023-01-10 11:02:00 +01:00
2023-01-01 15:05:13 +01:00
2022-10-14 08:01:13 -07:00
2023-01-01 15:05:13 +01:00
2022-12-11 18:41:26 -08:00
2023-01-10 11:02:00 +01:00
2018-10-29 09:55:07 +01:00
2023-01-03 10:07:43 +00:00
2018-10-29 09:55:07 +01:00
2022-11-10 09:05:25 +00:00
2015-08-15 15:25:30 -03:00
2022-12-11 18:41:26 -08:00
2023-01-04 07:38:48 +08:00
2019-03-26 19:55:33 +01:00
2022-12-31 13:25:26 +01:00
2022-11-02 21:45:26 +08:00
2023-01-01 15:05:13 +01:00
2022-11-10 09:05:25 +00:00
2023-01-01 15:05:13 +01:00
2022-09-26 17:43:23 +08:00
2023-01-01 15:05:13 +01:00
2022-10-15 17:42:45 +08:00
2022-12-31 13:25:26 +01:00
2022-07-26 11:26:23 +02:00
2023-01-10 11:02:00 +01:00
2022-11-10 09:05:25 +00:00
2023-01-03 10:07:43 +00:00
2021-09-08 07:24:12 -07:00
2021-05-01 22:29:02 -04:00
2021-05-02 12:53:49 -04:00
2022-09-26 17:43:23 +08:00
2021-05-01 22:29:03 -04:00
2021-04-27 09:21:33 -04:00
2018-10-29 10:01:44 +01:00
2021-04-29 09:27:19 -04:00
2018-10-29 10:01:44 +01:00
2021-04-29 20:42:16 -04:00
2019-03-26 19:55:33 +01:00
2021-04-27 09:21:34 -04:00
2023-01-03 10:07:43 +00:00
2023-01-03 10:07:43 +00:00
2023-01-03 10:07:43 +00:00
2023-01-03 10:07:43 +00:00
2022-11-10 09:05:25 +00:00