You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it works well, but other times it frequently throws errors. Even within the same buffer, it’s available on some lines but unavailable on others.
The following is the output of the messages command.
Error executing vim.schedule lua callback: .../neovim/0.10.2_1/share/nvim/runtime/lua/vim/lsp/util.lua:485: index out of range
stack traceback:
[C]: in function 'get_line_byte_from_position'
.../neovim/0.10.2_1/share/nvim/runtime/lua/vim/lsp/util.lua:485: in function 'apply_text_edits'
...l/share/nvim/lazy/copilot.lua/lua/copilot/suggestion.lua:489: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
It seems like the issue is caused by inconsistencies between the content in the buffer and the plugin. Could you provide some suggestions to help me resolve this problem?
I added some debugging code, as shown below:
vim.schedule_wrap(function()
-- 调试:打印 range 和 newText 变量
print("range:", vim.inspect(range))
print("newText:", vim.inspect(newText))
-- 调试:检查缓冲区中的行数是否足够
local buf = vim.api.nvim_get_current_buf()
local line_count = vim.api.nvim_buf_line_count(buf)
print("Current buffer line count:", line_count)
-- 获取目标行的字符数
local target_line = vim.api.nvim_buf_get_lines(buf, range.start.line, range.start.line + 1, false)[1]
print("Target line:", target_line)
local target_line_length = #target_line
print("Target line lenght:", target_line)
-- 调整 range 的结束字符位置,确保不超出字符数
if range["end"].character > target_line_length then
print("Warning: Adjusting end character to fit within line length")
range["end"].character = target_line_length
end
-- 调试:尝试应用 text edit 并捕获错误
local success, err = pcall(function()
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Space><Left><Del>", true, false, true), "n", false)
vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, buf, "utf-16")
end)
if not success then
print("Error applying text edits:", err)
return
end
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Space><Left><Del>", true, false, true), "n", false)
-- vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, vim.api.nvim_get_current_buf(), "utf-16")
-- Put cursor at the end of current line.
local cursor_keys = "<End>"
if has_nvim_0_10_x then
cursor_keys = string.rep("<Down>", #vim.split(newText, "\n", { plain = true }) - 1) .. cursor_keys
end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(cursor_keys, true, false, true), "n", false)
end)()
end
the messages as shown below:
range: {
["end"] = {
character = 65,
line = 163
},
start = {
character = 0,
line = 163
}
}
newText: "-- 用户输入代码或命令(Read),即时执行(Eval), 并输出结果(Print), 然后等待用户输入下一条命令(Loop)"
Current buffer line count: 245
Target line: -- 用户输入代码或命令(Read),即时执行(Eval),
Target line length: 65
Error applying text edits: .../neovim/0.10.2_1/share/nvim/runtime/lua/vim/lsp/util.lua:485: index out of range
The text was updated successfully, but these errors were encountered:
When I changed the character encoding from UTF-16 to UTF-8(source code,not editor), it started working correctly. I suspect that this issue might be due to different strategies in handling character boundaries with various encodings in nvim’s LSP.
Sometimes it works well, but other times it frequently throws errors. Even within the same buffer, it’s available on some lines but unavailable on others.
The following is the output of the messages command.
It seems like the issue is caused by inconsistencies between the content in the buffer and the plugin. Could you provide some suggestions to help me resolve this problem?
I added some debugging code, as shown below:
the messages as shown below:
The text was updated successfully, but these errors were encountered: