Skip to content

Commit b52bbc4

Browse files
authored
feat(lsp): <Plug> mapping for hover actions (#510)
1 parent 05c7010 commit b52bbc4

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,18 @@ vim.keymap.set(
403403
By default, this plugin replaces Neovim's built-in hover handler with hover
404404
actions, so you can also use `vim.lsp.buf.hover()`.
405405

406+
You can invoke a hover action by switching to the hover window and entering `<CR>`
407+
on the respective line, or with a keymap for the `<Plug>RustHoverAction` mapping,
408+
which accepts a `<count>` prefix as the (1-based) index of the hover action to invoke.
409+
410+
For example, if you set the following keymap:
411+
412+
```lua
413+
vim.keymap.set('n', '<space>a', '<Plug>RustHoverAction')
414+
```
415+
416+
you can invoke the third hover action with `3<space>a`.
417+
406418
![](https://github.com/mrcjkb/rustaceanvim/assets/12857160/c7b6c730-4439-47b0-9a75-7ea4e6831f7a)
407419

408420
</details>

lua/rustaceanvim/hover_actions.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ end
3030
-- run the command under the cursor, if the thing under the cursor is not the
3131
-- command then do nothing
3232
---@param ctx table
33-
local function run_command(ctx)
34-
local winnr = vim.api.nvim_get_current_win()
35-
local line = vim.api.nvim_win_get_cursor(winnr)[1]
36-
33+
---@param line integer
34+
local function run_command(ctx, line)
3735
if line > #_state.commands then
3836
return
3937
end
@@ -132,8 +130,13 @@ function M.handler(_, result, ctx)
132130

133131
-- run the command under the cursor
134132
vim.keymap.set('n', '<CR>', function()
135-
run_command(ctx)
133+
local line = vim.api.nvim_win_get_cursor(winnr)[1]
134+
run_command(ctx, line)
136135
end, { buffer = bufnr, noremap = true, silent = true })
136+
vim.keymap.set('n', '<Plug>RustHoverAction', function()
137+
local line = math.max(vim.v.count, 1)
138+
run_command(ctx, line)
139+
end, { buffer = vim.api.nvim_get_current_buf(), noremap = true, silent = true })
137140
end
138141

139142
local rl = require('rustaceanvim.rust_analyzer')

0 commit comments

Comments
 (0)