nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use relative path to find file

kuznetsss opened this issue · comments

I think using absolute path in searching for file is wrong because there could be symlinks.

For example in my system I open file from home directory:
~$ nvim Documents/vimwiki/index.md
But Documents is symlink Documents -> /mnt/Data/home_user/Documents
So the real absolute file path is /mnt/Data/home_user/Documents/vimwiki/index.md which nvim-tree tries to find being in /home/user directory. So the file can't be found.

I think it would be better to search file by relative path from nvim's cwd.

commented

you are correct, we should be searching by relative path. You could open a PR if i didn't fix this by the end of the day.

Current behaviour:

mkdir /tmp/root1
mkdir /tmp/root2
cd /tmp/root2
mkdir dir3
touch dir3/file31
cd /tmp/root1
mkdir dir1
mkdir dir2
touch file1
touch dir1/file11
cd /tmp/root1
ln -s /tmp/root2/dir3 dir31
ln -s ../root2/dir3 dir32
nvim -nu /tmp/nvt-min.lua

Success:
dir1/file11
dir31/file31
dir32/file31
dir1
dir2
dir31
dir32
file1

Fail:
file11
file31

It appears that the issues with the relative path of symlinks is resolved, be they absolute or relative. Search is successful for file11 and file31 if we C-] into dir1 dir31 or dir32 first.

This does highlight a problem, which might be in my understanding: we can only search for files/dirs which match a path under cwd, not for files/dirs of a name.

Proposal: search matches full file/dir names under cwd, as per :find behaviour.

PR #837

There are still some lingering issues around symlinked rel vs absolute:

find-file absolute path: node will be opened, however it will not be focussed
find-file path relative to cwd: node will not be found