start_col out of bounds
naefl opened this issue · comments
Describe the bug
Heya - thanks for le awesome plugin. Just ran into this error. Will debug further later tonight but wanted to report already because you might now the answer.
Getting start_col out of bounds
when triggering completion.
Here's the relevant logs
[nvim-magic] [DEBUG 13:54:00] .../.vim/plugged/nvim-magic/lua/nvim-magic/_buffer.lua:25: Appended lines count=26 row=4 col=2147483647)
Error executing vim.schedule lua callback: .../.vim/plugged/nvim-magic/lua/nvim-magic/_buffer.lua:26: start_col out of bounds
Clearly the col number shouldn't be 2147483647
so something's fishy there in the way it gets the selection.
Looking at the response.json
the correct completion is fetched, all looks reasonable there, just appears to have some funky stuff going on with that col number.
To Reproduce
Steps to reproduce the behavior:
e.g.
- Select some text
- run
require('nvim-magic.flows').append_completion(require('nvim-magic').backends.default)
Expected behavior
Don't error out :)
Screenshots
Details (please complete the following information):
- OS: MacOSX Big Sur M1 MBA
- Neovim version: 0.5
- nvim-magic version: commit #3ae8941
Same here in Arch Linux, it happened to me 4 when I first tried the plugin. I thought it was because I didn't have access to codex engines but now that I do the same happens.
ok so get_visual_start_end()
returns the odd col nr
ok so appears that this is due to line selection logic. using v
to select the text, vs V
works
from :h getpos
Note that for '< and '> Visual mode matters: when it is "V"
'> is a large number.
The column number in the returned List is the byte position
within the line.
The column number can be very large, e.g. 2147483647, in which
case it means "after the end of the line".
This can be used to save and restore the position of a mark: >
let save_a_mark = getpos("'a")
...
call setpos("'a", save_a_mark)
Thanks for debugging the cause for this issue! I've only used v
so encountered this bug only if I edited the text that was previously selected while the completion was being fetched. I'm going to try to fix this to work with V
in the code as well.
I've merged a possible fix into master
, I tried out a few completions using visual line mode and it seems to be working now, let me know if it works for you 🙏
@jameshiew been testing all morning, works for me
Great thanks for testing!