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: directories beginning or ending with symbol cause error in filesystem command set_root #1352

Closed
3 tasks done
bwpge opened this issue Feb 12, 2024 · 1 comment
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@bwpge
Copy link
Contributor

bwpge commented Feb 12, 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)

NVIM v0.9.2

Operating System / Version

Windows 11 22H2

Describe the Bug

On Windows systems, Neo-tree throws an error when using the filesystem source set_root command to set the current working directory when a path segment begins or ends with a symbol (such as (, &, etc.). This type of path is common with web projects that use "dynamic" paths such as foo/(bar)/baz. This is almost the same issue reported in #889, and is part of a bigger issue of properly handling Windows paths.

The Neo-tree view is able to properly update itself to the correct root node, but Neovim will not have the current working directory updated (confirmed with :pwd).

Root cause:
This is a Windows-specific path problem. The set_cwd function uses lcd, tcd, or cd commands to set the working directory (see snippet below). On Windows the argument passed to these commands is having the path separator \ treated as an escape character for a symbol such as \(. The path separator is lost and the final path is treated as foo(bar) instead of foo\(bar).

if state.path ~= cwd then
if winid > 0 then
vim.cmd("lcd " .. state.path)
elseif tabnr > 0 then
vim.cmd("tcd " .. state.path)
else
vim.cmd("cd " .. state.path)
end

Screenshots, Traceback

image

E5108: Error executing lua: vim/_editor.lua:341: nvim_exec2(): Vim(tcd):E344: Can't find directory "X:\foo(bar)" in cdpath
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua:341: in function 'cmd'
        ...data/lazy/neo-tree.nvim/lua/neo-tree/sources/manager.lua:357: in function 'set_cwd'
        ...y/neo-tree.nvim/lua/neo-tree/sources/filesystem/init.lua:160: in function '_navigate_internal'
        ...o-tree.nvim/lua/neo-tree/sources/filesystem/commands.lua:231: in function <...o-tree.nvim/lua/neo-tree/sources/filesystem/commands.lua:224>

Steps to Reproduce

Note that these steps must be followed on a Windows system to reproduce the issue.

  1. Use repro config below to open Neovim and install Neo-tree: nvim -u repro.lua (close Neovim)
  2. Create a sample directory containing no symbols (e.g., foo)
  3. Create a nested directory beginning and/or ending with symbols (e.g., foo/(bar))
  4. Open Neovim to foo with nvim -u repro.lua ./foo
  5. Open Neo-tree with :Neotree filesystem toggle left
  6. Select (bar) directory and press . to set root and observe error
  7. Hit <CR> and observe Neo-tree properly updates the view
  8. Run :pwd and observe Neovim's working directory is not correctly set

Expected Behavior

Neo-tree is able to set neovim current working directory (cd, lcd, tcd) without errors on Windows systems.

Your Configuration

-- lazy
local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

-- load neo-tree with default options
require("lazy").setup({
    {
        "nvim-neo-tree/neo-tree.nvim",
        branch = "v3.x",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-tree/nvim-web-devicons",
            "MunifTanjim/nui.nvim",
        },
        opts = {},
    },
})
@bwpge bwpge added the bug Something isn't working label Feb 12, 2024
@bwpge
Copy link
Contributor Author

bwpge commented Feb 16, 2024

Fixed by #1353

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant