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

Opening a project of a workspace checks the whole workspace #3975

Open
Ten0 opened this issue Apr 14, 2020 · 10 comments
Open

Opening a project of a workspace checks the whole workspace #3975

Ten0 opened this issue Apr 14, 2020 · 10 comments
Labels
E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@Ten0
Copy link

Ten0 commented Apr 14, 2020

I have a workspace which contains a large number of crates.

Say I need to do the following, in that order:

  • Update lib L
  • Fix crate A to new interface of lib L
  • Fix crate B to new interface of lib L

(A and B do not depend on each other)

When I try to completely update crate A, I can't see warnings and in general I get errors from project B, which I haven't fixed yet. This is due to rust-analyzer watching the whole workspace, even though I have only opened the root of A, and the Cargo.toml at the root of my folder is that of A.

I would expect that the current behaviour only happens when I open my workspace folder, and that when I open a single project it doesn't try to build the whole workspace, allowing me to completely fix a crate before moving to the next.

This would also have other benefits:

  • Performance: my workspace being very large, I rarely work on all projects at once so I would gain time and space by not building all of it
  • Feature flags testing: a global cargo check does not behave the same way as individual checks: when running a workspace check, all feature flags required in any crate of the workspace are enabled for every crate of the workspace, while when running a crate check, only the flags required for that specific crate are enabled.
@Ten0
Copy link
Author

Ten0 commented Apr 14, 2020

#2792 may be another solution to the first part (though I'm not sure how it would behave with the warnings), but it doesn't do anything for the "other benefits".

@matklad
Copy link
Member

matklad commented Apr 15, 2020

The current workaround is to set checOnSave.overrideCommand to a cargo command which checks only a specific package.

@Ten0
Copy link
Author

Ten0 commented Apr 15, 2020

What's the original command and how should I set it so that it checks in the root of my project ? (I wouldn't want to remove any other important parameters)

@matklad
Copy link
Member

matklad commented Apr 15, 2020

Original one is cargo check --workspace --message-format=json

@Ten0
Copy link
Author

Ten0 commented Apr 17, 2020

I tried setting:

{
	"rust-analyzer.checkOnSave.overrideCommand": [
		"cargo",
		"check",
		"--message-format=json"
	]
}

and it seems to still check the whole workspace. :(

@matklad
Copy link
Member

matklad commented Apr 17, 2020

That’s the base command, yeah, you need to add -p some-package no top of it to narrow it to a single package

@Ten0
Copy link
Author

Ten0 commented Apr 17, 2020

Oh that's awful, I'd have to change everytime I open a project :(

@flodiebold flodiebold added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Jan 31, 2021
@Ten0
Copy link
Author

Ten0 commented Jan 12, 2022

I'm trying to make this work with extraArgs but I can't seem to do so (while it does work with #3975 (comment)):

{
	"rust-analyzer.checkOnSave.extraArgs": [
		"-p",
		"some_crate",
	],
	"rust-analyzer.cargo.allFeatures": true
}

seems to still check the whole workspace.

@ellbur
Copy link

ellbur commented Aug 2, 2022

That’s the base command, yeah, you need to add -p some-package no top of it to narrow it to a single package

So maybe a wrapper script to infer the current project and add the -p? I'm going to give that a try.

@ellbur
Copy link

ellbur commented Aug 2, 2022

So maybe a wrapper script to infer the current project and add the -p? I'm going to give that a try.

Alas, I can find no way to detect the package since the cwd is the workspace...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-hard S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

4 participants