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

bug: wrong paths with local-lua-debugger-vscode #46

Open
4 tasks done
polirritmico opened this issue Jan 19, 2025 · 5 comments
Open
4 tasks done

bug: wrong paths with local-lua-debugger-vscode #46

polirritmico opened this issue Jan 19, 2025 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@polirritmico
Copy link

polirritmico commented Jan 19, 2025

Did you check docs and existing issues?

  • I have read the documentation
  • I have searched the existing issues
  • I have searched the existing issues of plugins related to this issue (if relevant)
  • I have tried setting log_level to vim.log.levels.debug in neotest.setup and examined the logs.

Neovim version (nvim -v)

NVIM v0.10.3 Build type: Release LuaJIT 2.1.1716656478

Operating system/version

Gentoo Linux 2.17

Describe the bug

Hi, I hope everything is going well. I love seeing the progress this project has made so far with the latest versions.

These days I've been trying the debugging capabilities with local-lua-debugger-vscode, and it has worked well except for some problems with the imports.

For example, I have this structure:

$ tree case
case/
├── lua
│   └── foo
│       └── init.lua
├── Makefile
└── tests
    ├── busted.lua
    ├── foo_spec.lua
    └── helpers.lua

If I require the helpers module from the foo_spec test file, then depending if I'm running a normal test through neotest or a debug test through dap, I have to adjust the require path:

-- in foo_spec.lua
local foo = require("foo")
local helpers = require("tests.helpers") -- this fail

The above code would work fine using :lua require("neotest").run.run() or nvim -l tests/busted.lua tests from the command line, but it would fail using :lua require("neotest").run.run(strategy="dap").

It complains that it couldn't find the tests.helpers module with this error:

Error → /home/<user>/repro/case/tests/foo_spec.lua @ 2
local-lua-debugger-vscode should load helpers in the correct path
/home/<user>/repro/case/tests/foo_spec.lua:4: module 'tests.helpers' not found:
        no field package.preload['tests.helpers']
cache_loader: module tests.helpers not found
cache_loader_lib: module tests.helpers not found
        no file './src/tests/helpers.lua'
        no file './src/tests/helpers/tests/helpers.lua'
        no file './src/tests/helpers/init.lua'
        no file 'lua/tests/helpers.lua'
        no file 'lua/tests/helpers/init.lua'
        no file '/home/<user>/tmp/local-lua-debugger-vscode//debugger/tests/helpers.lua'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/share/lua/5.1/tests/helpers.lua'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/share/lua/5.1/tests/helpers/init.lua'
        no file '/home/<user>/repro/case/tests/tests/helpers.lua'
        no file './csrc/tests/helpers.so'
        no file './csrc/tests/helpers/tests/helpers.so'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/lib/lua/5.1/tests/helpers.so'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/lib64/lua/5.1/tests/helpers.so'
        no file './csrc/tests.so'
        no file './csrc/tests/tests.so'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/lib/lua/5.1/tests.so'
        no file '/home/<user>/repro/case/.tests//data/nvim/lazy-rocks/busted/lib64/lua/5.1/tests.so'

I don't completely rule out that it may be an issue in my config, but since the debug session itself is working fine, and the require calls are working outside the dap neotest session, maybe is something related to a path missing or not created properly. For example, this path seems very strange:

no file '/home/<user>/repro/case/tests/tests/helpers.lua'

Expected Behavior

require("tests.helpers") should work fine when using the dap session through neotest-busted.

Output of :checkhealth neotest-busted if relevant

No response

neotest log output if relevant

No response

Steps To Reproduce

Replicate the issue involve a lot of steps to fully set the environment, so I've made a repro repository here. Since local-lua-debugger-vscode is needed for all this, I've use a Makefile with git clone and npm for the build:

  1. git clone https://github.com/polirritmico/busted-repro.git
  2. cd busted-repro
  3. nvim -u repro-demo.lua
  4. Follow the message instructions:
    1. Clone and build the local-lua-debugger-vscode in the expected path by the config
    2. Run the lazy/busted bootstrap
    3. Open the case and set the breakpoints
    4. Run the neotest dap session

