supermaven-inc / supermaven-nvim

The official Neovim plugin for Supermaven
https://supermaven.com/
MIT License
755 stars 37 forks source link

fix: use correct offset_encoding #93

Closed altermo closed 2 months ago

altermo commented 2 months ago

Problem: When the current line contains specific non-ASCII characters, there's an index out of range error. Cause: The offset_encoding is set to utf-16 while the applied range uses utf-8 compatible indexing. Solution: use utf-8 for offset_encoding

sm-victorw commented 2 months ago

I haven't been able to reproduce the index out of range error, if possible could you give steps? I am noticing buggy behavior when dealing with non-ASCII characters, though the switch from utf-16 to utf-8 didn't seem to fix any of the bugs - from the looks of it the applied range doesn't use utf-8 either, but rather the byte offset which is still inconsistent for non-ASCII characters

altermo commented 2 months ago

Reproducible steps:

  1. Create a file
  2. Insert a single ¿
  3. In insert mode autocomplete with supermaven
    Picture of error

20240912_07h53m37s_grim

sm-victorw commented 2 months ago

If possible could you give the version of Nvim and operating system you are using? I wasn't able to reproduce this, inserting ¿ and accepting a completion works as expected, inserting ¿Qué es el área de la Ciudad de México? with no issues. Typing ¿¿ and accepting a completion results in a long series of ¿¿¿¿¿¿ but no error in this case either.

AlejandroSuero commented 2 months ago

I also wasn't able to reproduce it. I also changed it to utf-8 and was behaving the same way. If I write a comment in lua like -- ¿ supermaven suggests ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ but no errors either.

https://github.com/user-attachments/assets/ffc7d55c-5801-4866-a514-7fa9431980e0

NeoVim version:

NVIM v0.10.1
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068
altermo commented 2 months ago

Sorry, I forgot to tell you I'm running the development build... I looked through the blame and the neovim PR that makes this error happen is https://github.com/neovim/neovim/pull/30288. I would recommend merging this (or solving the problem another way) as the neovim commit has been backported to 0.10 (see https://github.com/neovim/neovim/pull/30308)

AlejandroSuero commented 2 months ago

I don't know if v0.9 will cause some trouble or not, I can't test that until next week though, if someone can test that still works with utf-8 then wouldn't hurt to merge the PR.

Adding vim.fn.has(nvim-0.10.0) and changing the encoding depending on that would be nice too if there is a problem with using utf-8 over utf-16.

altermo commented 2 months ago

I tested and it works with v0.9.4.