Skip to content

Commit

Permalink
feat(lsp): <Plug> mapping for hover actions (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Sep 20, 2024
1 parent 05c7010 commit b52bbc4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@ vim.keymap.set(
By default, this plugin replaces Neovim's built-in hover handler with hover
actions, so you can also use `vim.lsp.buf.hover()`.

You can invoke a hover action by switching to the hover window and entering `<CR>`
on the respective line, or with a keymap for the `<Plug>RustHoverAction` mapping,
which accepts a `<count>` prefix as the (1-based) index of the hover action to invoke.

For example, if you set the following keymap:

```lua
vim.keymap.set('n', '<space>a', '<Plug>RustHoverAction')
```

you can invoke the third hover action with `3<space>a`.

![](https://github.com/mrcjkb/rustaceanvim/assets/12857160/c7b6c730-4439-47b0-9a75-7ea4e6831f7a)

</details>
Expand Down
13 changes: 8 additions & 5 deletions lua/rustaceanvim/hover_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ end
-- run the command under the cursor, if the thing under the cursor is not the
-- command then do nothing
---@param ctx table
local function run_command(ctx)
local winnr = vim.api.nvim_get_current_win()
local line = vim.api.nvim_win_get_cursor(winnr)[1]

---@param line integer
local function run_command(ctx, line)
if line > #_state.commands then
return
end
Expand Down Expand Up @@ -132,8 +130,13 @@ function M.handler(_, result, ctx)

-- run the command under the cursor
vim.keymap.set('n', '<CR>', function()
run_command(ctx)
local line = vim.api.nvim_win_get_cursor(winnr)[1]
run_command(ctx, line)
end, { buffer = bufnr, noremap = true, silent = true })
vim.keymap.set('n', '<Plug>RustHoverAction', function()
local line = math.max(vim.v.count, 1)
run_command(ctx, line)
end, { buffer = vim.api.nvim_get_current_buf(), noremap = true, silent = true })
end

local rl = require('rustaceanvim.rust_analyzer')
Expand Down

0 comments on commit b52bbc4

Please sign in to comment.