nvim-tree.lua icon indicating copy to clipboard operation
nvim-tree.lua copied to clipboard

Is this plugin incompatible with nvim-treesitter?

Open yanskun opened this issue 3 years ago • 16 comments

Description

When I open a file from Treesitter, I get an nvim-tree error.

However, once the error is displayed, it will not be displayed even if the same thing is done next time.

nvim-tree config

return function()
  local ok, nvimtree = pcall(require, 'nvim-tree')

  if not ok then
    return
  end

  nvimtree.setup {
    disable_netrw = false,
    hijack_netrw = true,
    hijack_cursor = true,
    update_focused_file = {
      enable = true,
      update_cwd = false,
    },
    actions = {
      open_file = {
        resize_window = true,
      }
    },
    git = {
      enable = true,
      ignore = false,
    }
  }

  require('which-key').register {
    ['<leader>t'] = { '<Cmd>NvimTreeToggle<CR>', 'nvim tree open / close toggle' }
  }
end

nvim-treesitter config

return function()
  require('nvim-treesitter.configs').setup {
    highlight = {
      enable = true,
      disable = { "TelescopePrompt" },
    },
    indent = {
      enable = true,
    },
  }
end

Error displayed

Error executing vim.schedule lua callback: ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:85: Vim(lua):E5108: Error executing lua [string ":lua"]:1: attempt to index global 'setup' (a nil value)
stack traceback:
        [string ":lua"]:1: in main chunk
        [C]: in function '__newindex'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:85: in function 'create_buffer'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:191: in function 'open'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:376: in function <...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:356>
stack traceback:
        [C]: in function '__newindex'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:85: in function 'create_buffer'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:191: in function 'open'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:376: in function <...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:356>
Press ENTER or type command to continue
Error executing vim.schedule lua callback: ...cker/start/nvim-tree.lua/lua/nvim-tree/renderer/init.lua:68: Expected 1 argument
stack traceback:
        [C]: in function 'nvim_win_get_cursor'
        ...cker/start/nvim-tree.lua/lua/nvim-tree/renderer/init.lua:68: in function 'draw'
        .../start/nvim-tree.lua/lua/nvim-tree/actions/find-file.lua:67: in function 'fn'
        ...m/site/pack/packer/start/nvim-tree.lua/lua/nvim-tree.lua:128: in function <...m/site/pack/packer/start/nvim-tree.lua/lua/nvim-tree.lua:123>

https://user-images.githubusercontent.com/43776161/168412702-05cdb58b-cdaa-45f1-830e-132fcb277b51.mov

Neovim version

NVIM v0.8.0-dev+1616-gf6be28c61
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

macOS 12.3

nvim-tree version

82ec79a

Minimal config

I'm sorry, I don't know.

Steps to reproduce

  1. Open Neovim,
  2. nvim-tree is expanded.
  3. In that state, expand tree-sitter and
  4. When I open any file, I get the following error

Expected behavior

No response

Actual behavior

No response

yanskun avatar May 14 '22 05:05 yanskun

view.lua:85 at master does not contain create_buffer. I suspect you may have an older (duplicate?) version of nvim-tree somewhere.

Since this problem appears to be in your configuration, please replicate using the minimal configuration nvt-min.lua as per the bug report instructions. If you cannot replicate, add treesitter and your other plugins to the minimal configuration.

alex-courtis avatar May 14 '22 06:05 alex-courtis

There is nothing this plugin is doing that could conflict with nvim-treesitter, and as an author of both nvim-tree and nvim-treesitter i can assure you that i will never be the case :) Please see alex's response

kyazdani42 avatar May 14 '22 07:05 kyazdani42

@alex-courtis @kyazdani42 Thank you for your reply.

I want to apologize first. It wasn't when I started treesitter that the bug happened, it was telescope.

The following is a config that seems to be reproduced. However, this does not occur.

Because in Minimal config on nvim-tree I didn't know how to start vim with disable_netrw = false, hijack_netrw = false,

