Skip to content

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

Closed
@generic-coder-1

Description

@generic-coder-1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS Windowsspecific to windowsbugSomething isn't workingreproducedIssue confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions