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

Run and Debug codelens link buttons for main (non test) entry point launch with differing cwd paths #17012

Closed
Keshi opened this issue Apr 4, 2024 · 3 comments · Fixed by #17275
Labels
C-bug Category: bug

Comments

@Keshi
Copy link

Keshi commented Apr 4, 2024

Observed behaviour: In the scenario of an bin package inside a virtual workspace, such as in this minimal example (https://github.com/Keshi/minimal-virtual-workspace), choosing to Run or Debug the main function using the codelens buttons results in different working directories.
If the application is one that expects to dynamically load a settings or asset file relative to the cwd, then the application will always fail to load the file through one of either Run or Debug.

Expected/Desired behaviour: Run and Debug codelens buttons both launch the application using the same cwd behaviour (as observed by the application) as Run currently does.

rust-analyzer version: rust-analyzer version: 0.3.1906-standalone (e4a405f 2024-03-31)
rustc version: rustc 1.77.1 (7cf61ebde 2024-03-27)
editor or extension: VSCode, rust-analyzer 0.3.1906

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional):
https://github.com/Keshi/minimal-virtual-workspace

@Keshi Keshi added the C-bug Category: bug label Apr 4, 2024
@roife
Copy link
Member

roife commented Apr 5, 2024

Related to #13022 and #15993.

Should we make Run and Debug both use the package-root as cwd?

Or we could introduce a setting and let users decide whether to use workspace-root or package-root.

@Keshi
Copy link
Author

Keshi commented Apr 5, 2024

I think that Run should keep its current behaviour, since it provides a cwd matching the user's context or scope of what they have opened using their IDE (for example, the whole workspace in a multi-package project), as if they had used cargo run or cargo run -p some-pkg-name from the terminal from the same context, or from opening a terminal in an IDE opened to the project. I think that Debug should be changed to use the same behaviour as that of Run for cwd, in the situation of an application (not a #[test]) launch. Changing Debug to match Run for cwd would thus make those 3 ways of starting an application consistent with each other for cwd, alleviating the issue.

I don't think Run and Debug should both always use package-root as cwd, as then you'd have surprising behaviour compared to cargo run in the terminal from the same user context, but in the case of a single package not in another workspace, that would end up being the effective behaviour regardless.

I think there is definitely an argument to be made for always using package-root for cwd in every scenario, but I also think that would only make sense if cargo run -p and cargo run in a workspace with a default member were also doing the same thing, which it is not.

@TieWay59
Copy link

TieWay59 commented Apr 17, 2024

pub fn current_dir() -> io::Result<PathBuf>
Returns the current working directory as a [PathBuf].

I think the current working directory definition is not clear enough in docs, it's itchy to guess what it will return.

I prefer the cwd = current workspace directory and expose a new API like current package root.

Debug should work as Run in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants