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

VSCode "Debug" test cwd is workspace root, not package root for tests #13022

Closed
Crzyrndm opened this issue Aug 15, 2022 · 2 comments · Fixed by #15993
Closed

VSCode "Debug" test cwd is workspace root, not package root for tests #13022

Crzyrndm opened this issue Aug 15, 2022 · 2 comments · Fixed by #15993
Labels
A-vscode vscode plugin issues C-bug Category: bug

Comments

@Crzyrndm
Copy link

Crzyrndm commented Aug 15, 2022

Setup: https://github.com/Crzyrndm/ra-executing-directory

A package nested in a workspace, the tests (unit + integration) just print std::env::current_dir() and then panic (so that the print is always visible)

  • cargo test --no-fail-fast: prints the package root directory for both unit and integration no matter what directory it is run in
  • VSCode "Run test" button: prints the package root directory
  • VSCode "Debug" button: prints the workspace root directory

This makes debugging tests that need to load a data file quite awkward

image

rust-analyzer version: rust-lang.rust-analyzer 0.3.1170 (current stable)

rustc version: rustc 1.63.0 (4b91a6ea7 2022-08-08)

Tested OS is Windows 10

relevant settings:

@Crzyrndm Crzyrndm changed the title VSCode "Debug" button runs in workspace root VSCode "Debug" test button runs in workspace root Aug 15, 2022
@Crzyrndm
Copy link
Author

Crzyrndm commented Aug 17, 2022

Disclaimer: I have never used JS/TS so take the following as you will

From what I can tell, the Debug executing directory is set here and is unconditionally the workspace/open folder root directory.

After some changes to the example repo and looking through cargo source:

  • Examples and bins are not localised (or more completely, cargo run doesn't modify cwd)
  • tests (and likely #[bench]) are localised to the package

The target appears to be known in the same scope although I don't know if that's package/folder/something else at this point. Presumably whether it's a run/test(/example/benchmark) or not can be obtained from this

E: Tests and benchmarks are definitely run the same way by cargo. This appears to be where the cmd is built for both.

@Crzyrndm Crzyrndm changed the title VSCode "Debug" test button runs in workspace root VSCode "Debug" test cwd is workspace root, not package root Aug 17, 2022
@Crzyrndm Crzyrndm changed the title VSCode "Debug" test cwd is workspace root, not package root VSCode "Debug" test cwd is workspace root, not package root for tests Aug 17, 2022
@esiegel
Copy link

esiegel commented Nov 7, 2022

In addition it doesn't include any of the cargo environment variables that could be used to help normalize a path. For example, CARGO_MANIFEST_DIR is missing

@Veykril Veykril added the C-bug Category: bug label Feb 9, 2023
@flodiebold flodiebold added the A-vscode vscode plugin issues label Apr 9, 2023
meowtec added a commit to meowtec/rust-analyzer that referenced this issue Nov 30, 2023
bors added a commit that referenced this issue Nov 30, 2023
Debug use cargo workspace root as `cwd`

fixes #13022
@bors bors closed this as completed in 4ca86ed Nov 30, 2023
roife added a commit to roife/rust-analyzer that referenced this issue May 22, 2024
roife added a commit to roife/rust-analyzer that referenced this issue May 23, 2024
bors added a commit that referenced this issue May 24, 2024
Fix inconsistent cwd of `run` and `debug` command in client

Fix #17012. Also related to #13022 and #15993.

When the `kind` of runnable is `bin`, Cargo would use the workspace root as the cwd for the `run` command; otherwise, Cargo defaults to the package root as the cwd for `run`.

Initially, r-a assumed the workspace root as the cwd for all runnables in `debug` command, which led to issue #13022. In this case, during unit testing, the `run` command would use the package root while `debug` would use the workspace root, causing inconsistency.

PR #15993 addressed this problem by using the package root as the cwd for `debug` command. However, it also resulted in an inconsistency: when executing the `run` command within the main fn of a package (whose target is `bin`), Cargo would use the workspace root, whereas `debug` would use the package root, leading to issue #17012.

The preferable approach is to determine the cwd based on the runnable's type. To resolve this, this PR introduces a new `cwd` field within `CargoRunnable`, allowing r-a to decide the appropriate cwd depending on the specific kind of the runnable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-vscode vscode plugin issues C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants