nvim-neo-tree / neo-tree.nvim

Neovim plugin to manage the file system and other tree like structures.
MIT License
3.36k stars 203 forks source link

BUG: Error creating item for <project folder> #1298

Open nappalm opened 6 months ago

nappalm commented 6 months ago

Did you check docs and existing issues?

Neovim Version (nvim -v)

v0.8.0-1210-gd367ed9b2

Operating System / Version

Windows

Describe the Bug

When I open my project it gives me the following error: BUG: Error creating item for <project folder>

I currently use astrovim

Screenshots, Traceback

image

Steps to Reproduce

  1. Open terminal
  2. Go to project folder
  3. nvim .

Expected Behavior

Use nvim without errors

Your Configuration

Astrovim init.lua
Askerad commented 5 months ago

It seems I have exactly the same problem. Also using astronvim on windows. Neo Tree starts spewing errors, it seems one error for each item in the folder. it can happen when any action is performed, but this far i haven't found any way to reproduce it every time. It happens like 2/3rds of the time I do anything.

I'm also available if logs or anything is needed.

Edit : I've had this problem for like a month, didn't raise an issue cuz I thought something was off with my config. Dunno if that can help to find the cause

miversen33 commented 5 months ago

I am not familiar with astronvim, could either of you dig into the astro config and share the relevant configuration for neo-tree?

nappalm commented 5 months ago

@miversen33 here you have the neo-tree configuration:

neo-tree.lua

miversen33 commented 5 months ago

I am unable to reproduce this on later versions of neovim on linux. I will have to get onto my windows machine later and pull down neovim 8.1 to see if I can reproduce this there.

Here is the reproduction config I am using.

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
      {
        "nvim-neo-tree/neo-tree.nvim",
        branch = "main", -- HACK: force neo-tree to checkout `main` for initial v3 migration since default branch has changed
        dependencies = { "MunifTanjim/nui.nvim" },
        cmd = "Neotree",
        init = function() vim.g.neo_tree_remove_legacy_commands = true end,
        opts = function()
            local utils = require "astronvim.utils"
            local get_icon = utils.get_icon
            return {
                auto_clean_after_session_restore = true,
                close_if_last_window = true,
                sources = { "filesystem", "buffers", "git_status" },
                source_selector = {
                    winbar = true,
                    content_layout = "center",
                    sources = {
                        { source = "filesystem", display_name = get_icon("FolderClosed", 1, true) .. "File" },
                        { source = "buffers", display_name = get_icon("DefaultFile", 1, true) .. "Bufs" },
                        { source = "git_status", display_name = get_icon("Git", 1, true) .. "Git" },
                        { source = "diagnostics", display_name = get_icon("Diagnostic", 1, true) .. "Diagnostic" },
                    },
                },
                default_component_configs = {
                    indent = { padding = 0 },
                    icon = {
                        folder_closed = get_icon "FolderClosed",
                        folder_open = get_icon "FolderOpen",
                        folder_empty = get_icon "FolderEmpty",
                        folder_empty_open = get_icon "FolderEmpty",
                        default = get_icon "DefaultFile",
                    },
                    modified = { symbol = get_icon "FileModified" },
                    git_status = {
                        symbols = {
                            added = get_icon "GitAdd",
                            deleted = get_icon "GitDelete",
                            modified = get_icon "GitChange",
                            renamed = get_icon "GitRenamed",
                            untracked = get_icon "GitUntracked",
                            ignored = get_icon "GitIgnored",
                            unstaged = get_icon "GitUnstaged",
                            staged = get_icon "GitStaged",
                            conflict = get_icon "GitConflict",
                        },
                    },
                },
                commands = {
                    system_open = function(state)
                        -- TODO: just use vim.ui.open when dropping support for Neovim <0.10
                        (vim.ui.open or require("astronvim.utils").system_open)(state.tree:get_node():get_id())
                    end,
                    parent_or_close = function(state)
                        local node = state.tree:get_node()
                        if (node.type == "directory" or node:has_children()) and node:is_expanded() then
                            state.commands.toggle_node(state)
                        else
                            require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
                        end
                    end,
                    child_or_open = function(state)
                        local node = state.tree:get_node()
                        if node.type == "directory" or node:has_children() then
                            if not node:is_expanded() then -- if unexpanded, expand
                                state.commands.toggle_node(state)
                            else -- if expanded and has children, seleect the next child
                                require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
                            end
                        else -- if not a directory just open it
                            state.commands.open(state)
                        end
                    end,
                    copy_selector = function(state)
                        local node = state.tree:get_node()
                        local filepath = node:get_id()
                        local filename = node.name
                        local modify = vim.fn.fnamemodify

                        local vals = {
                            ["BASENAME"] = modify(filename, ":r"),
                            ["EXTENSION"] = modify(filename, ":e"),
                            ["FILENAME"] = filename,
                            ["PATH (CWD)"] = modify(filepath, ":."),
                            ["PATH (HOME)"] = modify(filepath, ":~"),
                            ["PATH"] = filepath,
                            ["URI"] = vim.uri_from_fname(filepath),
                        }

                        local options = vim.tbl_filter(function(val) return vals[val] ~= "" end, vim.tbl_keys(vals))
                        if vim.tbl_isempty(options) then
                            utils.notify("No values to copy", vim.log.levels.WARN)
                            return
                        end
                        table.sort(options)
                        vim.ui.select(options, {
                            prompt = "Choose to copy to clipboard:",
                            format_item = function(item) return ("%s: %s"):format(item, vals[item]) end,
                        }, function(choice)
                            local result = vals[choice]
                            if result then
                                utils.notify(("Copied: `%s`"):format(result))
                                vim.fn.setreg("+", result)
                            end
                        end)
                    end,
                    find_in_dir = function(state)
                        local node = state.tree:get_node()
                        local path = node:get_id()
                        require("telescope.builtin").find_files {
                            cwd = node.type == "directory" and path or vim.fn.fnamemodify(path, ":h"),
                        }
                    end,
                },
                window = {
                    width = 30,
                    mappings = {
                        ["<space>"] = false, -- disable space until we figure out which-key disabling
                        ["[b"] = "prev_source",
                        ["]b"] = "next_source",
                        F = utils.is_available "telescope.nvim" and "find_in_dir" or nil,
                        O = "system_open",
                        Y = "copy_selector",
                        h = "parent_or_close",
                        l = "child_or_open",
                        o = "open",
                    },
                    fuzzy_finder_mappings = { -- define keymaps for filter popup window in fuzzy_finder_mode
                        ["<C-j>"] = "move_cursor_down",
                        ["<C-k>"] = "move_cursor_up",
                    },
                },
                filesystem = {
                    follow_current_file = { enabled = true },
                    hijack_netrw_behavior = "open_current",
                    use_libuv_file_watcher = true,
                },
                event_handlers = {
                    {
                        event = "neo_tree_buffer_enter",
                        handler = function(_) vim.opt_local.signcolumn = "auto" end,
                    },
                },
            }
        end,
    }

  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {
    -- Your config here
    -- ...
  },
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

