Skip to content

Root of nvim-tree changed unexpectedly when jump to file in another directory with LSP on Windows #2981

Closed
@ljie-PI

Description

@ljie-PI

Description

On windows, when I use LSP go to definition in another directory, the root of nvim-tree changed to that directory, even when the destination directory is a sub-directory of current directory.

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

82ab19e

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. Open a project with nvim
  2. Invoke "go to definition" provided by LSP, e.g.
image 3. Notice the root of the nvim-tree windows has changed to the subdirectory. image

Expected behavior

The root of nvim-tree doesn't change frequently if the directories are in the same project.

Actual behavior

root of the nvim-tree windows has changed

Metadata

Metadata

Assignees

Labels

OS Windows PowerShellspecific to windows powershellbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions