Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error accepting suggestions with multibyte (Cyrillic) characters (utf-16 -> utf-8 fixes the issue) #330

Open
Galicarnax opened this issue Oct 31, 2024 · 2 comments

Comments

@Galicarnax
Copy link

When I type with Cyrillic alphabet, and getting suggestions, pressing the key binding to accept gives this error:

Error  02:24:02 PM msg_show.lua_error Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/util.lua:485: index out of range
stack traceback:
	[C]: in function 'get_line_byte_from_position'
	/usr/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>

Looking into lua/copilot/suggestion.lua, I see this:

    vim.lsp.util.apply_text_edits({ { range = range, newText = newText } }, vim.api.nvim_get_current_buf(), "utf-16")

If I change utf-16 to utf-8, everything seems to work fine. Any reason for utf-16 here?

@traysh
Copy link

traysh commented Nov 6, 2024

I'm having the same problem when I have any accents in the line I'm accepting the suggestion, such as é or ö. I'm on Linux, the default encoding is utf-8.

I confirm setting that line to utf-8 fixes it for me, but it would probably break for files with other encodings, and some platforms use other encodings by default. Maybe it would be better to check the buffer encoding?

@traysh
Copy link

traysh commented Nov 6, 2024

This PR should fix it.

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

No branches or pull requests

2 participants