Skip to content

feature: allow to customize hover height #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OliverGuy opened this issue Apr 8, 2025 · 2 comments
Closed

feature: allow to customize hover height #396

OliverGuy opened this issue Apr 8, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@OliverGuy
Copy link

OliverGuy commented Apr 8, 2025

Is your feature request related to a problem? Please describe.

First of all, thanks for the awesome plugin!

The addition of LSP hover resizing in 17b839b has introduced an off-by-1 error in the size of hovercraft.nvim, producing rather frustrating hovers on small LSP outputs:

Image

This seems to be due to the "tab" line in hovercraft making the actual rendered text take one extra line.

For comparison, here's the same output before the commit:

Image

Describe the solution you'd like

Ideally, allow for a callback to either modify that height or just execute arbitrary lua code given the number of rendered lines, e.g.:

setup {
  on = {
    hover_init = function(rendered) end,
  }
}

Describe alternatives you've considered

  • allowing to disable the option entirely
  • adding an offset: less generic approach

Additional information

I'd be willing to contribute a PR :)

@OliverGuy OliverGuy added the enhancement New feature or request label Apr 8, 2025
@OliverGuy OliverGuy changed the title feature: option to offset hover height feature: allow to customize hover height Apr 9, 2025
MeanderingProgrammer added a commit that referenced this issue Apr 12, 2025
…r the first time

## Details

Request: #396

Adds `on.initial` function which is called only once for a buffer before
marks are added on the first render cycle.

Context is provided with the buffer and window id. Modify other
callbacks called within the main UI loop to also take a window id,
meaning `on.render` & `on.clear` are both provided with `win`, since it
is a context table this breaks no existing usage.

This can be used to make changes to LSP hover docs based on the users
knowledge of how their plugins work but identifying buffers as LSP hover
docs and applying changes is left up to the user.
@MeanderingProgrammer
Copy link
Owner

Added some support for this here: 91d40c2

Is under a new on.initial option which is provided with the buffer and window ids, the only thing special about it is it gets called only once before the first time marks are added to the buffer.

You can use it to increase the height of a buffer by one using:

require('render-markdown').setup({
    on = {
        initial = function(ctx)
            local height = vim.api.nvim_win_text_height(ctx.win, {}).all
            vim.api.nvim_win_set_height(ctx.win, height + 1)
        end,
    },
})

Of course this would apply to all buffers, so you'll need some way to gate it to LSP hover docs specifically. I don't provide a way of doing this since the way this plugin does this relies on undocumented behavior and I don't want others relying on it directly or being surprised if / when it breaks. Welcome to look through this plugin's source code for that if you like, but that's up to you.

@OliverGuy
Copy link
Author

Much appreciated, thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants