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

fix(find): Use full path instead of real path to avoid symlinks #368

Merged

Conversation

bltavares
Copy link
Contributor

When a respository is in a symlink-ed path (eg: larger hard-drive for projects w/ small SDD for OS), calling nio.uv.fs_realpath will perform symlink resolution.

local err, real = nio.uv.fs_realpath(path)

Given the following scenario, nvim will run buffers with the home-dir path, instead of the resolved symlink path.

ln -s $HOME/projects /mnt/largehdd/projets
cd $HOME/projects/my_project
nvim .

Then, the following lua code will result on 2 different filenames.

local path_name = vim.api.nvim_buf_get_name(0) -- /home/me/projects/my_project/src/lib.rs
neotest.lib.files.path.real(path_name) -- /mnt/largehdd/projects/my_project/src/lib.rs

When sending the fully resolved symlinked path to a plugin, the path_name on the plugin will not match any of the path names of buffers, if they perform a search or use an external process.

This causes issues on rustaceanvim LSP-based test detection, which requires the file to be on the root of the LSP runner directory, and thus, the file_path sent is rejected.

This commit changes the login of neotest.lib.files.path.real to use the vim function for resolving the full path name, followed by an exists check, as there is 1 function usage that requires the error checking present.

Now, the following code is the same, and resolves the No tests found! when running :Neotest run file using rustaceanvim on a symlinked project folder (I know, niche...).

local path_name = vim.api.nvim_buf_get_name(0) -- /home/me/projects/my_project/src/lib.rs
neotest.lib.files.path.real(path_name) -- /home/me/projects/my_project/src/lib.rs

bltavares and others added 2 commits February 20, 2024 10:32
When a respository is in a symlink-ed path (eg: larger hard-drive for
projects w/ small SDD for OS), calling `nio.uv.fs_realpath` will perform symlink resolution.
/~https://github.com/nvim-neotest/neotest/blob/f6048f32be831907fb15018af2688ff6633704fc/lua/neotest/lib/file/init.lua#L233

Given the following scenario, nvim will run buffers with the home-dir
path, instead of the resolved symlink path.

```sh
ln -s $HOME/projects /mnt/largehdd/projets
cd $HOME/projects/my_project
nvim .
```

Then, the following lua code will result on 2 different filenames.
```lua
local path_name = vim.api.nvim_buf_get_name(0) -- /home/me/projects/my_project/src/lib.rs
neotest.lib.files.path.real(path_name) -- /mnt/largehdd/projects/my_project/src/lib.rs
```

When sending the fully resolved symlinked path to a plugin, the
`path_name` on the plugin will not match any of the path names of
buffers, if they perform a search or use an external process.

This causes issues on `rustaceanvim` LSP-based test detection, which
requires the file to be on the root of the LSP runner directory, and
thus, the `file_path` sent is rejected.

This commit changes the login of `neotest.lib.files.path.real` to use
the vim function for resolving the full path name, followed by an exists
check, as there is 1 function usage that requires the error checking present.

Now, the following code is the same, and resolves the `No tests found!`
when running `:Neotest run file` using `rustaceanvim` on a symlinked
project folder (I know, niche...).

```lua
local path_name = vim.api.nvim_buf_get_name(0) -- /home/me/projects/my_project/src/lib.rs
neotest.lib.files.path.real(path_name) -- /home/me/projects/my_project/src/lib.rs
```
@rcarriga
Copy link
Collaborator

LGTM thanks for the PR!

@rcarriga rcarriga merged commit 5f93fb9 into nvim-neotest:master Mar 18, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants