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

Error: Invalid window id #2859

Closed
mikehaertl opened this issue Jul 30, 2024 · 6 comments · Fixed by #2863
Closed

Error: Invalid window id #2859

mikehaertl opened this issue Jul 30, 2024 · 6 comments · Fixed by #2863
Labels
awaiting feedback bug Something isn't working

Comments

@mikehaertl
Copy link
Contributor

mikehaertl commented Jul 30, 2024

Description

I get this error when I try to open a file under certain conditions:

Error executing vim.schedule lua callback: ...g/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:172: Invalid window id: 1008
stack traceback:
        [C]: in function 'nvim_set_option_value'
        ...g/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:172: in function 'pick_win_id'
        ...g/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:249: in function 'get_target_winid'
        ...g/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:277: in function 'open_in_new_window'
        ...g/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:400: in function 'fn'
        /tmp/plugged/vim-plug/nvim-tree.lua/lua/nvim-tree/view.lua:532: in function </tmp/plugged/vim-plug/nvim-tree.lua/lua/nvim-tree/view.lua:501>

I'm unsure if nvim-tree is really the root problem. I had to play around a lot to find the minmal set of plugins to reproduce the issue:

  • vim-airline
  • nvim-tre
  • fzf-lua
  • incline.nvim

Neovim version

NVIM v0.10.0
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068

Operating system and version

Linux Mint 21.3

Windows variant

No response

nvim-tree version

48d0e82

Clean room replication

"
" Minimal vim config to reproduce issues without messing with installed plugins.
" Based on https://github.com/hrsh7th/nvim-cmp/blob/main/utils/vimrc.vim
"
" To start vim with this config:
"  vim -u /path/to/minimal-example.vim
"
if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'ibhagwan/fzf-lua', { 'branch': 'main' }
Plug 'b0o/incline.nvim'
call plug#end()
PlugInstall | quit

let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
set laststatus=3                " always show the status line

lua << EOF
require('fzf-lua').setup()
require('incline').setup()
require('nvim-tree').setup()
EOF


let mapleader = ','       " Map <leader> to , instead of default \
nmap <leader>t <Cmd>NvimTreeFindFileToggle<CR>
nmap <leader>/ <Cmd>FzfLua live_grep path_shorten=false<CR>

Steps to reproduce

  1. mkdir test && cd test
  2. touch {a,b,c}.txt
  3. echo aaa > a.txt && echo aaa > c.txt
  4. nvim -u /path/to/above/minimal.vim -o a.txt b.txt
  5. Press , + t (to open nvim-tree)

You should now have this condition. Active window must be tree:
image

  1. Now trigger a fzf grep with , + / and enter aaa
    image

  2. Pick file c.txt with <c-j> followed by <CR>

  3. You should get a window selection (A or B).
    image

  4. Press A to select upper window.

Expected behavior

There should be no error

Actual behavior

image

@mikehaertl mikehaertl added the bug Something isn't working label Jul 30, 2024
@alex-courtis
Copy link
Member

Thanks for the detailed reproduction, however I can't reproduce this.

We'll need a standalone reproducer: there are four other plugins and moving parts. Just nvim-tree or nvim-tree + 1 other plugin please.

20240803_130627

@mikehaertl
Copy link
Contributor Author

Thanks for the detailed reproduction, however I can't reproduce this.

This is weird. I will try in an even cleaner environment.

We'll need a standalone reproducer: there are four other plugins and moving parts. Just nvim-tree or nvim-tree + 1 other plugin please.

I understand - but I can't: If I leave away only 1 plugin the issue goes away. I really spent a long time to reduce as much as possible. This is the best I could achieve.

But let me now first find out why you can't reproduce it. Maybe the fzf version is also relevant (0.53.0 (c4a9ccd))

@mikehaertl
Copy link
Contributor Author

I can also reproduce it in a completely new user environment. And also with the latest version of fzf (0.54.3 (af4917d)).

I started debugging myself now. I have no idea what to look for so I changed the location of the error around open-file.lua:172 like this:

  if laststatus == 3 then
    local tp = vim.api.nvim_get_current_tabpage()
    local wids = vim.api.nvim_tabpage_list_wins(tp)
    print("wids", vim.inspect(wids))
    print("usable_win_ids()", vim.inspect(usable_win_ids()))
    print("selectable", vim.inspect(selectable))
    print("not_selectable", vim.inspect(not_selectable))
    for _, id in ipairs(not_selectable) do
      for opt, value in pairs(win_opts[id]) do
        if vim.fn.has "nvim-0.10" == 1 then
          vim.api.nvim_set_option_value(opt, value, { win = id })
        else
          vim.api.nvim_win_set_option(id, opt, value) ---@diagnostic disable-line: deprecated
        end
      end
    end
  end

This is what I get:

Pick window:
wids { 1010, 1001, 1000, 1004, 1003 }
usable_win_ids() { 1001, 1000 }
selectable { 1001, 1000 }
not_selectable { 1010, 1009, 1004, 1003 }
Error executing vim.schedule lua callback: ...d/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:178: Invalid window id: 1009
stack traceback:
        [C]: in function 'nvim_set_option_value'
        ...d/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:178: in function 'pick_win_id'
        ...d/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:255: in function 'get_target_winid'
        ...d/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:283: in function 'open_in_new_window'
        ...d/nvim-tree.lua/lua/nvim-tree/actions/node/open-file.lua:406: in function 'fn'
        .../share/nvim/plugged/nvim-tree.lua/lua/nvim-tree/view.lua:532: in function <.../share/nvim/plugged/nvim-tree.lua/lua/nvim-tree/view.lua:501>

So it seems the list of not_selectable is already outdated at this point?

@alex-courtis
Copy link
Member

So it seems the list of not_selectable is already outdated at this point?

That sounds about right. open-file.lua is quite fragile however should become more robust following #2255

I can also reproduce it in a completely new user environment. And also with the latest version of fzf (0.54.3 (af4917d)).

Please share the init.vim/lua and instructions for reproduction.

@mikehaertl
Copy link
Contributor Author

The instructions are already above. I just created a new user and sudoed into it:

sudo useradd -d /home/nvimtest -m -s /bin/bash nvimtest
sudo -i -u nvimtest

And the /home/nvimtest/.config/nvim/init.vim is also almost identical to what I already posted:

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = stdpath('data') . '/plugged'

if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin()
Plug 'vim-airline/vim-airline'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'ibhagwan/fzf-lua', { 'branch': 'main' }
Plug 'b0o/incline.nvim'
call plug#end()
PlugInstall | quit

let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
set laststatus=3                " always show the status line

lua << EOF
require('fzf-lua').setup()
require('incline').setup()
require('nvim-tree').setup()
EOF


let mapleader = ','       " Map <leader> to , instead of default \
nmap <leader>t <Cmd>NvimTreeFindFileToggle<CR>
nmap <leader>/ <Cmd>FzfLua live_grep path_shorten=false<CR>

@alex-courtis
Copy link
Member

I just created a new user and sudoed into it:

That's a really way to do a completely clean replication!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants