Skip to content
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

BUG: document symbols follow_cursor error #1403

Open
3 tasks done
DDGRCF opened this issue Mar 16, 2024 · 2 comments
Open
3 tasks done

BUG: document symbols follow_cursor error #1403

DDGRCF opened this issue Mar 16, 2024 · 2 comments
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested

Comments

@DDGRCF
Copy link

DDGRCF commented Mar 16, 2024

Did you check docs and existing issues?

  • I have read all the docs.
  • I have searched the existing issues.
  • I have searched the existing discussions.

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
    }
	},
}
@DDGRCF DDGRCF added the bug Something isn't working label Mar 16, 2024
@pysan3
Copy link
Collaborator

pysan3 commented Mar 16, 2024

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!!!

@pysan3 pysan3 added question Further information is requested invalid This doesn't seem right labels Mar 16, 2024
@DDGRCF
Copy link
Author

DDGRCF commented Mar 17, 2024

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"] = "",
			},
		},
	},
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants