Operating system: MacOS 10.14.3
Python version: 3.6.8
Black version: 18.9b0
Neovim version: 0.3.4
Does also happen on master: yes
Using the Vim plugin, if the cursor is somewhere that will not exist after black has run, vim throws the error:
Error detected while processing function provider#python3#Call:
line 18:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 78, in Black
File "/Users/danturkel/anaconda3/lib/python3.6/site-packages/pynvim/api/window.py", line 27, in cur
sor
return self.request('nvim_win_set_cursor', pos)
File "/Users/danturkel/anaconda3/lib/python3.6/site-packages/pynvim/api/common.py", line 51, in req
uest
return self._session.request(name, self, *args, **kwargs)
File "/Users/danturkel/anaconda3/lib/python3.6/site-packages/pynvim/api/nvim.py", line 182, in requ
est
res = self._session.request(name, *args, **kwargs)
File "/Users/danturkel/anaconda3/lib/python3.6/site-packages/pynvim/msgpack_rpc/session.py", line 1
02, in request
raise self.error_wrapper(err)
pynvim.api.nvim.NvimError: b'Cursor position outside buffer'
Steps to reproduce:
```
Since the cursor starts in a place that no longer exists after running Black, vim doesn't know where to put it.
Black will delete the trailing newlines and bring the cursor up to the top.
Expected behavior:
This is up for debate. One interpretation would be: strip the trailing newlines and bring the cursor to the new last line.
PR https://github.com/ambv/black/pull/641 covers this, but it hasn't been merged yet.
Ah I searched issues but I didn't search PRs, so I missed this.
Thanks for the quick response!
@daturkel could you help verify whether the linked PR solves the issue for you? If so, I can merge @suola's PR.
@JelleZijlstra I just confirmed that #641 fixes this issue.
Thanks! I merged the PR. (Thanks also to @suola for submitting the change.)
Most helpful comment
PR https://github.com/ambv/black/pull/641 covers this, but it hasn't been merged yet.