folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.32k stars 344 forks source link

bug: keys configured for a plugin do not trigger loading it #441

Closed technicalpickles closed 1 year ago

technicalpickles commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.9.0-dev-1940+g0344bfad0-dirty

Operating system/version

macOS 13.2

Describe the bug

I'm in the process of migrating from packer to lazy.nvim. My config worked initially without making things lazy, and so started to sprinkle that in. I added keys for a few of my plugins and that worked as expected, until I got to trouble.nvim adding keys.

The keys do not seem to be working as expected My mapleader is `, so I start a new nvim, and try to use xxto triggle toggling. Instead, I get the behavior ofxx`, which is deleting two characters.

I've compared to LazyNvim, and it looks equivilent as far as I can tell: https://github.com/LazyVim/LazyVim/blob/e2bfd2d66499a208812d815f38d90c0eac9dedda/lua/lazyvim/plugins/editor.lua#L236-L244

Steps To Reproduce

  1. configure lazy.nvim with this spec
    {
        "folke/trouble.nvim",
        dependencies = "nvim-tree/nvim-web-devicons",
        cmd = { "TroubleToggle", "Trouble" },
        keys = {
            {"<leader>xx", "<CMD>TroubleToggle<CR>", silent_noremap},
            {"<leader>xw", "<CMD>Trouble workspace_diagnostics<CR>", silent_noremap},
            {"<leader>xd", "<CMD>Trouble document_diagnostics<CR>", silent_noremap},
            {"<leader>xl", "<CMD>Trouble loclist<CR>", silent_noremap},
            {"<leader>xq", "<CMD>Trouble quickfix<CR>", silent_noremap},
            {"gR", "<CMD>Trouble lsp_references<CR>", silent_noremap},

            -- ⌘-shift-m - toggle quickfix (aka problems)
            {"<S-D-M>", "<cmd>TroubleToggle<CR>", silent_noremap},
            {"<leader>M", "<cmd>TroubleToggle<CR>", silent_noremap},
        },
    },
  1. open a file and type <leader>xx
  2. see 2 characters deleted, instead of trouble window toggled
  3. call :TroubleToggle
  4. Try <leader>xx and see it toggled

Expected Behavior

I'd expect to see trouble toggled the first time with <leader>xx without having to call ToggleTrouble.

Repro

-- FIXME: haven't been able to reproduce yet :( this seems to work, so missing some other detail

-- 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)

local silent_noremap = { noremap = true, silent = true }

-- set mapleader to space
vim.g.mapleader = ' '

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
      "folke/trouble.nvim",
      dependencies = "nvim-tree/nvim-web-devicons",
      cmd = { "TroubleToggle", "Trouble" },
      keys = {
          {"<leader>xx", "<CMD>TroubleToggle<CR>", silent_noremap},
          {"<leader>xw", "<CMD>Trouble workspace_diagnostics<CR>", silent_noremap},
          {"<leader>xd", "<CMD>Trouble document_diagnostics<CR>", silent_noremap},
          {"<leader>xl", "<CMD>Trouble loclist<CR>", silent_noremap},
          {"<leader>xq", "<CMD>Trouble quickfix<CR>", silent_noremap},
          {"gR", "<CMD>Trouble lsp_references<CR>", silent_noremap},

          -- ⌘-shift-m - toggle quickfix (aka problems)
          {"<S-D-M>", "<cmd>TroubleToggle<CR>", silent_noremap},
          {"<leader>M", "<cmd>TroubleToggle<CR>", silent_noremap},
      },
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

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

The plugin's setup will never by called. Set opts = {} or config = true