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

Error on :edit a/b/c when parent dir (a/b) doesn't exist #404

Closed
6 tasks done
tmillr opened this issue May 20, 2024 · 2 comments · Fixed by #405
Closed
6 tasks done

Error on :edit a/b/c when parent dir (a/b) doesn't exist #404

tmillr opened this issue May 20, 2024 · 2 comments · Fixed by #405
Labels
bug Something isn't working

Comments

@tmillr
Copy link

tmillr commented May 20, 2024

Have you read the docs and searched existing issues?

Neovim version (nvim -v)

0.10

Operating system/version

macOS 14.2.1

Output of :checkhealth rustaceanvim

n/a

How to reproduce the issue

Run :e src/dir/file.rs where ./src exists but ./src/dir does not.

Expected behaviour

No error.

Actual behaviour

The plugin errors:

"src/new/new.rs" [New DIRECTORY]                                                                                                                                                 
Error detected while processing BufNewFile Autocommands for "*":                                                                                                                 
Error executing lua callback: ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35: Error executing lua: ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:36
: BufNewFile Autocommands for "*"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[20]..script /nix/store/d3g7mg2n16zqzx5g659p379jfqfi52fi-vimplugin-lua5.1-rustacean
vim-4.22.8-1-unstable-2024-05-16/ftplugin/rust.lua: Vim(runtime):E5113: Error while calling lua chunk: Vim:E475: Invalid argument: expected valid directory                      
stack traceback:                                                                                                                                                                 
        [C]: in function 'jobstart'                                                                                                                                              
        ...imPackages/start/rustaceanvim/lua/rustaceanvim/cargo.lua:54: in function 'get_root_dir'                                                                               
        ...ovimPackages/start/rustaceanvim/lua/rustaceanvim/lsp.lua:98: in function 'start'                                                                                      
        ...taceanvim-4.22.8-1-unstable-2024-05-16/ftplugin/rust.lua:56: in main chunk                                                                                            
        [C]: in function 'nvim_cmd'                                                                                                                                              
        ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:36: in function <...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35>                             
        [C]: in function 'nvim_buf_call'                                                                                                                                         
        ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35: in function <...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:10>                             
stack traceback:                                                                                                                                                                 
        [C]: in function 'nvim_cmd'                                                                                                                                              
        ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:36: in function <...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35>                             
        [C]: in function 'nvim_buf_call'                                                                                                                                         
        ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35: in function <...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:10>                             
stack traceback:                                                                                                                                                                 
        [C]: in function 'nvim_buf_call'                                                                                                                                         
        ...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:35: in function <...-neovim-unwrapped-0.10.0/share/nvim/runtime/filetype.lua:10>                             
Press ENTER or type command to continue

The minimal config used to reproduce this issue.

n/a

@tmillr tmillr added the bug Something isn't working label May 20, 2024
@tmillr
Copy link
Author

tmillr commented May 21, 2024

This is caused by the jobstart() call receiving an invalid/non-existent cwd here:

local cm = vim.fn.jobstart(cmd, {
on_stdout = function(_, d, _)
cargo_metadata = table.concat(d, '\n')
end,
stdout_buffered = true,
cwd = path,
})

I believe the cwd that gets passed is just the dirname() of the current/edited buffer, which in this case doesn't exist yet (but will when the user later writes the buf with :w ++p), hence the error. Perhaps, instead, the first directory that exists (going from right to left) could be passed? Also I could submit a patch, but I'm not overly familiar with this plugin and its inner-workings.

@mrcjkb
Copy link
Owner

mrcjkb commented May 21, 2024

Hey 👋

Thanks for the report and investigation. 🙏
I'll look into fixing it in the next few days.

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

Successfully merging a pull request may close this issue.

2 participants