@nappalm or @Askerad can either of you test this configuration? You will want to test it with the following command

$ nvim --clean -u repro.lua .

Where repro.lua is the above reproduction config and . is a directory where you can reproduce the issue with astronvim

nappalm commented 5 months ago

@miversen33 It works well for me using what you command

miversen33 commented 5 months ago

Sounds like this might be something to kick up to astronvim then as removing astro from the equation and using the exact same config worked

nappalm commented 5 months ago

It seems a little strange to me that it is due to the astrovim configuration, since I have returned to a version that I know worked perfectly, except that now a neo-tree error appears. Queer 🤔

miversen33 commented 5 months ago

I agree that is is a bit strange. However taking their exact config for neo-tree, stripping astronvim out and running it seems to work for both you and me. This would indicate that Astro is doing something that neo-tree doesn't like and it is happening outside the neo-tree configuration. I am not really interested in picking through a distro's configurations to try and figure that out. I would open an issue with them, tag this issue and see if they can help you diagnose the problem there as it appears to be related to something within Astro as opposed to a bug in neo-tree.nvim

Askerad commented 5 months ago

@miversen33 I also tried that config and all errors disappeared

Askerad commented 5 months ago

I figured out every version until 3.14 works perfectly fine. I took a brief look at 3.14's changelog and I suppose commit 77d9f48 broke something

i'll try to mess with that and if I get any result i'll send a PR

Workaround for now if people in the future find this : Rollback Neo-Tree to 3.13.0

Askerad commented 5 months ago

Erratum, I don't quite know which commit broke the thing, tinkering with it now, discard the previous guess

mehalter commented 5 months ago

@Askerad git bisect is a great command if you know an old working version and are looking for an offending commit