tools-life / taskwiki

Proper project management with Taskwarrior in vim.
Other
827 stars 93 forks source link

NVIM: WholeBuffer.update_from_tw() IndexError: list index out of range #96

Closed akashin closed 8 years ago

akashin commented 8 years ago

Hello! Thanks for an awesome plugin!

I'm getting the following error message when I try to open vimwiki file:

Error detected while processing function provider#python#Call:
line 18: IndexError('list index out of range',)
Traceback (most recent call last):  File "/Users/acid/Library/Python/2.7/lib/python/sitepackages/neovim/msgpack_rpc/session.py", line 177, in handler
    rv = self._request_cb(name, args)
  File "/Users/acid/Library/Python/2.7/lib/python/site-packages/neovim/api/common.py", line 237, in filter_request_cb
    walk(self._in, args, self, name, 'request'))
  File "/Users/acid/Library/Python/2.7/lib/python/site-packages/neovim/plugin/host.py", line 65, in _on_request
    rv = handler(*args)
  File "/usr/local/Cellar/neovim/0.1.2/share/nvim/runtime/autoload/provider/script_host.py", line 85, in python_execute_file
    exec(script, self.module.__dict__)
  File "/Users/acid/.vim/plugged/taskwiki/taskwiki/taskwiki.py", line 535, in <module>
    WholeBuffer.update_from_tw()
IndexError: list index out of range

After some digging I found out that the problem arises from access to wrong list element here: https://github.com/tbabej/taskwiki/blob/97d83de02b9f152d0cacbe9ccc066b85b4ae9f84/taskwiki/cache.py#L17

Apparently, some buffers with smaller numbers may be missing in vim.buffers leading to shift of positions of other buffers in this list (that's what happens in my case, I have buffers 2 and 3 but not 0 and 1).

I'm not sure whether this is specific to my installation or this is a bug, but we can use more robust solution to find specific buffer just by iterating over all buffers. The following quick fix works for me: https://github.com/IIoTeP9HuY/taskwiki/commit/a643bbbf93d7ad4aa5a6a6dcb16d03667f654e55

Could you please verify whether this is configuration issue or a bug? I'm using NVIM 0.1.2 with python installed through pip python support.

tbabej commented 8 years ago

No, this is not specific to your install, it's a bug, and one that has been here only for a short time.

I actually wrote a patch for this yesterday, but it only shifts the numbering of the Neovim buffers by -1. That helped, since I usually open taskwiki files directly in a dedicated nvim session, hence I rarely start with a buffer number larger than 1.

Your solution seems more robust, so I suggest we turn it into a pull request. Can you rebase the work on top my latest changes? I'd also move the get_buffer method to util.py, and call it only if we're in nvim (see NEOVIM constant).

tbabej commented 8 years ago

Fixed in current master.