nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.17k stars 611 forks source link

[On windows] Root of nvim-tree changed unexpectedly and buffer not listed by telescope #2961

Open ljie-PI opened 3 days ago

ljie-PI commented 3 days ago

Description

With this change (https://github.com/nvim-tree/nvim-tree.lua/commit/45a93d99794fff3064141d5b3a50db98ce352697#diff-eeb21711fceb0abba1450bd1adcbecc4fd90cf8ce4d5d7a8233f886c1bebd41fR375), I found it doesn't work well on Windows for 2 cases:

  1. When I open a file from nvim-tree, the root of nvim-tree window changed to the directory of that file
  2. The buffer of this file can not be listed when I use telescope command <cmd>lua require('telescope.builtin').buffers(require('telescope.themes').get_dropdown{previewer = false})<cr>

Neovim version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

Windows 11

Windows variant

Command Prompt

nvim-tree version

2a268f6

Clean room replication

I'm on windows so don't have /tmp/nvt-min.lua.

Pasting my config here:

local status_ok, nvim_tree = pcall(require, "nvim-tree")
if not status_ok then
  return
end

local api_status_ok, nvim_tree_api = pcall(require, "nvim-tree.api")
if not api_status_ok then
  return
end

local function customized_on_attach(bufnr)
  local function opts(desc)
    return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
  end
  -- default mappings
  nvim_tree_api.config.mappings.default_on_attach(bufnr)
  -- custom mappings
  vim.keymap.set('n', 'c', nvim_tree_api.tree.change_root_to_node, opts('CD'))
  vim.keymap.set('n', 'l', nvim_tree_api.node.open.edit, opts('Open'))
  vim.keymap.set('n', '<CR>', nvim_tree_api.node.open.edit, opts('Open'))
  vim.keymap.set('n', 'o', nvim_tree_api.node.open.edit, opts('Open'))
  vim.keymap.set('n', 'h', nvim_tree_api.node.navigate.parent_close, opts('Close Directory'))
  vim.keymap.set('n', 'v', nvim_tree_api.node.open.vertical, opts('Open: Vertical Split'))
end

local keymap = vim.api.nvim_set_keymap
keymap("n", "<leader>e", ":NvimTreeToggle<CR>", { noremap = true, silent = true })

nvim_tree.setup {
  update_focused_file = {
    enable = true,
    update_cwd = true,
  },
  actions = {
    change_dir = {
      enable = false,
    }
  },
  renderer = {
    root_folder_modifier = ":t",
    icons = {
      glyphs = {
        default = "",
        symlink = "",
        folder = {
          arrow_open = "",
          arrow_closed = "",
          default = "",
          open = "",
          empty = "",
          empty_open = "",
          symlink = "",
          symlink_open = "",
        },
        git = {
          unstaged = "",
          staged = "S",
          unmerged = "",
          renamed = "➜",
          untracked = "U",
          deleted = "",
          ignored = "◌",
        },
      },
    },
  },
  diagnostics = {
    enable = true,
    show_on_dirs = true,
    icons = {
      hint = "",
      info = "",
      warning = "",
      error = "",
    },
  },
  view = {
    width = 45,
    side = "left",
  },
  on_attach = customized_on_attach,
}

Steps to reproduce

  1. cd C:\Users\${username}\AppData\Local\nvim-data\site\pack\packer\start\nvim-tree.lua
  2. nvim .
  3. move to the file lua\nvim-tree\actions\root\change-dir.lua and open it image
  4. look at the nvim-tree window, the root changes to lua\nvim-tree\actions\root image
  5. and call the list buffer function in telescope, nothing shows up image

Expected behavior

No response

Actual behavior

No response

ljie-PI commented 3 days ago

Added some debugging messages as follows: image

And got these messages: image

The vim_cmd is under path and should not change root, but now it seems not because of "/" doesn't match "\"

ljie-PI commented 3 days ago

If I use telescope to open this file, everything goes well: image image

ljie-PI commented 2 days ago

I proposed a PR(https://github.com/nvim-tree/nvim-tree.lua/pull/2962) to revert previous change and fix the current issues (which I think are more common and more severe)

ljie-PI commented 2 days ago

I found the [issue #2862 is more likely an issue of neovim instead of nvim-tree.

In issue #2862, LandonHarter is trying to open C:\Users\${myname}\AppData\Local\nvim-data\site\pack\packer\start\nvim-tree.lua\app\\(pages\)\\(app\)\document\[id]\page.tsx. Sharing some findings:

So the previous code (before the fix #2862 ) is correct. But the neovim itself doesn't work well if the "[" and "]" come after "(" and ")".

Previous fix used a work around to change "\" to "/" to make this case work, but broke some more common features. I think #2862 is a much more niche case. So can we first revert the PR?

ljie-PI commented 2 days ago

I think for later release, we can deal with this specific case separately.

ljie-PI commented 2 days ago

Now also made changes to fix #2862. It works for all cases (open file correctly, root not changed unexpectedly, telescope can list all buffers) image

But telescope could not correctly open the files with both "()" and "[]" in path. May need changes in telescope or neovim itself to get that fixed.

ljie-PI commented 2 days ago

linke the PR: https://github.com/nvim-tree/nvim-tree.lua/pull/2962