Code Monkey home page Code Monkey logo

hover.nvim's People

Contributors

alfaix avatar b0o avatar beauwilliams avatar deptno avatar flrgh avatar green0wl avatar halftan avatar jolan78 avatar laytan avatar lewis6991 avatar pinbraerts avatar ravibrock avatar robertoesteves13 avatar wangl-cc avatar williamboman avatar wookayin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hover.nvim's Issues

cannot resume dead coroutine

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

unable to jump into hover window again

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.

function to close open hover window

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.

Feedback when no hover is found

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.

Allow cursor entering hover window with multiple calls in a row

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

Identifying/Customizing Highlight Group

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
Screenshot 2023-09-18 at 1 40 16 PM

Suggested mapping overrides help's K

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)

[feature] Expose `show_text` or similar without requiring a provider

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.)

Errors with Lazy/nVim v0.9.4

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?

Support position other than keyboard cursor position

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:

Screencast.from.2023-02-27.12-08-24.webm
  • The screenrecording in gnome-shell doesn't capture the mousecursor for somereason that's why i'm using the a11y ping thing... everytime you see a blip i'm hittin the ctrl key to show where the mouse cursor is.
  • when the mouse stops moving, you'll see a notification popup

Proposal: Allow provider to mess with the hover buffer/window

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.

Proposed Change

Allow providers to define a on_render function which is called when the hover is rendered.

Example Implementation

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

Example provider implementation (rust-tools hover actions)

---@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

Make hover _not_ complain about not finding providers?

Basically, I just don't want to see this text when using hover.
image

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

[Feature] Add nvim-cmp as provider

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.

Rust and Cargo.toml providers?

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

Lua error in `man` provider when using `hover_select`

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.)

[Feature] Transform floating window to preview window

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.

LSP error and warnings provider

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).

hover.hover() position is off by 1

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:

Screenshot from 2023-11-11 13-49-54

Screenshot from 2023-11-11 13-50-05

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!

Check on width for nvim_open_win failing

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.

if not width then
width = 0
for i, line in ipairs(contents) do
line_widths[i] = vim.fn.strdisplaywidth(line)
width = math.max(line_widths[i], width)
end
end

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

Switch source on hover window

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.