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
..
api.txt feat(float): open float relative to mouse #21531 2023-01-10 02:22:41 -08:00
arabic.txt feat(docs): update parser, HTML gen #20720 2022-10-18 07:18:44 -07:00
autocmd.txt vim-patch:partial:b59ae59a5870 (#21170) 2022-11-24 10:23:50 +00:00
builtin.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
change.txt docs: add missing docs from some Vim patches (#21296) 2022-12-05 21:09:31 +08:00
channel.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
cmdline.txt vim-patch:9.0.0861: solution for "!!sort" in closed fold is not optimal (#21027) 2022-11-12 07:43:36 +08:00
debug.txt vim-patch:8.1.1306: Borland support is outdated and doesn't work 2019-05-09 20:27:11 -04:00
deprecated.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
dev_style.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
develop.txt docs #20986 2022-12-11 18:41:26 -08:00
diagnostic.txt feat(highlight): add DiagnosticOk (and associated) highlight groups (#21286) 2022-12-28 09:01:40 -07:00
diff.txt vim-patch:partial:f1dcd14fc5d4 (#21602) 2023-01-01 15:00:39 +01:00
digraph.txt vim-patch:partial:b59ae59a5870 (#21170) 2022-11-24 10:23:50 +00:00
editing.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
editorconfig.txt refactor(editorconfig)!: change editorconfig_enable to editorconfig 2023-01-07 08:19:37 -07:00
eval.txt feat(ui): add 'statuscolumn' option 2023-01-09 17:12:06 +00:00
filetype.txt vim-patch:76db9e076318 (#21013) 2022-11-10 09:05:25 +00:00
fold.txt vim-patch:86b4816766d9 (#21314) 2022-12-08 16:33:38 +01:00
ft_ada.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
ft_ps1.txt vim-patch:4d8f476176ea (#15612) 2021-09-10 08:48:27 +02:00
ft_raku.txt vim-patch:c51cf0329809 (#17530) 2022-02-27 11:56:30 +01:00
ft_rust.txt vim-patch:partial:6ebe4f970b8b (#20860) 2022-10-29 17:41:22 +02:00
ft_sql.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
gui.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
hebrew.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
help.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
helphelp.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
if_perl.txt vim-patch:8.1.0735: cannot handle binary data 2021-09-15 21:19:22 +01:00
if_pyth.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
if_ruby.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
indent.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
index.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
insert.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
intro.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
job_control.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
lsp-extension.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
lsp.txt feat(float): open float relative to mouse #21531 2023-01-10 02:22:41 -08:00
lua-guide.txt docs: fix typos (#21427) 2023-01-04 07:38:48 +08:00
lua.txt feat(lua)!: execute Lua with "nvim -l" 2023-01-05 17:10:02 +01:00
luaref.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
luvref.txt docs(luvref): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
map.txt vim-patch:1b5f03ec9c55 (#21715) 2023-01-10 11:02:00 +01:00
mbyte.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
message.txt docs: add missing docs from some Vim patches (#21296) 2022-12-05 21:09:31 +08:00
mlang.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
motion.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
news.txt feat(float): open float relative to mouse #21531 2023-01-10 02:22:41 -08:00
nvim_terminal_emulator.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
nvim.txt docs #20986 2022-12-11 18:41:26 -08:00
options.txt vim-patch:1b5f03ec9c55 (#21715) 2023-01-10 11:02:00 +01:00
pattern.txt vim-patch:8.2.4978: no error if engine selection atom is not at the start 2022-11-05 16:09:22 +08:00
pi_gzip.txt vim-patch:91f84f6e11cd 2018-10-29 09:55:07 +01:00
pi_health.txt docs: ":che" is ":checkhealth" #20147 2022-10-23 04:04:23 -07:00
pi_msgpack.txt fix(docs-html): keycodes, taglinks, column_heading #20498 2022-10-06 06:16:00 -07:00
pi_netrw.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
pi_paren.txt vim-patch:91f84f6e11cd 2018-10-29 09:55:07 +01:00
pi_spec.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
pi_tar.txt vim-patch:76db9e076318 (#21013) 2022-11-10 09:05:25 +00:00
pi_tutor.txt runtime: Include vim-tutor-mode 2015-08-15 15:25:30 -03:00
pi_zip.txt vim-patch:partial:6ebe4f970b8b (#20860) 2022-10-29 17:41:22 +02:00
provider.txt docs #20986 2022-12-11 18:41:26 -08:00
quickfix.txt docs: fix typos (#21427) 2023-01-04 07:38:48 +08:00
quickref.txt feat(ui): add 'statuscolumn' option 2023-01-09 17:12:06 +00:00
recover.txt refactor: remove cpo-& behavior (#17745) 2022-03-23 19:52:50 +08:00
remote_plugin.txt doc [ci skip] 2019-03-26 19:55:33 +01:00
remote.txt fix(tui): more work in the TUI 2022-12-31 13:25:26 +01:00
repeat.txt docs: fix typos 2022-11-02 21:45:26 +08:00
rileft.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
russian.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
scroll.txt feat: add 'mousescroll' option (#12355) 2022-07-06 19:34:24 +08:00
sign.txt vim-patch:partial:f1dcd14fc5d4 (#21602) 2023-01-01 15:00:39 +01:00
spell.txt vim-patch:76db9e076318 (#21013) 2022-11-10 09:05:25 +00:00
starting.txt feat(lua): store "nvim -l" scriptname in _G.arg[0] 2023-01-07 03:03:38 +01:00
support.txt docs(support): update tested versions (#21126) 2022-11-20 18:42:30 +08:00
syntax.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
tabpage.txt docs: fix typos (#20150) 2022-09-26 17:43:23 +08:00
tagsrch.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
term.txt docs: add language annotation to Nvim manual 2022-12-02 16:05:00 +01:00
testing.txt vim-patch:8.2.1420: test 49 is old style 2022-12-03 14:47:35 +08:00
tips.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00
treesitter.txt feat(treesitter): add 'lang' option to show_tree() (#21341) 2022-12-08 09:51:46 -07:00
uganda.txt vim-patch:partial:9da17d7c5707 2022-10-15 17:42:45 +08:00
ui.txt fix(tui): more work in the TUI 2022-12-31 13:25:26 +01:00
undo.txt vim-patch:b529cfbd04c0 (#19501) 2022-07-26 11:26:23 +02:00
userfunc.txt vim-patch:1b5f03ec9c55 (#21715) 2023-01-10 11:02:00 +01:00
usr_01.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
usr_02.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_03.txt vim-patch:76db9e076318 (#21013) 2022-11-10 09:05:25 +00:00
usr_04.txt docs: update explanation of Y to reflect new defaults 2022-02-24 18:13:44 +08:00
usr_05.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_06.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
usr_07.txt docs: update explanation of Y to reflect new defaults 2022-02-24 18:13:44 +08:00
usr_08.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_09.txt vim-patch:d2ea7cf10a4d #15571 2021-09-08 07:24:12 -07:00
usr_10.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_11.txt vim-patch:cb80aa2d53e5 2021-05-01 22:29:02 -04:00
usr_12.txt vim-patch:11e3c5ba8203 2021-05-02 12:53:49 -04:00
usr_20.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_21.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_22.txt docs: fix typos (#20150) 2022-09-26 17:43:23 +08:00
usr_23.txt vim-patch:4072ba571bab 2021-05-01 22:29:03 -04:00
usr_24.txt vim-patch:5666fcd0bd79 2021-04-27 09:21:33 -04:00
usr_25.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_26.txt vim-patch:d473c8c10126 2018-10-29 10:01:44 +01:00
usr_27.txt vim-patch:2547aa930b59 2021-04-29 09:27:19 -04:00
usr_28.txt vim-patch:d473c8c10126 2018-10-29 10:01:44 +01:00
usr_29.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_30.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_31.txt vim-patch:e7b1ea0276cc 2021-04-29 20:42:16 -04:00
usr_32.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_40.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_41.txt vim-patch:9.0.0916: getbufline() is inefficient for getting a single line 2022-11-22 07:21:26 +08:00
usr_42.txt docs(manual): fix treesitter parsing errors 2023-01-01 15:05:21 +01:00
usr_43.txt doc [ci skip] 2019-03-26 19:55:33 +01:00
usr_44.txt vim-patch:8024f9363683 2021-04-27 09:21:34 -04:00
usr_45.txt docs: fix/remove invalid URLs #20647 2022-10-14 08:01:13 -07:00
usr_toc.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
various.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
vi_diff.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
vim_diff.txt feat!: remove hardcopy 2023-01-03 10:07:43 +00:00
visual.txt vim-patch:76db9e076318 (#21013) 2022-11-10 09:05:25 +00:00
windows.txt docs: fix treesitter parsing errors 2023-01-01 15:05:13 +01:00