fix(picker): avoid crash on multi-byte lines in resolve_loc#2789
Open
lasorda wants to merge 1 commit intofolke:mainfrom
Open
fix(picker): avoid crash on multi-byte lines in resolve_loc#2789lasorda wants to merge 1 commit intofolke:mainfrom
lasorda wants to merge 1 commit intofolke:mainfrom
Conversation
… 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
Snacks.picker.lsp_symbols()on files containing multi-byte characters (e.g. Chinese comments in.protofiles), navigating the picker results with<C-j>/<C-k>crashes with:Root Cause
In
resolve_loc(),M.str_byteindexis called without thestrict_indexingparameter:When an LSP server (e.g. clangd) returns a
range.end.characterthat exceeds the UTF-16 length of a line — which is common with CJK/multi-byte characters —vim.str_byteindexin Neovim 0.10+ raises"index out of range"becausestrict_indexingdefaults totrue.The fix in #2389 (commit 46917d0) correctly added the
strict_indexingparameter toM.str_byteindex, but the call site inresolve_locnever passes it.Fix
Pass
strict_indexing=falseso out-of-range indexes are clamped to the string end:Reproduction
.protofile with Chinese comments (or any file with CJK characters):lua Snacks.picker.lsp_symbols()<C-j>/<C-k>