-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Do not activate test
feature
#7225
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
Comments
I'm running into this as well. We could use the new |
Fixes crates which vanish when the 'test' cfg atom is set. Fix rust-lang#7243. Fix rust-lang#9203. Fix rust-lang#7225.
This was closed in #9227, but the fix seems incomplete (it requires the user to configure things to work correctly). I think in many cases such as #7243 the fix would simply be to have dependencies, maybe just ones outside of the workspace, be loaded without Can this be re-opened? |
Is there a way to detect rust-analyzer in a #[cfg(all(not(feature = "test"), any(test, doctest)))]
compile_error!("turbosql must be tested with '--features test'"); Which works great, except that it shows up as an error in rust-analyzer. I'd rather detect and avoid this in the code itself, rather than as a user setting. |
Same problem |
this allows the user to still enable #[cfg(test)] in rust-analyzer globally while not breaking dependencies that have different (broken) behavior when #[cfg(test)] is set. see: - rust-lang/rust-analyzer#7225 - lf-/rust-analyzer@86c9e7b
this allows the user to still enable #[cfg(test)] in rust-analyzer globally while not breaking dependencies that have different (broken) behavior when #[cfg(test)] is set. see: - rust-lang/rust-analyzer#7225 - lf-/rust-analyzer@86c9e7b
this allows the user to still enable #[cfg(test)] in rust-analyzer globally while not breaking dependencies that have different (broken) behavior when #[cfg(test)] is set. see: - rust-lang/rust-analyzer#7225 - lf-/rust-analyzer@86c9e7b
Would it be a possible solution to be able to set the |
You can for test. You can use |
But you have to specify the crate. Why is this not a boolean? |
Most of the time you don't want to apply it to the crate you are working on as it breaks ide functionality like autocompletion inside tests. |
I would actually argue the opposite. Most of the time you want to toggle it for the crate you are working on and have it always unset for dependency crates. The rationale is this: rust-analyzer give you a view of what you can do on the command-line with cargo. For example:
Each time I switch from working on one cargo command to another, I want rust-analyzer to adapt. For now I can do it for features and target (I update the config and restart rust-analyzer), but I cannot do it for test, it's always enabled (there's the variable you mentioned but that should be a bool, the same way features and target apply to the current crate and don't mention any crates). |
I agree that we usually don't want to set |
I don't think workspace crates should be analyzed under the same rust-analyzer instance with current technology. This brings too many problems (unnecessary load time, features ambiguity, test ambiguity, etc). Given how things seem to be implemented currently (rust-analyzer state seems to be tied to some specific rust invocation and some implicit crate to which features are provided), there should be one rust-analyzer instance per (crate-level) cargo invocation. I agree that ideally, rust-analyzer should probably be able to be tied to multiple rust invocations (and possibly multiple crates) which would permit to easily switch between features, targets, and test (and even crate) without recomputing the state. But I'm not even sure this is planned and will definitely be very long-term. So for now I think the focus should be on the user experience with a single rust invocation for a single crate. This objective seems reachable in the short-term. The workaround for workspace crates (resp. features, target, test) is to use one rust-analyzer per crate (resp. features, target, test). Or is there something I'm missing in the current design? |
That's how rust-analyzer works right now. There is no implicit main crate or anything like that; RA works on whole crate graphs and can in principle have multiple versions of the same crate in the graph. RA is not tied to some specific rustc invocation. |
I guess you talk specifically about workspace crates right? Because otherwise (when the LSP workspace is an actual crate and not a Cargo workspace) how would
What about the
So it's trying to read a Cargo.toml file (I suspect the one of the LSP workspace) which is thus the main crate (if it happens to be a workspace you're doomed). |
A virtual workspace doesn't have a main crate.
Cargo workspaces are fully supported AFAIK. |
Ok so this is specific to Cargo workspaces. If the LSP workspace is a crate and not a Cargo workspace, then you have a main crate. Is this understanding correct? If yes, I think this use-case should be well-supported because that's the most simple one (i.e. at least features, target, and test should work, the first 2 already do, the 3rd is this issue).
For example features are not: #10298. While they work with a main crate. |
Hello!
Right now, I believe Rust Analyzer hard codes activating
test
as a feature. This works well for writing tests, but has the unfortunate side effect that it's difficult to have any cfgs in the rest of a codebase, which should only be active duringtest
.In my specific usecase, I'm working on an opengl application, and i'd like to make a "HeadlessContext". I use it like this:
Right now, in the above program, Rust Analyzer will infer in all code (outside of test) that I am using
HeadlessContext
, notContext
, which leads to false positive errors (and false negative non-errors).I don't think the solution to this problem is really that easy though -- if RA simply allowed me to turn off
test
as a condition, then writing Unit Tests would suddenly get much harder, since i would no longer have access to the RA in such a context. A bit hacky, but a solution where cfg(test) on modules is accepted, but cfg(test) on non-modules is not would fix this usecase, but seems very shaky and perhaps confusing to users.Thank you for all the hard work on this excellent library! What do you think of the above?
The text was updated successfully, but these errors were encountered: