Skip to content
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

feature: resize LSP hover windows based on concealed lines #384

Closed
2 tasks done
ValdezFOmar opened this issue Mar 30, 2025 · 1 comment
Closed
2 tasks done

feature: resize LSP hover windows based on concealed lines #384

ValdezFOmar opened this issue Mar 30, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@ValdezFOmar
Copy link

Neovim version (nvim -v)

0.11.0

Neovim distribution

N/A

Operating system

Linux

Terminal emulator / GUI

Kitty

Describe the bug

I've noticed that even though the backticks for code blocks are concealed, there is still an additional two lines at the end of hover windows:

Without this plugin:

Image

With this plugin:

Image

Expected behavior

The hover window should not have this extra lines, just like the first capture.

Healthcheck output

==============================================================================
render-markdown:                     require("render-markdown.health").check()

render-markdown.nvim [version] ~
- OK plugin 8.1.22
- OK neovim >= 0.10

render-markdown.nvim [configuration] ~
- OK valid

render-markdown.nvim [treesitter] ~
- OK markdown: parser installed
- OK markdown_inline: parser installed
- WARNING latex: parser not installed
  - ADVICE:
    - Disable latex support to avoid this warning
    - require('render-markdown').setup({ { latex = { enabled = false } })
- WARNING html: parser not installed
  - ADVICE:
    - Disable html support to avoid this warning
    - require('render-markdown').setup({ { html = { enabled = false } })
- OK markdown: highlight enabled

render-markdown.nvim [icons] ~
- WARNING none installed

render-markdown.nvim [executables] ~
- WARNING latex2text: not installed
  - ADVICE:
    - Disable latex support to avoid this warning
    - require('render-markdown').setup({ { latex = { enabled = false } })

render-markdown.nvim [conflicts] ~
- OK headlines: not installed
- OK markview: not installed
- OK obsidian: not installed

Plugin configuration

{                                                                                                                                                                           
  overrides = {                                                                                                                                                             
    buftype = {                                                                                                                                                             
      nofile = {                                                                                                                                                            
        code = {                                                                                                                                                            
          border = "hide",                                                                                                                                                  
          style = "normal"                                                                                                                                                  
        }                                                                                                                                                                   
      }                                                                                                                                                                     
    }                                                                                                                                                                       
  }                                                                                                                                                                         
}

Plugin error log

N/A

Confirmations

  • I have updated this plugin to the latest version using my plugin manager
  • I have provided the text contained in all screenshots as raw text in this issue. This means if there is a screenshot below it is the copy pasted contents of the file in the screenshot. I understand that my issue will be closed if I have not.

Additional information

I can reproduce this behaviour with the following steps:

git clone https://github.com/MeanderingProgrammer/render-markdown.nvim.git
git clone https://github.com/nvim-treesitter/nvim-treesitter.git
./nvim-linux-x86_64.appimage --clean -u init.lua a.lua

nvim-linux-x86_64.appimage is the official appimage build.

a.lua

function f() end

init.lua:

vim.lsp.config.luals = {
    cmd = { 'lua-language-server' },
    filetypes = { 'lua' },
}

vim.lsp.enable('luals')

vim.o.winborder = 'rounded'

vim.opt.rtp:prepend './nvim-treesitter'

require('nvim-treesitter.configs').setup({
    ensure_installed = {
        'markdown',
        'markdown_inline',
    },
    highlight = { enable = true },
})

vim.opt.rtp:prepend './render-markdown.nvim'

require('render-markdown').setup({
    overrides = {
        buftype = {
            nofile = {
                code = {
                    style = 'normal',
                    border = 'hide',
                },
            },
        },
    },
})
@ValdezFOmar ValdezFOmar added the bug Something isn't working label Mar 30, 2025
MeanderingProgrammer added a commit that referenced this issue Mar 31, 2025
## Details

Request: #384

Since the `conceal_lines` directive is enabled in the default highlights
neovim actively handles reducing the height of LSP hover doc windows to
remove unnecessary vertical space.

This happens here:

https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/util.lua#L1657-L1661

```lua
-- Reduce window height if TS highlighter conceals code block backticks.
local conceal_height = api.nvim_win_text_height(floating_winnr, {}).all
if conceal_height < api.nvim_win_get_height(floating_winnr) then
    api.nvim_win_set_height(floating_winnr, conceal_height)
end
```

Since our decorations are added separately from highlights and behave
very differently there would be no way for neovim to practically pickup
highlights added by this plugin.

To get around this we essentially re-implement this same logic as part
of this plugin. After the first load of a buffer when we are just about
to add our `extmark`s check if the buffer is related to LSP hover docs
and if it is adjust the height taking into account the concealed lines
that will be added (removed) by this plugin.

I don't see this as a bug, since adjusting windows to fit their content
is not something this plugin ever intended to do and supporting every
feature in neovim is not the goal. However, since this is for a very
specific scenario and the implementation is straightforward I've added
it.

> [!CAUTION]
> We'll likely need to update how we identify LSP hover doc buffers over
> time since the current approach is tied to internal undocumented behavior.

> [!NOTE]
> See if we can add a marker on LSP buffers that is a documented feature
> others can rely on, if such a thing doesn't already exist.
@MeanderingProgrammer MeanderingProgrammer added enhancement New feature or request and removed bug Something isn't working labels Mar 31, 2025
@MeanderingProgrammer MeanderingProgrammer changed the title bug: extra lines at the bottom of LSP hover windows feature: support resizing LSP hover windows based on concealed lines Mar 31, 2025
@MeanderingProgrammer MeanderingProgrammer changed the title feature: support resizing LSP hover windows based on concealed lines feature: resize LSP hover windows based on concealed lines Mar 31, 2025
@MeanderingProgrammer
Copy link
Owner

Added support to resize LSP windows here: 17b839b

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