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

Get all members as available targets even though default-members was specified. #15199

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

linyihai
Copy link
Contributor

What does this PR try to resolve?

The old behavior gets members from default-members if specified in a virtual workspace, this PR gets all workspace members for Available target hints.

Fixes #14544

How should we test and review this PR?

The first commit added the test, the second commit addressed the issue.

Additional information

@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 18, 2025
[ERROR] "--bin" takes one argument.
Available binaries:
crate1
crate2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #14544

If the fix only adds bins from all targets to this error theo it will lead to user frustration as they then add --bin crate2 and it fails without saying why.

The core problem in the Issue is the --bin crate2 error message. It only suggested touching this error message as an addendum and suggested it show what the needed package is. I agree with that with the caveat that we need to double check if our completion or fish's completion script uses the output from this. While this is meant for humans and can change, we still want to play nice with these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the focus of #14544 is now included, two of the 3 improvements still require investigating their impact on cargo's and fish's completions and one still has the issue of showing values that can't be used.

@rustbot rustbot added the A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) label Feb 19, 2025
Comment on lines 314 to 345
fn get_targets_from_other_packages(
&self,
filter_fn: impl Fn(&Target) -> bool,
) -> CargoResult<Option<(String, String)>> {
let packages = Packages::All(Vec::new()).get_packages(self.ws)?;
let targets = packages.into_iter().find_map(|pkg| {
if let Some(target) = pkg
.manifest()
.targets()
.iter()
.find(|target| filter_fn(target))
{
Some((pkg.name().to_string(), target.name().to_string()))
} else {
None
}
});

Ok(targets)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name implies this returns multiple but it only returns the first.

What should we do when there are multiple?

Comment on lines 1353 to 1356
[HELP] a target with a similar name exists: `a`


"#]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra newline doesn't seem right

Comment on lines 2842 to 2843
[ERROR] no bin target named `crate2`.
Available bin targets:
another
Available bin targets in crate2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say

no bin target named crate2 in crate1 package.

or

no bin target named crate2 in default-run packages

Without that extra context, I worry users might get confused because they know might know these targets come from other packages but not realize it

(this should probably be its own commit)

Comment on lines 2842 to 2843
[ERROR] no bin target named `crate2`.
Available bin targets:
another
Available bin targets in crate2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cases like this where the bin and target name are redundant, should we clarify this

Available bin targets in package crate2:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-cli Area: Command-line interface, option parsing, etc. A-workspaces Area: workspaces S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

workspace.default-members causes cargo run --bin from-other-crate to fail with an unhelpful error
4 participants