folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.45k stars 177 forks source link

bug: Invalid Window id Error #400

Closed tummetott closed 6 months ago

tummetott commented 6 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1703358377

Operating system/version

MacOs 14.2.1

Describe the bug

I get a invalid window id error:

Error setting option `foldlevel=99`

OptionSet Autocommands for "foldlevel": Vim(append):Error executing lua callback: ...es/.repro/plugins/trouble.nvim/lua/trouble/view/init.lua:150: Invalid window id: 1002
stack traceback:
^I[C]: in function '__index'
^I...es/.repro/plugins/trouble.nvim/lua/trouble/view/init.lua:150: in function <...es/.repro/plugins/trouble.nvim/lua/trouble/view/init.lua:145>
^I[C]: at 0x0104bb94c0
^I[C]: in function 'pcall'
^I.../.repro/plugins/trouble.nvim/lua/trouble/view/window.lua:177: in function 'set_options'
^I.../.repro/plugins/trouble.nvim/lua/trouble/view/window.lua:199: in function 'mount'
^I.../.repro/plugins/trouble.nvim/lua/trouble/view/window.lua:249: in function 'open'
^I...es/.repro/plugins/trouble.nvim/lua/trouble/view/init.lua:385: in function 'open'
^I...s/issues/.repro/plugins/trouble.nvim/lua/trouble/api.lua:55: in function <...s/issues/.repro/plugins/trouble.nvim/lua/trouble/api.lua:45>
^I...sues/.repro/plugins/trouble.nvim/lua/trouble/command.lua:130: in function 'execute'
^I.../.repro/plugins/trouble.nvim/lua/trouble/config/init.lua:179: in function <.../.repro/plugins/trouble.nvim/lua/trouble/config/init.lua:178>

Steps To Reproduce

nvim -u repro.lua :Trouble quickfix Open a emtpy trouble window. it can also be diagnostics or whatever, it does not matter :lua require('edgy').close() Close the Edgy Window :Trouble quickfix Open trouble again

BTW: the same error occurs in several scenarios, this is just one reproduction

Expected Behavior

No Error

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    {
        "folke/trouble.nvim",
        branch = "dev",
        lazy = false,
        opts = {
            follow = false,
            restore = true,
            auto_preview = false,
            auto_refresh = false,
        },
    },
    {
        'folke/edgy.nvim',
        opts = {
            bottom = {
                {
                    title = 'TROUBLE',
                    ft = 'trouble',
                },
            }
        }

    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/edgy.nvim",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 6 months ago

This is now fixed in Trouble v3. Thank you for reporting!

tummetott commented 6 months ago

Awesome, took you 11 minutes, you're a machine 😄

I thought it's an edgy error, thanks for fixing

amtoine commented 4 months ago

i get a very similar error nowadays, using the following versions

E5108: Error executing lua: ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:392: Invalid window id: 1009
stack traceback:
        [C]: in function 'get_cursor'
        ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:392: in function 'get_line'
        ....local/share/nvim/lazy/trouble.nvim/lua/trouble/view.lua:406: in function 'next_item'
        ....local/share/nvim/lazy/trouble.nvim/lua/trouble/init.lua:267: in function 'next'
        /home/amtoine/.config/nvim/lua/custom/lsp.lua:109: in function </home/amtoine/.config/nvim/lua/custom/lsp.lua:109>

i'm trying to use Trouble functions to jump around in the list of diagnostics

local nmap = function(keys, func, desc, bufnr)
  if desc then
    desc = 'LSP: ' .. desc
  end

  vim.keymap.set('n', keys, func, { buffer = bufnr, silent = true, noremap = true, desc = desc })
end

-- ...

local trouble = require("trouble")

-- ...

local jump = function(fn)
  return function() fn({skip_groups = true, jump = true}) end
end

nmap("<leader>ltj", jump(trouble.next), "Jump to next item")
nmap("<leader>ltk", jump(trouble.previous), "Jump to previous item")
nmap("<leader>ltg", jump(trouble.first), "Jump to first item")
nmap("<leader>ltG", jump(trouble.last), "Jump to last item")

-- ...

Note

  • before opening the Trouble window for the first time, the 4 bindings above don't do anything.
  • after the first time the Trouble window has been opened there are two cases
    • if the Trouble window is CLOSED: then the error appears
    • if the Trouble window is OPENED: the 4 bindings work as expected