lewis6991 / pckr.nvim

Spiritual successor of https://github.com/wbthomason/packer.nvim
MIT License
251 stars 13 forks source link

Lazy loading with dependent plugins isn't working #14

Closed shmerl closed 8 months ago

shmerl commented 8 months ago

Set up:

nvim --version
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

While trying to use such plugins.lua, it fails to lazy load a plugin based on NERDTreeTabsToggle command. Note, the actual code of the pckr.nvim is cloned and etc. it works in simpler configuration without using any conds:

local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim"
vim.opt.rtp:prepend(pckr_path)

local cmd = require('pckr.loader.cmd')
local keys = require('pckr.loader.keys')

-- Plugins
require('pckr').add({
  -- File tree
  { 'scrooloose/nerdtree',
    cond = {
      cmd('NERDTreeTabsToggle')
    }
  },
  { 'jistr/vim-nerdtree-tabs',
    cond = {
      cmd('NERDTreeTabsToggle')
    }
  }
})

Note that vim-nerdtree-tabs is built as an extension of nerdtree. I.e. it's using it. So I tried to put a command from the former as a lazy loading trigger for both. But in result it gives me this error when I try to use :NERDTreeTabsToggle

Error executing Lua callback: vim/_editor.lua:0: nvim_exec2(): Vim:E492: Not an editor command:  NERDTreeTabsToggle 
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ....local/share/nvim/pckr/pckr.nvim/lua/pckr/loader/cmd.lua:9: in function <....local/share/nvim/pckr/pckr.nvim/lua/pckr/loader/cmd.lua:6>
lewis6991 commented 8 months ago

There's not much need to lazy load either of these plugins.

I advise you don't lazy load for the sake of it and only do it if it genuinely speeds things up.

shmerl commented 8 months ago

Well, but does it mean that lazy loading is not handled correctly or I don't understand how it's supposed to be used? Can you please explain what I was dong wrong, or what are the functional limitations of lazy loading that one has to consider (i.e. when does it work and when it doesn't)?

I get that may be in this case it's not strictly necessary, but that's not the point of this bug report - the point is that it wasn't even working as expected.

lewis6991 commented 8 months ago

I suggest you use lazy.nvim if lazy loading is something you are interested in.

I haven't got time to provide user support for people who don't understand how to use this manager. I'm only interested in actual bugs or merging PR's

My guess here is that the cmd has loaded jistr/vim-nerdtree-tabs first which doesn't actually create any commands so the loader fails. cmd probably isn't designed to be used this way.

shmerl commented 8 months ago

I looked at lazy.nvim, but it looks massive for my needs and I thought pckr.nvim is a better option since it focuses on functionality I need.

I didn't know that lazy loading here is barebones and isn't working with some plugins.

I really followed the instruction, so argument of not understanding how to use it isn't really fair. Short of debugging the actual plugin, it was just an unexpected behavior.

May be adding a comment in the documentation that lazy loading isn't really always expected to work is worth it to set expectations if that's what you intend for it.

On a side note, that plugin does define this:

https://github.com/jistr/vim-nerdtree-tabs/blob/master/nerdtree_plugin/vim-nerdtree-tabs.vim#L88

command! NERDTreeTabsToggle   call <SID>NERDTreeToggleAllTabs()
lewis6991 commented 8 months ago

Neither vim or neovim source nerdtree_plugin/ upon loading a plugin, so lazy loading that extension will net you nothing other than one less entry in 'rtp'.

I assume it is nerdtree itself that sources this directory.

I really followed the instruction, so argument of not understanding how to use it isn't really fair. Short of debugging the actual plugin, it was just an unexpected behavior.

This is free open source. You take it, leave it or fix it.

shmerl commented 8 months ago

Yeah, it has something here:

https://github.com/preservim/nerdtree/blob/master/autoload/nerdtree.vim#L198

But I'm not sure how exactly that is triggered.

I guess this case just isn't a fit for the cmd as you said.