I hope that the automation works, but in any case, I've also added a standard repro.lua file (try with nvim -u repro.lua). Beyond that, with the case folder itself it should be relatively straight forward to reproduce the issue after running the busted/lazy bootstrap.

Thanks!

@polirritmico polirritmico added the bug Something isn't working label Jan 19, 2025
@MisanthropicBit
Copy link
Owner

Hi, I hope everything is going well. I love seeing the progress this project has made so far with the latest versions.

Everything going good, thanks and likewise. That progress is in no small part thanks to you 😄 Glad to hear debugging is mostly working.

Thanks for the repro repository, that really helps! I'll take a look at it when I have time and see if I can reproduce it.

The paths should be the same for running neotest and running it through dap with the exception that passing arguments to the debug command requires quotes due to the way it is run.

Two things I notice after skimming the repro that might be worth investigating (I'll go through the repro in depth later):

  1. neotest-busted sets up the path to look for modules in the lua/ folder but not in any tests/ folder so I'm a bit surprised that it even works in one case unless you are manually adding that to the path. One solution might be to just move the helpers to the lua/ folder. For example in one project, I have a test_helpers.lua file for the same purpose.
  2. You are manually setting the busted_command option which, as per the warning in this section, makes neotest-busted not set up paths automatically since it won't know where they are located for certain. You would need to set them yourself but perhaps the test setup through lazy.nvim is setting up the paths to amend this (it looks like that's the case from the paths searched in the stack trace).

@MisanthropicBit MisanthropicBit self-assigned this Jan 19, 2025
@MisanthropicBit
Copy link
Owner

A small update: I've successfully reproduced the issue with your repro and tried out a few things but so far I haven't been able to figure out what the issue is unfortunately.

@polirritmico
Copy link
Author

polirritmico commented Feb 2, 2025

A small update: I've successfully reproduced the issue with your repro and tried out a few things but so far I haven't been able to figure out what the issue is unfortunately.

Nice to hear that you could reproduce the issue, it took me some time to narrow it down to reproducible steps.

In any case, I've also dig in on it. First, as you say, the path was set by lazy here:

package.path = package.path .. ";" .. vim.uv.cwd() .. "/tests/?.lua"

Since that is working with the non-dap strategy, it seems that something is changing the cwd.

As a workaround I've tried the add project path to the rtp, but doing it only for the dap debug strategy feels like a hack:

-- in the tests/path/to/test/spec.lua module
package.path = package.path .. ";" .. vim.uv.cwd() .. "/?.lua"

I've managed to debug the debugger through osv, and maybe the issue is related to how the ${workspaceFolder} variable is resolved?

I would try to dig a little further in case I found something more relevant.

Thanks!

@polirritmico
Copy link
Author

polirritmico commented Feb 2, 2025

After some checks, I've found that run the non-dap strategy tests execute the busted.lua module that I set in minimal_init = "tests/busted.lua", but running the tests through strategy = "dap" doesn't. I'm going to I've updated the https://github.com/polirritmico/busted-repro/blob/main/case/tests/busted.lua file in the repro so you could check it.

@MisanthropicBit
Copy link
Owner

In any case, I've also dig in on it. First, as you say, the path was set by lazy here:

Thanks, that explains my confusion.

As a workaround I've tried the add project path to the rtp, but doing it only for the dap debug strategy feels like a hack:

So that workaround worked? Ok, seems you're on the right path then.

...maybe the issue is related to how the ${workspaceFolder} variable is resolved?

Here is how it is resolved. So its value depends entirely on where you are in the filesystem and isn't related to a "project root" as one might otherwise believe. I tried printing the cwd from nvim-dap when running nvim -u repro-demo.lua which gave me "~/projects/nvim/busted-repro/case" (~ was expanded).

I want to try to run inside the case/tests folder but I need to change a few things in the repro to do that so I'll do it later when I have more time.

but running the tests through strategy = "dap" doesn't.

How did you verify this? As I've written here there is a difference between how the test process is run between neotest and the debug adapter so perhaps this is why?

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

No branches or pull requests

2 participants