From 40f5115ac43088fb6183a860d5db4ccd206e9bcc Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Sun, 24 Aug 2025 20:15:14 +0800 Subject: [PATCH] fix(lua): disable `strict_indexing` when converting LSP positions --- runtime/lua/vim/pos.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/pos.lua b/runtime/lua/vim/pos.lua index 56bf500ec2..48ad8157ab 100644 --- a/runtime/lua/vim/pos.lua +++ b/runtime/lua/vim/pos.lua @@ -172,7 +172,9 @@ function Pos.lsp(buf, pos, position_encoding) -- When on the first character, -- we can ignore the difference between byte and character. if col > 0 then - col = vim.str_byteindex(get_line(buf, row), position_encoding, col) + -- `strict_indexing` is disabled, because LSP responses are asynchronous, + -- and the buffer content may have changed, causing out-of-bounds errors. + col = vim.str_byteindex(get_line(buf, row), position_encoding, col, false) end return Pos.new(row, col, { buf = buf })