marilari88 / neotest-vitest

Vitest adapter for Neovim Neotest plugin
91 stars 34 forks source link

Adapter fails when attempting to change the cwd #47

Open JordanFaust opened 5 months ago

JordanFaust commented 5 months ago

Anytime neotest-vitest is used within a buffer attempting to change the current working directory within neovim fails due to nio background tasks.

Full stack trace:

   Error  09:16:12 AM msg_show.lua_error E5108: Error executing lua: vim/_editor.lua:0: nvim_exec2()..DirChanged Autocommands for "*": Vim(append):Error executing lua callback: .../jordan/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: Async task failed without callback: The coroutine failed with this message: 
...are/nvim/lazy/neotest-vitest/lua/neotest-vitest/init.lua:21: attempt to concatenate local 'rootPath' (a nil value)
stack traceback:
    ...are/nvim/lazy/neotest-vitest/lua/neotest-vitest/init.lua: in function 'hasVitestDependency'
    ...are/nvim/lazy/neotest-vitest/lua/neotest-vitest/init.lua:54: in function 'root'
    ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:13: in function 'adapters_with_root_dir'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:519: in function '_update_adapters'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:447: in function <...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:446>
stack traceback:
    [C]: in function 'error'
    .../jordan/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:95: in function 'close_task'
    .../jordan/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:117: in function 'step'
    .../jordan/.local/share/nvim/lazy/neotest/lua/nio/tasks.lua:145: in function 'run'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:446: in function <...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:444>
    [C]: in function 'nvim_exec2'
    vim/_editor.lua: in function 'cmd'
    ...hare/nvim/lazy/project.nvim/lua/project_nvim/project.lua:182: in function 'set_pwd'

This specifically is failing within the checks looking for a vitest dependency but I think it might be the root function that is causing the issue.

marilari88 commented 5 months ago

@JordanFaust, could you assist me in reproducing the issue by providing more details about your configuration or the steps you're following? I'm attempting to change the current working directory with a test file in the buffer, but no errors are appearing.

JordanFaust commented 5 months ago

So I moved what I was doing into an autogroup that changes the directory after I load a new session for a project. That is working just fine now. However, if I execute the command lua vim.api.nvim_set_current_dir('/some/other/project') after I have executed tests using the vitest adapter I get the above error still.