Skip to content

fix: compensate cached completion edits in the client encoding - #2651

Open
wrvsrx wants to merge 1 commit into
saghen:mainfrom
wrvsrx:fix/completion-edit-offset-encoding
Open

wrvsrx wants to merge 1 commit into
saghen:mainfrom
wrvsrx:fix/completion-edit-offset-encoding

Conversation

@wrvsrx

@wrvsrx wrvsrx commented Oct 3, 2026

Copy link
Copy Markdown

Accepting a cached UTF-16/UTF-32 completion after typing 三 can turn {三} into {三角洲, deleting the closing brace. Cursor compensation currently adds a byte delta to a range expressed in the client's encoding.

Preserve the request-time line alongside each item's position and compute the cursor delta in the client's encoding before converting the edit to UTF-8. This also handles deletions and IME replacements such as san → 三, where the byte column does not change. Preserve the original line through LSP cache reuse and strip the internal metadata before completionItem/resolve. Byte-based edits retain their existing path, and conversion still happens after compensation to avoid premature clamping on shortened lines.

Closes #2650.

Validation:

  • The issue's standalone reproduction fails on 8219b58 and passes with this change.
  • 54 deterministic regression cases exercise LSP response processing and edit application across UTF-8/UTF-16/UTF-32, CJK/emoji insertion and deletion, IME replacement, delayed responses, cache reuse, trailing text, and insert/replace/default edit ranges.
  • stylua --check . and git diff --check pass.

Run the regression cases with Neovim >= 0.11 and a sibling blink.lib checkout (tested with Neovim 0.12.5+editor-fixes.6 and blink.lib fd9a48e):

nvim --headless -u NONE --cmd 'set rtp+=.,../blink.lib' -l tests/text_edits.lua

The runner stubs only the LSP client; no language server, IME, snippet engine, or native fuzzy build is required. Local checks ran under a 512 MiB cgroup limit with swap disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cached UTF-16/UTF-32 completions delete trailing text after multibyte input

1 participant