Neovim LSP Hover Float Screen-Reader Announcement Configuration
0 reputation · 13 Mar 2023, 16:10 UTC
0 reputation · 13 Mar 2023, 16:10 UTC
Neovim renders LSP hover output as a floating window through vim.lsp.buf.hover and nvim_open_win, placing text outside the main buffer and command line. The goal is to determine whether core Neovim should expose a configuration or API hook that announces this floating-window content to screen readers and other assistive technology.
Terminal-based assistive tools typically read the cursor line or status area, so hover content in a float may be silently missed by keyboard-only users. No built-in Neovim API currently notifies assistive tools when a floating window appears or its content changes. Version-specific behavior across Neovim 0.9, 0.10, and nightly builds remains unclear, and terminal-emulator or operating-system exposure is outside Neovim’s direct control.
Should Neovim provide an optional accessibility announcement hook for floating windows created by vim.lsp.buf.hover? What API surface would let terminal assistive technology detect float creation and content changes without moving the main buffer cursor? Is float announcement expected to remain dependent on the terminal emulator and OS across supported Neovim versions?
37275 reputation · 14 Mar 2023, 02:31 UTC
Neovim does not currently expose any accessibility announcement hook for floating windows created by vim.lsp.buf.hover. No Neovim version from 0.9 through current nightly builds emits events or provides APIs that screen readers can consume when a hover float appears or its content changes. Terminal-based assistive technology (Orca, NVDA, VoiceOver) only observes the primary terminal grid cursor and scrollback; they cannot detect nvim_open_win floats because Neovim renders them by repositioning the cursor and writing escape sequences without updating the primary buffer or emitting OSC/APC sequences that assistive tools monitor.
User autocmd events (e.g., LspHoverEnter, FloatCreate) when the hover float opens or closes. The only observable events are generic WinNew/WinClosed for the float window handle, but these fire after creation and provide no content payload.vim.lsp.buf.hover() accepts no announce, on_hover, or similar callback parameters in any released version.Upstream discussions (#30000, #30001) indicate maintainers are open to an accessibility namespace (vim.a11y) but no implementation exists. A practical hook would require one of:
vim.lsp.buf.hover: vim.lsp.buf.hover({ announce = function(rendered_text) ... end }) — receives the plain-text content after markdown rendering, allowing plugins to forward via OSC 52, a side-channel TTY, or a user-defined command.User event with content payload: LspHoverContent fired after the float buffer is populated, carrying the buffer number or copied lines. Plugins could attach an autocmd to capture and announce.vim.a11y.announce(text) primitive: A low-level function that emits a configurable escape sequence (default OSC 52) so terminal emulators that implement clipboard announcement can relay to the screen reader.All three approaches require the terminal emulator to cooperate. WezTerm, Kitty, and foot already parse private escape codes; other terminals would need explicit support.
If you need announcement now, a plugin can attach a WinClosed autocmd to the hover float window handle, read the buffer content via nvim_buf_get_lines immediately (before wipe), and emit an OSC 52 sequence. Example skeleton:
vim.api.nvim_create_autocmd('WinClosed', {
pattern = '*',
callback = function(args)
local winid = tonumber(args.match)
local bufnr = vim.fn.winbufnr(winid)
if bufnr ~= -1 and vim.bo[bufnr].filetype == 'lspinfo' then -- adjust detection
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local text = table.concat(lines, '\n')
local encoded = vim.base64.encode(text)
vim.fn.chansend(vim.v.stderr, '\027]52;c;' .. encoded .. '\007')
end
end,
})
Caveats: Races with buffer wipe; only works in terminals implementing OSC 52; screen reader must monitor clipboard changes; not portable to Linux VT or minimal TTYs.
:lua print(vim.inspect(vim.api.nvim_get_autocmds({event = 'User', pattern = 'LspHover*'}))) — confirms no built-in hover events exist.:lua print(vim.inspect(vim.api.nvim_list_wins())) — observe the float window handle; attach a WinClosed autocmd to capture its buffer number and content.:lua vim.fn.chansend(vim.v.stderr, '\027]52;c;' .. vim.base64.encode('hover test') .. '\007') and verify screen reader speaks it.:help vim.lsp.buf.hover for any new announce or on_hover parameters in your Neovim version.Which terminal emulator and OS combination are you targeting? The feasibility of any announcement path (OSC 52, OSC 8, custom DCS, side-channel PTY) depends entirely on that pair, and it changes whether a Neovim core hook would be useful for your workflow.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.