Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid window id when closing windows #72

Open
petobens opened this issue Mar 21, 2020 · 5 comments
Open

Invalid window id when closing windows #72

petobens opened this issue Mar 21, 2020 · 5 comments

Comments

@petobens
Copy link

petobens commented Mar 21, 2020

Consider the following minimal init.vim file:

let $DOTVIM = expand('$HOME/.config/nvim')

set runtimepath+=$DOTVIM/bundle/repos/github.com/numirias/semshi
filetype plugin indent on

Now open nvim and, as in the GIF, do:

  1. Edit some random python file with :e a.py and add a single line # foo.
  2. Split windows with :vsp
  3. Run location list vimgrep with :lvim foo % | lopen
  4. Switch from the location list window to the new split window and run 3. again
  5. Switch from this new location list window to the first (left) window (using <Ctrl-w> mappings)
  6. Run windo if &buftype == 'quickfix' | lclose | endif

After 6. an invalid window id error is triggered:

Error detected while processing function SemshiBufEnter[1]..remote#define#request:
line    2:
error caught in async handler '/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/semshi:function:SemshiCursorMoved [[1, 1]]'
Traceback (most recent call last):
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/semshi/plugin.py", line 102, in event_cursor_moved
    self._mark_selected()
  File "/home/pedro/git-repos/private/dotfiles/vim/bundle/.cache/init.vim/.dein/rplugin/python3/semshi/plugin.py", line 234, in _mark_selected
    self._cur_handler.mark_selected(self._vim.current.window.cursor)
  File "/home/pedro/.local/lib/python3.8/site-packages/pynvim/api/window.py", line 22, in cursor
    return self.request('nvim_win_get_cursor')
  File "/home/pedro/.local/lib/python3.8/site-packages/pynvim/api/common.py", line 58, in request
    return self._session.request(name, self, *args, **kwargs)
  File "/home/pedro/.local/lib/python3.8/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/home/pedro/.local/lib/python3.8/site-packages/pynvim/msgpack_rpc/session.py", line 104, in request
    raise self.error_wrapper(err)
pynvim.api.common.NvimError: Invalid window id: 1003

semshi

@voldikss
Copy link

voldikss commented Apr 9, 2020

Ran into this issue when I use asyncrun.vim to run python code in a split terminal window. When I closed the terminal, this error occured.

@petobens
Copy link
Author

petobens commented Jul 25, 2020

@numirias hi! Any chance/plans to look into this? Thanks in advance :)

@blueyed
Copy link
Contributor

blueyed commented Nov 25, 2020

