Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Cannot debug test in workspace's member #88

@FirelightFlagboy

Description

@FirelightFlagboy

Description

Currently the plugin does not work when trying to debug workspace member's test.
It result in the following error originating from dap:

Error on launch: The "program" attribute is required for launch.

Reproduction steps

  1. cargo new --lib foo
  2. cd foo
  3. cargo new --lib bar
  4. Try to debug the test bar::tests::it_works with neotest-rust

Analysis

I've done some investigation why program was missing because from the source it's always included:

local strategy = {
name = "Debug Rust Tests",
type = get_dap_adapter(),
request = "launch",
cwd = cwd or "${workspaceFolder}",
stopOnEntry = false,
args = dap_args,
program = dap.get_test_binary(cwd, position.path),
}

So I have patched neotest_rust.build_spec like so:

local neotest_rust = require('neotest-rust')({})

local _orig_build_spec = neotest_rust.build_spec
function neotest_rust.build_spec(args)
    local position = args.tree:data()
    local cwd = neotest_rust.root(position.path)
    local test_bin = require('neotest-rust.dap').get_test_binary(cwd, position.path)
    local data = {
        strategy = args.strategy,
        position = position,
        cwd = cwd,
        test_bin = test_bin or 'is falsy'
    }
    vim.print('neotest-rust::build_spec <-', data)
    local ret = _orig_build_spec(args)
    vim.print('neotest-rust::build_spec ->', ret)
    return ret
end

To be able to inspect the return value on get_test_binary.
And it result that the value in nil caused by the following:

Maybe it should be an error instead 🤔

Uppon further inspection it's get_src_paths that is causing the issue with the command cargo test --no-run ...:

local cmd = {
"cargo",
"test",
"--manifest-path=" .. root .. sep .. "Cargo.toml",
"--message-format=JSON",
"--no-run",
"--quiet",
}

The manifest path it receive correspond to Cargo.toml at the root of the workspace, executing the command cargo t --manifest-path=Cargo.toml --message-format=JSON --no-run, result in:

{
  "reason": "compiler-artifact",
  "package_id": "path+file:///tmp/foo#0.1.0",
  "manifest_path": "/tmp/foo/Cargo.toml",
  "target": {
    "kind": [
      "lib"
    ],
    "crate_types": [
      "lib"
    ],
    "name": "foo",
    "src_path": "/tmp/foo/src/lib.rs",
    "edition": "2024",
    "doc": true,
    "doctest": true,
    "test": true
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": false
  },
  "features": [],
  "filenames": [
    "/tmp/foo/target/debug/deps/libfoo-c16a48930bdc4950.rlib",
    "/tmp/foo/target/debug/deps/libfoo-c16a48930bdc4950.rmeta"
  ],
  "executable": null,
  "fresh": true
}
{
  "reason": "compiler-artifact",
  "package_id": "path+file:///tmp/foo#0.1.0",
  "manifest_path": "/tmp/foo/Cargo.toml",
  "target": {
    "kind": [
      "lib"
    ],
    "crate_types": [
      "lib"
    ],
    "name": "foo",
    "src_path": "/tmp/foo/src/lib.rs",
    "edition": "2024",
    "doc": true,
    "doctest": true,
    "test": true
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": true
  },
  "features": [],
  "filenames": [
    "/tmp/foo/target/debug/deps/foo-6a5eba1d06f19a5d"
  ],
  "executable": "/tmp/foo/target/debug/deps/foo-6a5eba1d06f19a5d",
  "fresh": true
}
{
  "reason": "build-finished",
  "success": true
}

Where it could not find the expected path /tmp/foo/bar/src/lib.rs

Whereas by adding --workspace or setting --manifest-path to bar/Cargo.toml result in JSON containing the expected path:

{
  "reason": "compiler-artifact",
  "package_id": "path+file:///tmp/foo/bar#0.1.0",
  "manifest_path": "/tmp/foo/bar/Cargo.toml",
  "target": {
    "kind": [
      "lib"
    ],
    "crate_types": [
      "lib"
    ],
    "name": "bar",
    "src_path": "/tmp/foo/bar/src/lib.rs",
    "edition": "2024",
    "doc": true,
    "doctest": true,
    "test": true
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": false
  },
  "features": [],
  "filenames": [
    "/tmp/foo/target/debug/deps/libbar-d6004391109334c7.rlib",
    "/tmp/foo/target/debug/deps/libbar-d6004391109334c7.rmeta"
  ],
  "executable": null,
  "fresh": true
}
{
  "reason": "compiler-artifact",
  "package_id": "path+file:///tmp/foo/bar#0.1.0",
  "manifest_path": "/tmp/foo/bar/Cargo.toml",
  "target": {
    "kind": [
      "lib"
    ],
    "crate_types": [
      "lib"
    ],
    "name": "bar",
    "src_path": "/tmp/foo/bar/src/lib.rs",
    "edition": "2024",
    "doc": true,
    "doctest": true,
    "test": true
  },
  "profile": {
    "opt_level": "0",
    "debuginfo": 2,
    "debug_assertions": true,
    "overflow_checks": true,
    "test": true
  },
  "features": [],
  "filenames": [
    "/tmp/foo/target/debug/deps/bar-5ff8b03c55139d64"
  ],
  "executable": "/tmp/foo/target/debug/deps/bar-5ff8b03c55139d64",
  "fresh": true
}
{
  "reason": "build-finished",
  "success": true
}

It's the output with --manifest-path=bar/Cargo.toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions