fix_lsp_window shrinks LSP hover float: nvim_win_text_height already accounts for conceal_lines

Aperta Adatta ai principianti
#720 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 21 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
lua, markdown, neovim
Ambito
devtools

Direzione di ricerca

Inizia da lua/render-markdown/lib/compat.lua ed esamina M.fix_lsp_window, soprattutto il modo in cui utilizza nvim_win_text_height() e gli extmark conceal_lines. Controlla i tempi di rendering e il comportamento dell’altezza della finestra descritti nella segnalazione; la riproduzione suggerita usa Neovim con sqls che mostra al passaggio del mouse una tabella larga. Il lavoro è completato quando la finestra flottante dell’hover mostra la tabella renderizzata per intero all’altezza misurata, senza essere ridotta eccessivamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

LSP hover floats get shrunk to a few lines when the hover document contains a rendered markdown table, because compat.fix_lsp_window() subtracts one line per conceal_lines extmark from nvim_win_text_height(), which already returns the post-fold height.

With sqls hovering a 14-column table (18-line hover doc) the float ends up 112x3 instead of 112x19; the rendered table is unreadable (only the first rows visible) even though it was rendered correctly.

:RenderMarkdown disable gives the normal 112x18 float, so this is the plugin, not lspconfig/sqls.

To reproduce

Environment: NVIM v0.13.0-dev-2042+g74f3ce7970, render-markdown 8e87953 (2026-10-10), default opts (file_types = { 'markdown', 'codecompanion' }).

  1. sqlite db with e.g. CREATE TABLE big(a INT, b TEXT, c REAL, d BLOB, e INT, f TEXT, g INT, h TEXT, i INT, j TEXT, k INT, l TEXT, m INT, n TEXT);
  2. sqls connected, cursor on the table name, :lua vim.lsp.buf.hover()

The hover doc is:

# `big` table

| Name   | Type   | Primary key … | … |
| :--------------- | :--------------- | :---------------------- | … |
| `a` | `INT` | `NO` | `-` |  |
…
Actual
win 112x3   nvim_win_text_height = 18 at the time fix_lsp_window runs, 19 after the render settles
extmarks: 15 with conceal_lines, 17 rows of virt_lines (the drawn table)
height = 18 - 15 = 3
Expected

Float large enough for the rendered content (112x19).

Root cause

lua/render-markdown/lib/compat.lua:

-- account for conceal lines marks allowing us to reduce window height
local height = vim.api.nvim_win_text_height(win, {}).all
for _, extmark in ipairs(extmarks) do
    if extmark:get().opts.conceal_lines then
        height = height - 1
    end
end
if height < vim.api.nvim_win_get_height(win) then
    vim.api.nvim_win_set_height(win, height)
end

Verified on this Neovim build that nvim_win_text_height() already excludes lines collapsed by conceal_lines marks: for the same 18-line hover doc, a normal (non-float) markdown buffer after render shows the table on rows 3..20 (18 rows, checked with a pty + screenstring()), while nvim_win_text_height() reports 19 (18 rows + the trailing empty line). So the subtraction is a second deduction and the more conceal_lines marks a table produces, the smaller the float gets.

Note also that the function only ever shrinks (if height < ...), so nothing restores the height when the measurement is too small.

Suggested fix

Trust the measurement, and re-measure after the marks have settled:

function M.fix_lsp_window(buf, win, extmarks)
    local has_lsp = pcall(vim.api.nvim_win_get_var, win, 'lsp_floating_bufnr')
    if not has_lsp then
        return
    end
    local env = require('render-markdown.lib.env')
    local str = require('render-markdown.lib.str')
    -- width handling unchanged
    local width = 0
    for _, line in ipairs(vim.api.nvim_buf_get_lines(buf, 0, -1, false)) do
        width = math.max(width, str.width(line))
    end
    if width <= vim.api.nvim_win_get_width(win) then
        env.win.set(win, 'wrap', false)
    end
    vim.schedule(function()
        if not vim.api.nvim_win_is_valid(win) then
            return
        end
        local height = vim.api.nvim_win_text_height(win, {}).all
        if height ~= vim.api.nvim_win_get_height(win) then
            pcall(vim.api.nvim_win_set_height, win, height)
        end
    end)
end

With this patch the same hover shows 112x19 with the whole table visible. Small terminals stay fine: nvim_win_set_height is clamped by Neovim to the available rows (16-line terminal -> height 14, scrolling inside the float still works).

Checklist
  • I have read the CONTRIBUTING guide
  • I have searched existing issues
Lingua principale
Lua
Stelle
5.2k
Fork
155
Merge medio
5g 10h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MeanderingProgrammer/render-markdown.nvim

Tutte le issue di MeanderingProgrammer/render-markdown.nvim

Issue simili

Altre issue su Lua

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.