lewis6991 / hover.nvim Goto Github PK
View Code? Open in Web Editor NEWHover plugin framework for Neovim
License: MIT License
Hover plugin framework for Neovim
License: MIT License
Trying to get started with hover, and would like to use the github providers.
But my system has no gh
command, and the hover docs don't indicate what upstream is for that; help?
Please advice
The coroutine failed
with this message: cannot resume dead coroutine
Error executing vim.schedule lua callback: ...im/site/pack/packer/start/hover.nvim/lua/hover/async.lua:36
Thanks
Sometime the hover docs is long and I need to jump into the hover window to scroll the content by clikc K
again, which binding to require("hover").hover()
. But after some updates, I cannot do this in the same way.
As far as I can tell theres no public method to close the currently open hover window. This would be great so that I can have normal hover() on CursorHold and then a bind to close that if its in the way, or to close and then run hover_select if I don't want to use the default provider. Not sure how to do this currently.
when I use keybinding from lspconfig with noice, it gives a nice (or should I noice π ) popup to tell you if when there's no hover information to pop up. On the contrast with this plugin, it seems to give no feedback at all, so maybe that could be improved in the some form that maybe as simple as printing message.
https://api.dictionaryapi.dev times out. Looks like it is just a frontend for a Google API, which may either be rate limited, or removed.
curl -v https://api.dictionaryapi.dev
* Trying 99.83.154.118:443...
... hangs ...
A bit of an inverse of this issue: #19
I updated the plugin and calling hover
multiple times no longer 'jumps' the cursor into the window. Now instead, I have to use window functions in nvim to get there. I quite liked the "press K twice to jump inside" feature.
:)
Thanks! <3
As you can see in the attached image, part of the floating window is transparent when I don't want it to be. The problem is I can't tell which highlight group this isβso far as I can tell, it's not any of the TabLine groups, which other parts of the floating window depend on, and not any of vim's default Float highlight groups, like Float, NormalFloat, FloatTitle, etc.
I'm hoping someone knows what the highlight is (my hope would be not Normal, so it can be customized separately from the editor), and it would be nice if customizing this and other highlights was possible from the config
In help files K
can be used to jump to topic under the cursor. Suggested mapping overrides it. Neovim hover handler (vim.lsp.buf.hover
) which I think many users have also mapped to K
through on_attach
function will not have that issue as it will not be mapped for help files. It makes sense to create global mapping for hover.nvim as it's useful beyond files with LSP attached. I have came up with following guard, not sure if it's the right way of doing it, but perhaps you can think of better way and update readme accordingly?
vim.keymap.set('n', 'K', function()
if vim.bo.filetype ~= 'help' then
require('hover').hover()
end
vim.api.nvim_feedkeys('K', 'ni', true)
end)
Sometimes I have a one-off hover action I'd like to run without keeping a provider around, or really even encapsulating the 'get some text' portion of the operation in a provider.
It would be really convenient to use this repo's logic for showing text in preview windows without needing a provider.
My fork has a hack to get the behavior I want by allowing you to directly run a provider, but there's almost certainly a better way. I'm using this in my config to run a pass-through provider that has no logic for getting text.
A better solution than mine would be to separate the concept of showing text in a hover window from the concept of getting the text.
Something like:
require('hover.actions').show_text(text_record)
where the text record would have the info currently stored on providers (bufnr, focusable, etc.)
E5108: Error executing lua: .../.local/share/nvim/lazy/hover.nvim/lua/hover/actions.lua:277: attempt to index field 'uv' (a nil value)
Is there a missing dependency, etc?
Installed it, and nothing on mouse hover :(
hover
and hover_select
should not assume they are using the current keyboard cursor position as the "hover" position.
Neovim now supports a trivial way to know the mouse cursor position (I'm using alacritty and gnome-terminal):
Currently I'm using this:
return {
"lewis6991/hover.nvim",
config = function()
require("hover").setup {
init = function()
-- Require providers
require("hover.providers.lsp")
-- require('hover.providers.gh')
-- require('hover.providers.gh_user')
-- require('hover.providers.jira')
-- require('hover.providers.man')
-- require('hover.providers.dictionary')
end,
preview_opts = {
border = nil
},
-- Whether the contents of a currently open hover window should be moved
-- to a :h preview-window when pressing the hover keymap.
preview_window = false,
title = true
}
local hover_time = 500
local hover_timer = nil
local mouse_position = 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()
mouse_position = vim.fn.getmousepos()
hover_timer = nil
require('notify').notify(vim.inspect(mouse_position))
require("hover").hover()
end, hover_time)
return '<MouseMove>'
end, { expr = true })
end
Which ends up lookin like this:
ctrl
key to show where the mouse cursor is.Some hover providers (like rust-analyzer) allow clients to have certain actions embedded in the hover, which would need providers to be able to modify the buffer and window (set keymaps, change window options) etc. So, I think allowing providers the ability to do that is a good idea.
Allow providers to define a on_render
function which is called when the hover is rendered.
diff --git a/lua/hover/actions.lua b/lua/hover/actions.lua
index 65d8cc5..321c269 100644
--- a/lua/hover/actions.lua
+++ b/lua/hover/actions.lua
@@ -66,11 +66,13 @@ local function focus_or_close_hover()
end
local function show_hover(provider_id, config, result, opts)
- local _, winnr = util.open_floating_preview(result.lines, result.filetype, opts)
+ local bufnr, winnr = util.open_floating_preview(result.lines, result.filetype, opts)
if config.title then
add_title(winnr, provider_id)
end
+
+ return bufnr, winnr
end
-- Must be called in async context
@@ -89,7 +91,10 @@ local function run_provider(provider)
local result = provider.execute()
if result then
async.scheduler()
- show_hover(provider.id, config, result, opts)
+ local bufnr, winnr = show_hover(provider.id, config, result, opts)
+ if provider.on_render then
+ provider.on_render(bufnr, winnr)
+ end
return true
end
---@diagnostic disable: missing-parameter, param-type-mismatch
local M = {}
M._state = { commands = nil }
local function execute_rust_analyzer_command(action, ctx)
local fn = vim.lsp.commands[action.command]
if fn then
fn(action, ctx)
end
end
-- run the command under the cursor, if the thing under the cursor is not the
-- command then do nothing
local function run_command(ctx)
local winnr = vim.api.nvim_get_current_win()
local line = vim.api.nvim_win_get_cursor(winnr)[1]
if line > #M._state.commands then
return
end
local action = M._state.commands[line]
vim.api.nvim_win_close(winnr, true)
execute_rust_analyzer_command(action, ctx)
end
local function parse_commands()
local prompt = {}
for i, value in ipairs(M._state.commands) do
if value.command == "rust-analyzer.gotoLocation" then
table.insert(
prompt,
string.format("%d. Go to %s (%s)", i, value.title, value.tooltip)
)
elseif value.command == "rust-analyzer.showReferences" then
table.insert(prompt, string.format("%d. %s", i, "Go to " .. value.title))
else
table.insert(prompt, string.format("%d. %s", i, value.title))
end
end
return prompt
end
require("hover").register({
name = "Rust Hover Actions",
enabled = function()
return true
end,
execute = function(done)
local util = require("vim.lsp.util")
local params = util.make_position_params()
vim.lsp.buf_request(
0,
"textDocument/hover",
params,
function(_, result, ctx)
if not result or not result.contents then
done()
return
end
M._state.commands = nil
local lines = util.convert_input_to_markdown_lines(result.contents)
if result.actions then
M._state.commands = result.actions[1].commands
local prompt = parse_commands()
local l = {}
for _, value in ipairs(prompt) do
table.insert(l, value)
end
lines = vim.list_extend(l, lines)
end
lines = util.trim_empty_lines(lines)
M._state.ctx = ctx
if vim.tbl_isempty(lines) then
done()
return
end
done({ lines = lines, filetype = "markdown" })
end
)
end,
on_render = function(bufnr, winnr)
if M._state.commands == nil then
return
end
-- makes more sense in a dropdown-ish ui
vim.api.nvim_win_set_option(winnr, "cursorline", true)
-- run the command under the cursor
vim.keymap.set("n", "<CR>", function()
run_command(M._state.ctx)
end, { buffer = bufnr, noremap = true, silent = true })
end,
})
return M
Basically, I just don't want to see this text when using hover.
My use case, I have hover set to auto trigger on the :CursorHold
event. Its super slick but it also means that it will attempt to run hover when there is no LSP running. Which should be fine if I have a way to tell hover to not print complaints to neovim.
Looking at the source it doesn't appear there is a way to do this currently
Given that hover does allow a configuration to be passed in on setup, what's your thoughts on adding an opt in configuration that tells hover to not complain about no providers found?
I am not quite sure the best way to approach this otherwise (without undoing my current work flow which is fine I guess).
Edit: On second thought, I might be able to work around this by only triggering hover if an LSP is available for the current buffer, though I don't know a good way to establish that
Disregard the edit, this behavior also happens when activating on empty lines in a buffer that has an LSP attached
With the normal lsp hover, you could use vim.lsp.buf.hover(nil, { focus = false, focusable = false })
to prevent the cursor from entering the window, but that same thing doesn't seem to work, and I didn't see anything in the readme or anywhere else to indicate the presence of something similar.
Me again! This is sort of in the same vein as #5 where (after 5 seconds of thinking about it) I believe this would only apply to the preview window use case. I tried to get a similar "send to preview window" functionality submitted into nvim-cmp, but at the direction of hrsh7th we decided it was out of scope. I'd be interested to know if you feel like this could have a place in this plugin? I'm not entirely sure how the integration would work as nvim-cmp manages the floating window itself, but I'm sure something could be worked out on both sides to enable this.
I currently have a textDocument/hover handler that looks like this:
function M.hover()
if vim.bo.filetype == "rust" then
require("rust-tools.hover_actions").hover_actions()
elseif vim.fn.expand("%:t", false, false) == "Cargo.toml" then
require("crates").show_popup()
else
require("hover").hover()
require("autocommands")("DisableCursorHold")(function(autocmd)
vim.opt.eventignore:append("CursorHold")
autocmd(
{ "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" },
{ pattern = "<buffer>", once = true, desc = "Prevent floating diagnostic from opening while hover is opened." },
function()
vim.opt.eventignore:remove("CursorHold")
end
)
end)
end
end
And wanted to see about making both the rust-tools.nvim and crates.nvim actions be hover.nvim
providers. However, both of these manage their own popup windows.
Any ideas here, or should I continue with this approach?
Thanks
Hi, when I use the hover_select
function, I get the following error:
E5108: Error executing lua: ...l/share/nvim/lazy/hover.nvim/lua/hover/providers/man.lua:10: Invalid 'name': Expected Lua string
stack traceback:
[C]: in function '__index'
...l/share/nvim/lazy/hover.nvim/lua/hover/providers/man.lua:10: in function 'enabled'
.../.local/share/nvim/lazy/hover.nvim/lua/hover/actions.lua:19: in function <.../.local/share/nvim/lazy/hover.nvim/lua/hover/actions.lua:18>
vim/shared.lua: in function 'tbl_filter'
.../.local/share/nvim/lazy/hover.nvim/lua/hover/actions.lua:254: in function 'hover_select'
...moschcau/.local/share/nvim/lazy/hover.nvim/lua/hover.lua:15: in function <...moschcau/.local/share/nvim/lazy/hover.nvim/lua/hover.lua:14>
I also noticed that the lua LSP is complaining about my calls of hover()
and hover_select()
now expecting one argument (the options table) and receiving none. Not sure if this needs to be changed, because the given configuration examples of this plugin also do not pass any arguments to them. (To my knowledge rhs
functions in vim.keymap.set
do not receive any arguments.)
Hello! I personally prefer to send the contents of a floating window to a preview window, so that I can keep it open for a little while longer (and to get more screen real estate than a floating window). Do you think it'd make sense to include this an option in this plugin? I'd be happy to send a PR for it in that case. To give some idea how I'd implement it - I've currently accomplished this in my own config like so (this was prior to trying hover.nvim), it's a bit messy but it works.
Hello,
Would you consider a provider for LSP warnings and LSP errors?
I think the provider should be straightforward (although I have little knowledge about this). However, for it to play nicely with the existing LSP provider, one would probably need some form of priority among providers, or a way to display multiple hover windows (more complicated).
Hiya π
Today after updating the plugin to bb3dc1a I noticed that require("hover").hover()
yields a result for $current_line + 1
instead of $current_line
:
Here is my lazy.nvim package def and config for hover.nvim
:
{
"lewis6991/hover.nvim",
event = "VeryLazy",
config = function()
require("hover").setup({
init = function()
require("hover.providers.lsp")
require("hover.providers.man")
require("hover.providers.gh")
end,
preview_opts = {
border = nil,
},
title = true,
})
end,
}
...and I have a normal mode keymap for K
which just calls require("hover").hover()
. I can also reproduce the problem by running this without the keymap (e.g. :lua require("hover").hover()
).
All of my other LSP mappings (definition, declaration, code-action, etc all work normally) are working fine.
Reverting to 24369e8 fixes the problem, so I suspect that there might be some unintentional breakage from these two recent commits
I'll try to writeup a minimal repro config when time permits. If there's anything else I can do to help troubleshoot in the meantime, lemme know!
In lua/hover/util.lua, there is a check to see if there is a width, and if not do some things to define one.
Lines 202 to 208 in a173256
I'm currently using Hover with nvim-jdtls.
On java files, on symbols with no return from lsp, width is still at 0, resulting in an error every time I use K with the following message:
Error executing vim.schedule lua callback: ....hover.nvim/lua/hover/async.lua:37: The coroutine failed with this message: .../hover.nvim/lua/hover/util.lua:316: 'width' key must be a positive Integer
vim.lsp.buf.hover() just says 'no information available' with no errors
how to change the highlight?
An action to switch between source in the hover window would be nice alternative for hover_select
For example like n
and p
for next/previous source.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.