I am seeing this often with vim-fugitive (tpope/vim-fugitive#1634).

From adding some printing etc it appears the window is gone when Semshi asks for the cursor position there.

DBG: [37, 37] (WinLeave: abuf: 4, amatch: …foo.py, winnr():2, ft: python, bt: )
DBG: [37, 37] (WinEnter: abuf: 16, amatch: fugitive://…, winnr():1, ft: python, bt: )
DBG: [37, 37] (BufEnter: abuf: 16, amatch: fugitive://…, winnr():1, ft: python, bt: )
=== _update_step buf=<Buffer(handle=16)> ===
  File "/usr/lib/python3.8/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 158, in _update_loop
    self._update_step()
  File "…/vim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 178, in _update_step
    self._buf, "".join(traceback.format_stack())

semshi: _wait_for: (<function BufferHandler._update_step.<locals>.<lambda> at 0x7ff5ae1dd430>, False)
  File "/usr/lib/python3.8/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 158, in _update_loop
    self._update_step()
  File "…/vim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 184, in _update_step
    code = self._wait_for(lambda: lines_to_code(self._buf[:]), sync)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 118, in _wait_for
    "semshi: _wait_for", (func, sync), "".join(traceback.format_stack())
semshi: _wait_for: (<function BufferHandler._update_step.<locals>.<lambda> at 0x7ff5ae1ddaf0>, False)
  File "/usr/lib/python3.8/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 158, in _update_loop
    self._update_step()
  File "…/vim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 206, in _update_step
    cursor = self._wait_for(
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 118, in _wait_for
    "semshi: _wait_for", (func, sync), "".join(traceback.format_stack())
DBG: [37, 37] (BufWinLeave: abuf: 16, amatch: fugitive://…, winnr():1, ft: python, bt: )
DBG: [37, 37] (BufUnload: abuf: 16, amatch: fugitive://…, winnr():1, ft: python, bt: )
DBG: [37, 37] (BufDelete: abuf: 16, amatch: fugitive://…, winnr():1, ft: python, bt: )
DBG: [37] (WinEnter: abuf: 4, amatch: …foo.py, winnr():1, ft: python, bt: )
Error detected while processing function SemshiBufEnter[1]..remote#define#request:
line    2:
error caught while executing async callback:
NvimError('Invalid window id: 1002')
Traceback (most recent call last):
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 124, in wrapper
    res = func()
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 207, in <lambda>
    lambda: self._vim.current.window.cursor, sync
  File "/usr/lib/python3.8/site-packages/pynvim/api/window.py", line 22, in cursor
    return self.request('nvim_win_get_cursor')
  File "/usr/lib/python3.8/site-packages/pynvim/api/common.py", line 58, in request
    return self._session.request(name, self, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/pynvim/msgpack_rpc/session.py", line 102, in request
    raise self.error_wrapper(err)
pynvim.api.common.NvimError: Invalid window id: 1002
 
the call was requested at
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 158, in _update_loop
    self._update_step()
  File "…/vim/plugged/semshi/rplugin/python3/semshi/util.py", line 19, in wrapper
    res = func(*args, **kwargs)
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 206, in _update_step
    cursor = self._wait_for(
  File "…/vim/plugged/semshi/rplugin/python3/semshi/handler.py", line 134, in _wait_for
    self._vim.async_call(wrapper)
error while running <function BufferHandler._update_step.<locals>.<lambda> at 0x7ff5ae1ddaf0>: Invalid window id: 1002

Here the handler (0x7ff5ae1ddaf0) was triggered for BufEnter of buffer 16, and the error happens after WinEnter of buffer 4, when buffer 16 was deleted/unloaded already.

I might look into this a bit more later, but it might also make sense to unregister via BufUnload/BufDelete, and/or just ignore this kind of expected error.

blueyed added a commit to blueyed/semshi that referenced this issue Nov 25, 2020
This should not be necessary in general, since it gets triggered via
`CursorMoved` already.
It also might trigger an error due to `self._vim.current.window` not
being a valid window anymore, when `cursor` gets accessed [1].
It also should not be using the global current window's cursor (which
might be for another buffer!) to mark selected nodes in the buffer.

1: numirias#72
This might trigger
blueyed added a commit to blueyed/semshi that referenced this issue Nov 25, 2020
This should not be necessary in general, since it gets triggered via
`CursorMoved` already.
It also might trigger an error due to `self._vim.current.window` not
being a valid window anymore, when `cursor` gets accessed [1].
It also should not be using the global current window's cursor (which
might be for another buffer!) to mark selected nodes in the buffer.

1: numirias#72
@blueyed
Copy link
Contributor

blueyed commented Nov 25, 2020

#94 should help here / fix this, please give it a try.

@wookayin
Copy link
Contributor

wookayin commented Aug 27, 2021

Bumping this up with #94! (Actually similar errors can happen somewhere else, such as self._update_step(self._options.always_update_all_highlights), etc.)

blueyed added a commit to blueyed/semshi that referenced this issue Sep 28, 2021
This should not be necessary in general, since it gets triggered via
`CursorMoved` already.
It also might trigger an error due to `self._vim.current.window` not
being a valid window anymore, when `cursor` gets accessed [1].
It also should not be using the global current window's cursor (which
might be for another buffer!) to mark selected nodes in the buffer.

1: numirias#72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants