nvim-neo-tree / neo-tree.nvim

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

BUG: document symbols follow_cursor error #1403

Open DDGRCF opened 8 months ago

DDGRCF commented 8 months ago

Did you check docs and existing issues?

Neovim Version (nvim -v)

0.9.5

Operating System / Version

Ubuntu22.04

Describe the Bug

vim.keymap.set("n", "<Leader>fd",
  function() vim.cmd("Neotree toggle show document_symbols") end,
  vim.tbl_extend("force", opt, { desc = "[Neotree] open document_symbols" }))

After, I use above command, the error popup like following:

debounce  document_symbols_follow  error:  .../neo-tree/sources/document_symbols/lib/symbols_utils.lua:86: attempt to index local 'tree' (a nil value)

Screenshots, Traceback

message like above

Steps to Reproduce

  1. <Leader>fd

Expected Behavior

no error

Your Configuration

local neo_tree_config = {
    open_files_do_not_replace_types = {
        "terminal",
        "qf",
        "trouble",
        "TelescopePrompt",
    },
    sources = {
        "filesystem",
        "document_symbols",
        "git_status",
    },
  window = {
    mappings = keymappings.window.mappings,
  },
    filesystem = {
    commands = keymappings.filesystem.commands,
        bind_to_cwd = false, -- true creates a 2-way binding between vim's cwd and neo-tree's root
        follow_current_file = {
            enabled = true,
            leave_dirs_open = false,
        },
        use_libuv_file_watcher = true,
    window = {
      mappings = keymappings.filesystem.window.mappings,
      fuzzy_finder_mappings = keymappings.filesystem.window.fuzzy_finder_mappings
    }
    },
    document_symbols = {
        follow_cursor = true,
    commands = keymappings.document_symbols.commands,
    window = {
      mappings = keymappings.document_symbols.window.mappings
    }
    },
    source_selector = {
        winbar = true,
        statusline = false,
        sources = {
            {
                source = "filesystem",
                display_name = " 󰈚 Files ",
            },
            {
                source = "git_status",
                display_name = " 󰊢 Git ",
            },
            {
                source = "document_symbols",
                display_name = "  Symbols ",
            },
        },
    },
    git_status = {
        symbols = require("plugin-config.gitsigns").icons,
    window = {
      mappings = keymappings.git_status.mappings
    }
    },
}
pysan3 commented 8 months ago

Does this happen for every language and every time?

I cannot reproduce this with lua_ls.

On top of that, your repro config contains variables such as keymappings that I have no clue what it is. Please give us a reproducible config!!!

DDGRCF commented 8 months ago

Does this happen for every language and every time?

I cannot reproduce this with lua_ls.

On top of that, your repro config contains variables such as keymappings that I have no clue what it is. Please give us a reproducible config!!!

yeh! in my case, it happened in clangd\pyright\lua_ls most each time. And I find that follow_cursor=true cause this error. here is my keymappings:

pluginKeys.neoTree = {
    window = {
        mappings = {
            ["<space>"] = "",
            ["I"] = "focus_preview",
            ["P"] = { "toggle_preview", config = { use_float = false, use_image_nvim = true } },
            ["<"] = "prev_source",
            [">"] = "next_source",
            ["z"] = "close_all_nodes",
            ["Z"] = "expand_all_nodes",
      ["y"] = "",
      ["Y"] = "",
      ["l"] = "",
      ["h"] = ""
        },
    },
    filesystem = {
    commands = {
            my_close_node = function(state)
                local node = state.tree:get_node()
                if node.type == "directory" and node:is_expanded() then
                    require("neo-tree.sources.filesystem").toggle_directory(state, node)
                else
                    require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
                end
            end,
            my_open_node = function(state)
                local node = state.tree:get_node()
                if node.type == "directory" then
                    if not node:is_expanded() then
                        require("neo-tree.sources.filesystem").toggle_directory(state, node)
                    elseif node:has_children() then
                        require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
                    end
                end
            end,
            my_copy_filepath_to_clipboard = function(state)
                local node = state.tree:get_node()
                local filepath = node:get_id()
                local filename = node.name
                local modify = vim.fn.fnamemodify

                local results = {
                    filepath,
                    modify(filepath, ":."),
                    modify(filepath, ":~"),
                    filename,
                    modify(filename, ":r"),
                    modify(filename, ":e"),
                }
        local plugin = "Neo-tree"
                vim.ui.select({
                    "[1] Absolute path: " .. results[1],
                    "[2] Path relative to CWD: " .. results[2],
                    "[3] Path relative to HOME: " .. results[3],
                    "[4] Filename: " .. results[4],
                    "[5] Filename without extension: " .. results[5],
                    "[6] Extension of the filename: " .. results[6],
                }, { prompt = "Choose to copy to clipboard:" }, function(choice)
                    if choice then
                        local i = tonumber(choice:sub(2, 2))
                        if i then
                            local result = results[i]
                            vim.fn.setreg('"', result)
              vim.notify("Copied: ".. result, "info", { title = plugin })
                        else
              vim.notify("Invalid selection", "info", { title = plugin })
                        end
                    else
            vim.notify("Selection cancelled", "info", { title = plugin })
                    end
                end)
            end,
      my_copy_file_to_clipboard = function(state)
        require("neo-tree.sources.common.commands").copy_to_clipboard(state)
      end,
      my_cut_file_to_clipboard = function(state)
        require("neo-tree.sources.common.commands").cut_to_clipboard(state)
      end
    },
        window = {
      mappings = {
        ["y"] = "my_copy_file_to_clipboard",
        ["Y"] = "my_copy_filepath_to_clipboard",
        ["x"] = "my_cut_file_to_clipboard",
        ["h"] = "my_close_node",
        ["l"] = "my_open_node"
      },
            fuzzy_finder_mappings = {
                ["<down>"] = "move_cursor_down",
                ["<C-j>"] = "move_cursor_down",
                ["<up>"] = "move_cursor_up",
                ["<C-k>"] = "move_cursor_up",
            },
        },
    },
    git_status = {
        window = {
            mappings = {
                ["A"] = "git_add_all",
                ["gu"] = "git_unstage_file",
                ["ga"] = "git_add_file",
                ["gr"] = "git_revert_file",
                ["gc"] = "git_commit",
                ["gp"] = "git_push",
                ["gg"] = "git_commit_and_push",
                ["o"] = { "show_help", nowait = false, config = { title = "Order by", prefix_key = "o" } },
                ["oc"] = { "order_by_created", nowait = false },
                ["od"] = { "order_by_diagnostics", nowait = false },
                ["om"] = { "order_by_modified", nowait = false },
                ["on"] = { "order_by_name", nowait = false },
                ["os"] = { "order_by_size", nowait = false },
                ["ot"] = { "order_by_type", nowait = false },
        ["z"] = "",
        ["Z"] = "",
            },
        },
    },
    document_symbols = {
    commands = {
      my_open_node = function(state)
        local node = state.tree:get_node()
        if not node:is_expanded() then
          require("neo-tree.sources.common.commands").toggle_node(state)
        else
          require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
        end
      end,
      my_close_node = function(state)
        local node = state.tree:get_node()
        if node:is_expanded() then
          require("neo-tree.sources.common.commands").toggle_node(state)
        else
          require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
        end
      end,
    },
        window = {
            mappings = {
        ["l"] = "my_open_node",
        ["h"] = "my_close_node",
        ["z"] = "",
        ["Z"] = "",
            },
        },
    },
}