This error does not occur when some file is open.

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "kyazdani42/nvim-tree.lua",
      "kyazdani42/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      'nvim-lua/plenary.nvim',
      'nvim-telescope/telescope.nvim',
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {
    disable_netrw = false,
    hijack_netrw = true,
    hijack_cursor = true,
    update_focused_file = {
      enable = true,
      update_cwd = false,
    },
    actions = { open_file = {
        resize_window = true,
      }
    },
    git = {
      enable = true,
      ignore = false,
    }
  }
  require('telescope').setup {}
end

After startup

run :lua require('telescope.builtin').find_files({ hidden = true })

yanskun avatar May 14 '22 14:05 yanskun

After setting hijack_netrw = true, the error no longer occurs.

yanskun avatar May 14 '22 14:05 yanskun

view.lua:85 at master does not contain create_buffer. I suspect you may have an older (duplicate?) version of nvim-tree somewhere.

Try to find out in this direction

yanskun avatar May 14 '22 14:05 yanskun

  1. I removed it from the packer's config and uninstalled it.
  2. Then start vim and make sure nvim-tree doesn't work.
  3. Reinstall nvim-tree and start nvim

The error reappears

yanskun avatar May 14 '22 14:05 yanskun

This error is not create_buffer on line 85, but create_buffer on line 191 in the open function.

So the error itself happens on line 85 in the create_buffer function. Doesn't it mean that?

Error executing vim.schedule lua callback: ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:85: Vim(lua):E5108: Error executing lua [string ":lua"]:1: attempt to index global 'setup' (a nil value)
stack traceback:
        [string ":lua"]:1: in main chunk
        [C]: in function '__newindex'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:85: in function 'create_buffer'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:191: in function 'open'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:376: in function <...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:356>

yanskun avatar May 14 '22 15:05 yanskun

This error is not create_buffer on line 85, but create_buffer on line 191 in the open function.

My mistake, please accept my apologies.

alex-courtis avatar May 15 '22 04:05 alex-courtis

Investigations have shown some strange behaviour at startup: #1270

alex-courtis avatar May 15 '22 05:05 alex-courtis

I cannot replicate this with 0.7.0 release or neovim master 0adc66171 however I am not surprised:

nvim -nu /tmp/nvt-min.lua
:NvimTreeOpen
:lua require('telescope.builtin').find_files({ hidden = true })

Opening with nvim -nu /tmp/nvt-min.lua . has the same result, despite having the netrw buffer open.

The stack is confusing; perhaps the setup function not being found is something unrelated to nvim-tree, maybe a side effect of enumerating buffer options. We are operating in a vim.schedule function here, so race conditions are a possibility.

Plan of attack:

  • @yasudanaoya please move require('telescope').setup {} before nvim-tree's and test
  • Investigate #1270

alex-courtis avatar May 15 '22 05:05 alex-courtis

Let's follow this in #1270, but i'm not sure these behaviors can be properly fixed, nvim startup is quite complicated to manage due to very different user configurations.

kyazdani42 avatar May 15 '22 08:05 kyazdani42

@alex-courtis @kyazdani42 Thank you for your investigation.

I cannot replicate this with 0.7.0 release or neovim master 0adc66171 however I am not surprised:

I agree that it is not due to the neovim version.

yanskun avatar May 15 '22 11:05 yanskun

@yasudanaoya please move require('telescope').setup {} before nvim-tree's and test

I tried it, but the result did not change

yanskun avatar May 15 '22 11:05 yanskun

I get the same error when I run : NvimTreeToggle. Moreover, this fails to execute.

I'm in trouble because it's a command I use often.

yanskun avatar May 17 '22 01:05 yanskun

I tried it, but the result did not change

Thanks for trying it out.

alex-courtis avatar May 17 '22 02:05 alex-courtis

I get the same error when I run : NvimTreeToggle. Moreover, this fails to execute.

I'm in trouble because it's a command I use often.

Thank you for reporting. It is useful to have another.

Please produce an nvt-min.lua and instructions on how to reproduce the issue. See instructions on the bug report form.

alex-courtis avatar May 17 '22 02:05 alex-courtis

Closing due to inactivity.

alex-courtis avatar Sep 03 '22 03:09 alex-courtis