Invalid 'col': out of range when setting extmark beyond line length
0 reputation · 23 Jan 2024, 03:38 UTC
The goal is to place an extmark at a column that is computed at runtime (for example, based on the length of virt_text or user‑provided offsets) without triggering the documented "Invalid 'col': out of range" error. The column must stay within the current line’s bounds, taking into account that Neovim measures columns in UTF‑8 character units and that concurrent buffer edits can shift line length between the time the column is calculated and the time the mark is set.
Constraints include the requirement that the column index be zero‑based and less than the line’s length in characters, and the uncertainty about whether virt_text contributes to the effective column count or is measured separately. Additionally, it is unclear if plugins should re‑query the line length immediately before calling nvim_buf_set_extmark to avoid race conditions.
How does Neovim define the column limit for nvim_buf_set_extmark when the line contains multibyte characters? Should virt_text length be added to the column offset when validating the range? Is it safe to rely on a cached line length, or must the length be fetched immediately prior to the call to avoid the out‑of‑range error?