wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.87k stars 266 forks source link

Can't work with nvim tree with latest version #285

Open glepnir opened 3 years ago

glepnir commented 3 years ago

@akinsho Hey there. update the all things just now. nvim tree can't work when first open. the buffer is empty of nvimtree. seems like the plugin/tree.vim not load ?

ui['kyazdani42/nvim-tree.lua'] = {
  cmd = {'NvimTreeToggle','NvimTreeOpen'},
  config = conf.nvim_tree,
  requires = 'kyazdani42/nvim-web-devicons'
}

nvim tree need this augroup. when lazyload the nvim-tree. it not load when press command before

augroup NvimTree
  if get(g:, 'nvim_tree_hijack_netrw', 1) == 1 && get(g:, 'nvim_tree_disable_netrw', 1) == 0
    silent! autocmd! FileExplorer *
  endif
  au BufWritePost * lua require'nvim-tree'.refresh()
  if get(g:, 'nvim_tree_lsp_diagnostics', 0) == 1
    au BufWritePost * lua require'nvim-tree.diagnostics'.update()
  endif
  au BufEnter * lua require'nvim-tree'.buf_enter()
  if get(g:, 'nvim_tree_auto_close') == 1
    au WinClosed * lua require'nvim-tree'.on_leave()
  endif
  au ColorScheme * lua require'nvim-tree'.reset_highlight()
  au User FugitiveChanged lua require'nvim-tree'.refresh()
  if get(g:, 'nvim_tree_tab_open') == 1
    au TabEnter * lua require'nvim-tree'.tab_change()
  endif
augroup end
akinsho commented 3 years ago

Hmm 🤔 @glepnir I have a very similar config i.e

    use "kyazdani42/nvim-web-devicons"

    use {
      "kyazdani42/nvim-tree.lua",
      cmd = "NvimTreeOpen",
      keys = "<c-n>",
      config = conf("nvim-tree"),
      requires = "nvim-web-devicons"
    }

And that loads on demand. Regarding the plugin file, in this case packer I think doesn't have to do any special loading of the plugin file vim handles this automatically when packadd-ing the file. Have you tried it with a minimal init.lua to see if there's anything else getting in the way?

glepnir commented 3 years ago

It works before. yup if we add the plugin to data path or rtp .vim will load plugin/*.vim. but infact when i first press command I got empty buffer..

wbthomason commented 3 years ago

@glepnir Any chance you know what commit of nvim-tree was last working for you? @akinsho is correct; packadd should source everything in a plugin's plugin/ directory.

If you run :verbose autocmd NvimTree after trying to load the plugin, what output do you get?

glepnir commented 3 years ago

it will show like this. because the nvim-tree need a bufenter event in it's autogroup. so when i first to load nvim tree this group not load.

::verbose autocmd NvimTree
--- Autocommands ---
NvimTree  BufEnter
    *         lua require'nvim-tree'.buf_enter()
        Last set from ~/.local/share/nvim/site/pack/packer/opt/nvim-tree.lua/plugin/tree.vim
line 19
NvimTree  BufWritePost
    *         lua require'nvim-tree'.refresh()
        Last set from ~/.local/share/nvim/site/pack/packer/opt/nvim-tree.lua/plugin/tree.vim
line 15
NvimTree  ColorScheme
    *         lua require'nvim-tree'.reset_highlight()
        Last set from ~/.local/share/nvim/site/pack/packer/opt/nvim-tree.lua/plugin/tree.vim
line 23
NvimTree  User
    FugitiveChanged
              lua require'nvim-tree'.refresh()
        Last set from ~/.local/share/nvim/site/pack/packer/opt/nvim-tree.lua/plugin/tree.vim
line 24
glepnir commented 3 years ago

Untitled

wbthomason commented 3 years ago

Right - the confusing fact here is that the BufEnter autocommand should be in place before the buffer gets opened. We load the plugin by, in order:

  1. Deleting any lazy-loaders (fake commands, etc.)
  2. Running packadd the-plugin
  3. Running the plugin's config, if any
  4. Handling sequence loading, if any
  5. If the plugin was loaded via a fake command, calling the real thing to make the desired behavior happen

So creating the autocommand should happen in step (2) before being required in step (5). @glepnir, do you know what was the last working commit for you?

akinsho commented 3 years ago

As an FYI I believe this is an issue that should be discussed at nvim-tree rather than here as there has been a refactor to how it works that means the plugin behaves differently than you'd expect. It is discussed over in the issue below. The TLDR is that a user now has to add an extra call for it to work via lazy loading. I don't think this is due to some bug in packer rather a design decision in nvim-tree

https://github.com/kyazdani42/nvim-tree.lua/issues/280