codota / tabnine-nvim

Tabnine Client for Neovim
https://tabnine.com
362 stars 32 forks source link

[BUG] Cursor position outside buffer #157

Closed gachikuku closed 8 months ago

gachikuku commented 8 months ago

https://github.com/codota/tabnine-nvim/assets/11743804/5dc7abf9-11f4-4be2-98ae-e3d293ee8f00

When I press TAB to complete, the error shown in the video is displayed.

Version Info:

My tabnine config https://github.com/gachikuku/.dotfiles/blob/main/nvim/.config/nvim/lua/gachikuku/lazy/tabnine.lua

The dl_binaries.sh script has been ran manually within the plugin directory ~.local/share/nvim/lazy/tabnine-nvim I could not get it to work by simply including this build = "./dl_binaries.sh" in my lazyvim config.

aarondill commented 8 months ago

@amirbilu this is caused by #156 the expression to calculate the new line number should be:

fn.line(".") + #lines - 2

the current line, plus the number of lines to insert, minus one because the api is 0 indexed, minus one because the current line already exists.

aarondill commented 8 months ago

@gachikuku if you change line 29 in ~/.local/share/nvim/lazy/tabnine-nvim/lua/tabnine/completion.lua

to this:

api.nvim_win_set_cursor(0, { fn.line(".") + #lines - 2, fn.col(".") + #lines[#lines] })

does it fix the issue?

gachikuku commented 8 months ago
image

Actually it made it worse. Now the error occurs on one line and mulitple lines. Before only on mulitple lines.

gachikuku commented 8 months ago

api.nvim_win_set_cursor(0, { fn.line("."), fn.col(".") + #lines[#lines] }) fixes it. Found on #155

amirbilu commented 8 months ago

Thanks. This is a regression made by a recent PR i merged. Apologies.

barrydevp commented 8 months ago

@amirbilu I think the difference is in the neovim version. In #155 I'm using v0.10 whereas this issue is in v0.9.5. Perhaps neovim nvim_win_set_cursor api has changed its behaviour in the new version. Should we use another approach by using nvim_feedkeys as in copilot?

Screen Shot 2024-03-15 at 10 16 04

Or community copilot plugin for neovim written in lua https://github.com/zbirenbaum/copilot.lua/blob/f7612f5af4a7d7615babf43ab1e67a2d790c13a6/lua/copilot/suggestion.lua#L490

barrydevp commented 8 months ago

@amirbilu I think I found the change on the neovim nvim_buf_set_lines API affects this behaviour as in https://github.com/codota/tabnine-nvim/issues/155#issuecomment-2000057812. We could continue on #155.