TaDaa / vimade

An eye friendly plugin that fades your inactive buffers and preserves your syntax highlighting!
MIT License
486 stars 8 forks source link

Array index sometimes is a float? #34

Closed tzhouhc closed 4 years ago

tzhouhc commented 4 years ago

Behavior:

Sometimes when using fzf's list view, instead of it working I would get this

Screen Shot 2019-12-20 at 00 55 22
Error detected while processing function vimade#CheckWindows[3]..provider#python#Call:
line   18:
Error invoking 'python_execute' on channel 7 (python2-script-host):^@Traceback (most recent call last):^@  File "<string>", line 2, in <module>^@  File "/Users/tingzhou/.dotfiles
/vim/bundle/vimade/lib/vimade/bridge.py", line 32, in update^@    fader.update(nextState)^@  File "/Users/tingzhou/.dotfiles/vim/bundle/vimade/lib/vimade/fader.py", line 208, in
update^@    fadeWin(win)^@  File "/Users/tingzhou/.dotfiles/vim/bundle/vimade/lib/vimade/fader.py", line 476, in fadeWin^@    adjustEnd = rawText[cursorCol:mCol]^@TypeError: slic
e indices must be integers or None or have an __index__ method

I don't know what is needed to trigger this issue, but --

Some print() debugging shows that the issue from line 476 in fader.py is that, sometimes mCol is a float. In my case, I got an '1.0' somehow. Casting to int(mCol) makes it work.

Screen Shot 2019-12-20 at 00 55 04

Following the trace up, it seems like line 419 is the culprit: in python2.7.16, math.floor always returns a float, even if fed an int, which then borks the array index. Adding an int casting fixes the issue for myself:

virtual_rows = int(math.floor(end_text_ln / width))

I'd like to think that even without a setup to reproduce this issue, this is a safe-ish casting to do? :)

tzhouhc commented 4 years ago

Oh also in case someone else bumps into the same issue and doesn't want to modify code -- updating your python neovim bindings might help (if you are using neovim, that is):

pip3 install pynvim neovim

I reverted my changes to fader.py and vimade runs just fine in py3 mode, so I'm set! Feel free to close! Thanks for the great work!

TaDaa commented 4 years ago

thanks for the detailed report and finding the issue -- should be all set now for python 2 as well