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

Race Condition With open_on_setup

Open alex-courtis opened this issue 2 years ago • 6 comments

Description

Inconsistent behaviour is occurring with the following options:

open_on_setup
open_on_setup_file
ignore_buffer_on_setup
disable_netrw
hijack_netrw

Neovim version

NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Linux 5.17.5-arch1-1

nvim-tree version

7293f8d

Minimal config

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
    },
    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 {
	  open_on_setup = true,
	  open_on_setup_file = false,
	  ignore_buffer_on_setup = true,
	  disable_netrw = false,
	  hijack_netrw = true,
  }
end

Steps to reproduce

vim -nu /tmp/nvt-min.lua <file> sometimes opens the tree nvim -nu /tmp/nvt-min.lua sometimes opens the tree nvim -nu /tmp/nvt-min.lua . sometimes opens netrw

Expected behavior

No response

Actual behavior

No response

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

Alternatives like:

    open_on_setup = false,
    open_on_setup_file = true,
    ignore_buffer_on_setup = true,

Show similarly inconsistent behaviour.

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

See #1262

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

Some things we have to note with opening on setup:

  • users with lazy-loading
  • users using a rooter plugin (which might itself be lazy loaded somehow)
  • users with open on setup enabled
  • users with open on setup enabled, opening nvim to commit, or read a manpage export MANPAGER="nvim +Man!"
  • users without open on setup enabled, with hijack directories enabled, opening a directory nvim $HOME
  • users without open on setup enabled, with open file enabled, opening a file nvim file.lua

There might be other cases too, that's why it's quite complicated to handle this altogether.

  • hijack directories will hijack netrw windows because these are directories (it's stated in the docs i believe).
  • when a user is opening nvim tree when nvim starts up, nvim tree will run before nvim is loaded (filename, current cwd and such will be wrong), that's why we have to schedule the call.
  • running nvim tree without hijacking netrw can cause very strange behaviors, because you will actually have 2 file explorers running, and thus user config options for nvim tree can very much make nvim unstable.

I'm pretty sure there are many other edge cases during nvim startup that i cannot remember right now, but that's why managing this feature is quite a challenge.

kyazdani42 avatar May 15 '22 09:05 kyazdani42

I'm pretty sure there are many other edge cases during nvim startup that i cannot remember right now, but that's why managing this feature is quite a challenge.

Yes. This is not something we can fix quickly or easily. I opened this mainly to track the behaviour I have noticed.

There are no outstanding issues besides perhaps #1262. Let's wait until we have an urgent issue or more reports of such behaviour.

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

https://github.com/kyazdani42/nvim-tree.lua/issues/286#issuecomment-1208996663 showed good results setting g:loaded_netrw before anything else.

Documentation to do the above on problems may be enough. Removing them from setup is also an option; it is just not reliable.

alex-courtis avatar Aug 14 '22 02:08 alex-courtis

Added doc to eagerly disable netrw: https://github.com/kyazdani42/nvim-tree.lua/commit/fb8735e96cecf004fbefb086ce85371d003c5129

alex-courtis avatar Sep 11 '22 01:09 alex-courtis

Setup is now more stable via a variety of bugfixes.

Eager disable of netrw appears successful.

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

Not consistent. When opening in a massive repo. Adding logging.

9914780

Error executing vim.schedule lua callback: .../share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/utils.lua:120: attempt to index local 'explorer' (a nil value)
stack traceback:
        .../share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/utils.lua:120: in function 'get_node_from_path'
        ...im/vundle/nvim-tree.lua/lua/nvim-tree/explorer/watch.lua:44: in function 'refresh_path'
        ...im/vundle/nvim-tree.lua/lua/nvim-tree/explorer/watch.lua:68: in function 'callback'
        .../share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/utils.lua:400: in function <.../share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/utils.lua:399>
        [C]: in function 'wait'
        ...e/nvim/vundle/nvim-tree.lua/lua/nvim-tree/git/runner.lua:126: in function '_wait'
        ...e/nvim/vundle/nvim-tree.lua/lua/nvim-tree/git/runner.lua:145: in function 'run'
        ...are/nvim/vundle/nvim-tree.lua/lua/nvim-tree/git/init.lua:136: in function 'load_project_status'
        ...vim/vundle/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:29: in function '_load'
        ...vim/vundle/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:23: in function 'new'
        ...l/share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/core.lua:15: in function 'init'
        ...al/share/nvim/vundle/nvim-tree.lua/lua/nvim-tree/lib.lua:119: in function 'open'
        ....local/share/nvim/vundle/nvim-tree.lua/lua/nvim-tree.lua:274: in function 'on_enter'
        ....local/share/nvim/vundle/nvim-tree.lua/lua/nvim-tree.lua:761: in function <....local/share/nvim/vundle/nvim-tree.lua/lua/nvim-tree.lua:760>

alex-courtis avatar Oct 15 '22 00:10 alex-courtis

Unfortunately this change has been reverted due to many regressions: #1668

A new mechanism to control startup behaviour is under way: #1669

alex-courtis avatar Oct 18 '22 00:10 alex-courtis