Skip to content

fix(picker): avoid crash on multi-byte lines in resolve_loc#2789

Open
lasorda wants to merge 1 commit intofolke:mainfrom
lasorda:fix/picker-multibyte-byteindex
Open

fix(picker): avoid crash on multi-byte lines in resolve_loc#2789
lasorda wants to merge 1 commit intofolke:mainfrom
lasorda:fix/picker-multibyte-byteindex

Conversation

@lasorda
Copy link
Copy Markdown

@lasorda lasorda commented Mar 30, 2026

Problem

When using Snacks.picker.lsp_symbols() on files containing multi-byte characters (e.g. Chinese comments in .proto files), navigating the picker results with <C-j>/<C-k> crashes with:

E5108: Lua: vim/_core/editor.lua:0: index out of range
  vim/_core/editor.lua: in function 'str_byteindex'
  .../snacks.nvim/lua/snacks/picker/util/init.lua:402: in function 'resolve'

Root Cause

In resolve_loc(), M.str_byteindex is called without the strict_indexing parameter:

local col = line and M.str_byteindex(line, pos.character, item.loc.encoding) or pos.character

When an LSP server (e.g. clangd) returns a range.end.character that exceeds the UTF-16 length of a line — which is common with CJK/multi-byte characters — vim.str_byteindex in Neovim 0.10+ raises "index out of range" because strict_indexing defaults to true.

The fix in #2389 (commit 46917d0) correctly added the strict_indexing parameter to M.str_byteindex, but the call site in resolve_loc never passes it.

Fix

Pass strict_indexing=false so out-of-range indexes are clamped to the string end:

local col = line and M.str_byteindex(line, pos.character, item.loc.encoding, false) or pos.character

Reproduction

  1. Open a .proto file with Chinese comments (or any file with CJK characters)
  2. Run :lua Snacks.picker.lsp_symbols()
  3. Navigate with <C-j>/<C-k>
  4. Observe crash on items whose range spans multi-byte characters

… on multi-byte lines

When an LSP server returns a `range.end.character` that exceeds the
UTF-16 length of a line (common with CJK/multi-byte characters),
`vim.str_byteindex` in Neovim 0.10+ raises "index out of range" because
`strict_indexing` defaults to `true`.

This causes a crash when navigating picker results (e.g. lsp_symbols)
in files containing multi-byte characters such as Chinese comments.

Fix by passing `strict_indexing=false` so out-of-range indexes are
clamped to the string end instead of throwing an error.

Closes folke#2389 (related)
@github-actions github-actions bot added picker size/xs Extra small PR (<3 lines changed) labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

picker size/xs Extra small PR (<3 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant