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 · 1 comment
Open
4 tasks done

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

polirritmico opened this issue Jan 19, 2025 · 1 comment
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
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