GnikDroy / projections.nvim

A map to your filesystem
GNU General Public License v3.0
236 stars 8 forks source link

[bug] The plugin fails to load the stores session, when /home or the workspace path is a symlink #43

Open raphaelahrens opened 9 months ago

raphaelahrens commented 9 months ago

Basic checklist

Expected vs Actual behavior On FreeBSD the /home directory is by default a symlink to /usr/home. If the Session.store function tries to save the session, it calls Session.info and fails because nil was returned. The reason why Session.info fails is because it receives the argument spath which was created by a call to vim.loop.cwd(). vim.loop.cwd() returns the realpath of the current working directory, which on FreeBSD is for ~/projects/abc the path /usr/home/USER/projects/abc.

For reference the code in question https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/session.lua#L17-L37 Here the info function extracts the workspace_path and then compares this path with the path of the workspace set in the configuration. The path of the Workspace is a Path object. In Path.new the given spath is normalized https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/path.lua#L33 The result of calling vim.fs.normalize("~/projects") is "/home/USER/projects".

This lets this condition https://github.com/GnikDroy/projections.nvim/blob/f18a8505f84f45a0fe024cafca5b969447f63cd5/lua/projections/session.lua#L25 fail since "/usr/home/USER/projects" is unequal to "/home/USER/projects".

Of course this can be avoided, when I use the realpath (usr/home/USER/projects) in projections_workspaces.json. But what bothers me is that it failed silently and no session was saved, but I also have no good solution. Ideally Workspace.path should hold the real path and only compare it with a real path, but I don't know if lua/neovim can get the information without relying on shell or libs.

Anyway It is at least something which could be documented.

Environment information

I don't have the tree command on my system and I think this is irrelevant.

To Reproduce Steps to reproduce the behavior:

  1. Create a symlink to the real workspace path
  2. Try to store a session with Session.store for the symlink path
GnikDroy commented 9 months ago

Ok. So, I believe projections needs to handle symlinks correctly. I can perhaps make Path.__eq(a, b) method work with symlinks. I will see what I can do.

In the meanwhile, you can try to see if the dev branch has this issue (likely still there). It tries to avoid vim.loop, which is currently vim.uv in nvim-0.10. This is supposed to be the "new" projections. I will put up a migration notice in a couple of days.

raphaelahrens commented 9 months ago

Thanks for the reply. I have checked with the dev branch (0e36a2d2a9a7ff160618bbe636bc26365d4e0487) there is still the same problem.vim.fn.getcwd() also return the real path.

jorgerojas26 commented 5 months ago

Having the same issue :P