Skip to content

Issue on windows when trying to iterate through the Appliction Data directory(not the AppData directory)(Confusing I know) #2866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
generic-coder-1 opened this issue Aug 13, 2024 · 6 comments · Fixed by #2874
Labels
bug Something isn't working OS Windows specific to windows reproduced Issue confirmed

Comments

@generic-coder-1
Copy link

generic-coder-1 commented Aug 13, 2024

Description

Let me preface this with:
I barely know what I'm doing. I installed neovim yesterday and just started NvChad today. I am by no metric an expert in anything vim, neovim, lua, git, github, or windows related. I'm just trying to get this to work on my machine.

Basically the problem is when nvim-tree is iterating through the files from where I called nvim in the terminal which is the directory of the current user. In the user directory(directory of the user not a directory called user) there is another directory called "Application Data"(which I didn't even know existed before this issue)(not to be confused with the AppData directory). When nvim-tree hits the Application Data directory it crashes with this ugly error:

Error executing Lua callback: ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: Vim:Error executing Lua callback: ...ta/lazy/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:63: attempt to perform arithmetic on a nil value                                                                                                                                            stack traceback:                                                                                                                                                                   
    ...ta/lazy/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:63: in function 'populate_children'                                                 
    ...ta/lazy/nvim-tree.lua/lua/nvim-tree/explorer/explore.lua:85: in function 'explore'                                                                   
    ...-data/lazy/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:62: in function '_load'                                                                    
    ...-data/lazy/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:53: in function 'new'                                                                 
    ...ocal/nvim-data/lazy/nvim-tree.lua/lua/nvim-tree/core.lua:19: in function 'init'                                                                
    ...Local/nvim-data/lazy/nvim-tree.lua/lua/nvim-tree/lib.lua:261: in function 'open'                                                            
    ...lazy/nvim-tree.lua/lua/nvim-tree/actions/tree/toggle.lua:48: in function 'toggle'                                                                 
    .../nvim-data/lazy/nvim-tree.lua/lua/nvim-tree/commands.lua:36: in function <.../nvim-data/lazy/nvim-tree.lua/lua/nvim-tree/commands.lua:35>                                               
   [C]: in function 'cmd'                                                                                                                                                                      
    ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>                                        
stack traceback:                                                                                                                                                                      
  [C]: in function 'cmd'                                                                                                                                                                      
  ...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:48: in function <...l/nvim-data/lazy/lazy.nvim/lua/lazy/core/handler/cmd.lua:16>

After some debugging(and copious amounts of print statments) I was able to figure out that in this part of explore.lua:

for reason, value in pairs(FILTER_REASON) do
  if filter_reason == value then
    node.hidden_stats[reason] = node.hidden_stats[reason] + 1
  end
end

the variable reason ends up being FILTER_REASON.none. Fortunately, I was able to find a fix(I have no clue whether or not this is an actual fix or a "fix" that will end up breaking something else later down the line but works for now). Shorty above the previous code snippet, in this section:

node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
    git = 0,
    buf = 0,
    dotfile = 0,
    custom = 0,
    bookmark = 0,
})

If you add none = 0, it ends up working just fine. I would try and make a pull request but 1) I don't know how to and 2) It's about 11:30 PM and I don't have the energy to figure out how

More on the Application Data directory

After doing some research, I realize that this directory is weird. It doesn't show up in the default windows file explorer(even when you make hidden folders visible) or with the dir command(windows version of ls)(I was able to get it to show up with ls from Git tho). Apparently it's there for some backwards compatibility reason as stated here(It's for windows 10 but I assume it's the exact same for windows 11).

Neovim version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

Windows 11

Windows variant

Command Prompt

nvim-tree version

ad0b95d

Clean room replication

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

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",
      "nvim-tree/nvim-tree.lua",
      "nvim-tree/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 {}
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
  pattern = "lua",
  callback = function()
    vim.lsp.start { cmd = { "lua-language-server" } }
  end,
})
]]

Steps to reproduce

  1. open neovim from user directory with nvim -nu .\AppData\Local\nvim-data\tmp\nvt-min.lua(AppData not Application Data)
  2. Run NvimTreeOpen
  3. receive error and enjoy

Expected behavior

Opens up the folder tree sidebar

Actual behavior

image

@generic-coder-1 generic-coder-1 added the bug Something isn't working label Aug 13, 2024
@Shaobin-Jiang
Copy link

Happens for me as well on Windows 11. It occurs when I try to switch to C:/Users/<username>/AppData/Local/, with exactly the same errors as above. I did some extra testing, by adding printing the cwd and name after this line:

  while true do
    local name, t = vim.loop.fs_scandir_next(handle)
    if not name then
      break
    end

    local abs = utils.path_join { cwd, name }
    print(cwd, name)
    -- The rest of the code here
  end

The error above appears just after the name "Application Data` is printed. A closer look tells me I have only limited access to this directory, which I presume is why things do not work properly here?

Shaobin-Jiang added a commit to Shaobin-Jiang/nvim-tree.lua that referenced this issue Aug 15, 2024
Fixes nvim-tree#2866. The original code, while detecting whether Windows NT
allows the dir to be iterated through, will go to the other branch
of the if...else... statement, which is intended for cases when
filter_reason is not none. Simply moving `is_fs_event_capable` into the
first branch should solve the problem.
@alex-courtis alex-courtis added reproduced Issue confirmed OS Windows specific to windows labels Aug 17, 2024
@aasril
Copy link

aasril commented Aug 18, 2024

Affecting me as well (Windows 11, Neovim v0.10.1, Powershell 7.4.4).

Meanwhile I revert back to Nvim-Tree v1.5.0

@alex-courtis
Copy link
Member

@generic-coder-1 @aasril I'd be grateful if you tested a fix branch #2874

cd /path/to/nvim-tree.lua
git pull
git checkout 2866-windows-explorer-ignore-unenumerable-directories

When you're finished testing:

git checkout master

@aasril
Copy link

aasril commented Aug 18, 2024

@alex-courtis, sure! I checked out the branch and I don't get the error anymore.

err_master
no_err

@generic-coder-1
Copy link
Author

Ditto! Works perfectly on my end.

@jinzhongjia
Copy link

I think this problem has fixed, that also works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OS Windows specific to windows reproduced Issue confirmed
Projects
None yet
5 participants