mrjones2014 / legendary.nvim

🗺️ A legend for your keymaps, commands, and autocmds, integrates with which-key.nvim, lazy.nvim, and more.
MIT License
1.14k stars 19 forks source link

[Bug]: Clicking in nvim window with legendary picker open breaks legendary #447

Closed WizardStark closed 6 months ago

WizardStark commented 6 months ago

Similar Issues

Neovim Version

$ nvim --version 
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1710088188

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"

Run :checkhealth for more info

Steps to Reproduce

  1. Open finder
  2. Triple click anywhere outside finder window
  3. Try to open finder again

Expected Behavior

Finder opens as normal

Actual Behavior

No finder window appears, although legendary logs report normal behaviour.

Minimal Configuration to Reproduce

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",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    -- do not remove the colorscheme! it makes testing nicer
    "folke/tokyonight.nvim",
    {
        "mrjones2014/legendary.nvim",
        dependencies = {
            { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
            "stevearc/dressing.nvim",
        },
    },
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

require("dressing").setup()

require("legendary").setup({
    -- add any options here
})

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme! it makes testing nicer
vim.cmd([[colorscheme tokyonight]])

Output from :LegendaryLog

:LegendaryLog output (click to expand) ``` [Tue 16 Apr 09:23:03 2024][legendary.nvim] Took 2.026875 ms to filter items in context. [Tue 16 Apr 09:23:03 2024][legendary.nvim] Config.sort.frecency is enabled, but sqlite is not available or database could not be opened, frecency is automatically disabled. [Tue 16 Apr 09:22:57 2024][legendary.nvim] Took 2.055083 ms to filter items in context. [Tue 16 Apr 09:22:57 2024][legendary.nvim] Config.sort.frecency is enabled, but sqlite is not available or database could not be opened, frecency is automatically disabled. [Tue 16 Apr 09:22:54 2024][legendary.nvim] setup() parsed and applied all configuration. ```

The second call here at 09:23:03 did not open any finder

Additional Details and/or Screenshots

Triple clicking may seem excessive - in my own config though it is only a single click (which often occurs when just refocusing the nvim window).

I also find this very strange as any telescope window handles this gracefully, and legendary just uses the vim.ui.select implementation of your choice.

mrjones2014 commented 6 months ago

Interesting, I am able to reproduce, and weirdly, after adding some debug logs, it is executing properly all the way up to the vim.ui.select line (I added a debug line directly above vim.ui.select which does run) and then it appears that vim.ui.select just... does nothing?

https://github.com/mrjones2014/legendary.nvim/blob/a88744dcfc1e0ad0ed1e347778f036d7b6e4a0ca/lua/legendary/ui/init.lua#L77

mrjones2014 commented 6 months ago

Possibly Neovim bug? Let's see if we can reproduce with a different vim.ui.select handler like mini.pick or fzf-lua

WizardStark commented 6 months ago

Using mini.pick or fzf-lua I am not able to reproduce this behaviour - the window opened by either plugin closes as expected when clicking outside of it.

Super strange that this only happens with Telescope + legendary, I tried all builtin telescope pickers and was not able to break it.

minimal init.lua for swapping between all 3:

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",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    -- do not remove the colorscheme! it makes testing nicer
    "folke/tokyonight.nvim",
    {
        "mrjones2014/legendary.nvim",
        dependencies = {
            -- {
            --  "echasnovski/mini.pick",
            --  version = "*",
            --  config = function()
            --      vim.ui.select = require("mini.pick").ui_select
            --  end,
            -- },
            -- {
            --  "ibhagwan/fzf-lua",
            --  config = function()
            --      require("fzf-lua").register_ui_select()
            --  end,
            -- },
            { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } },
            { "stevearc/dressing.nvim", opts = {} },
        },
    },
    -- add any other pugins here
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

require("legendary").setup({
    -- add any options here
})

-- add anything else here
vim.opt.termguicolors = true
-- do not remove the colorscheme! it makes testing nicer
vim.cmd([[colorscheme tokyonight]])
WizardStark commented 6 months ago

Confirmed that this is a bug in the dressing code, at least for the telescope select implementation.

Any logging in this method is hit while the legendary select ui is functioning as normal, but is absent after breaking.

WizardStark commented 6 months ago

Just for interests sake I also used fzf-lua + dressing, which does not break - so narrowed down to the dressing telescope select implementation.

WizardStark commented 6 months ago

Created issue https://github.com/stevearc/dressing.nvim/issues/150, feel free to close this!