Skip to content

feat(add): suggest similarly named features #15438

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

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

Conversation

Jujumba
Copy link

@Jujumba Jujumba commented Apr 18, 2025

What does this PR try to resolve?

Fixes #15436

How should we test and review this PR?

There are 3 tests for each test case:

  • there are no feature suggestions
  • there's only one feature suggestion (most common)
  • there are several feature suggestions

@rustbot
Copy link
Collaborator

rustbot commented Apr 18, 2025

r? @epage

rustbot has assigned @epage.
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 Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2025
@epage
Copy link
Contributor

epage commented Apr 18, 2025

There are 3 tests for each test case:

Would you be willing to restructure this to match the recommendation at https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request to add tests in a commit before your change with them passing and then your commit with your change updates the tests so they still pass so that the diff between the commits highlights the change in behavior?

.into_iter()
.format("\n ")
)?;
}
if deactivated.len() <= MAX_FEATURE_PRINTS {
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 still display all of the features if there is a closest match for every unknown feature?

Copy link
Author

Choose a reason for hiding this comment

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

I would say yes, although this might be pretty lengthy

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking around at how we do this elsewhere

  • Most places do not list all options, even without a suggestion
  • One place always lists out how to see all options, independent of whether there was a suggestion
  • 2 places will conditionally show all options if a suggestion is not present

So there is only a small precedence but it tends to be towards not listing everything if there is a suggestion.

Thinking particularly for this case, we most likely want to focus the users attention on the suggestion. Also, since there was a concern over the number of suggestions, what there can be a lot more of is number of features. While we use columns, it can be quite large.

I lean towards only showing the suggestion.

Copy link
Author

Choose a reason for hiding this comment

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

Looking around at how we do this elsewhere

* Most places do not list all options, even without a suggestion

* One place always lists out how to see all options, independent of whether there was a suggestion

* 2 places will conditionally show all options if a suggestion is not present

So there is only a small precedence but it tends to be towards not listing everything if there is a suggestion.

Thinking particularly for this case, we most likely want to focus the users attention on the suggestion. Also, since there was a concern over the number of suggestions, what there can be a lot more of is number of features. While we use columns, it can be quite large.

I lean towards only showing the suggestion.

So, how should the output look like?

Comment on lines 171 to 172
if !deactivated.is_empty() {
let mut suggested_features = Vec::new();
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 check even among activated features?

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps, but I don't see value in it: these features are already activated 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

The user might not realize its activated and they may be taking a feature that is indirectly activated and explicitly activating it.

Copy link
Author

Choose a reason for hiding this comment

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

The user might not realize its activated and they may be taking a feature that is indirectly activated and explicitly activating it.

Sounds reasonable. So, do I have to check in activated features as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we should.

@Jujumba
Copy link
Author

Jujumba commented Apr 18, 2025

There are 3 tests for each test case:

Would you be willing to restructure this to match the recommendation at https://doc.crates.io/contrib/process/working-on-cargo.html#submitting-a-pull-request to add tests in a commit before your change with them passing and then your commit with your change updates the tests so they still pass so that the diff between the commits highlights the change in behavior?

Sure! To make tests pass before I introduce my changes, I have to leave them blank, right?

@epage
Copy link
Contributor

epage commented Apr 18, 2025

Sure! To make tests pass before I introduce my changes, I have to leave them blank, right?

In this case, they should still be doing adds; just there will be no suggestions given. If there are questions, the link I gave has links to example PRs.

@Jujumba
Copy link
Author

Jujumba commented Apr 18, 2025

Sure! To make tests pass before I introduce my changes, I have to leave them blank, right?

In this case, they should still be doing adds; just there will be no suggestions given. If there are questions, the link I gave has links to example PRs.

Alright, done

@Jujumba Jujumba requested a review from epage April 18, 2025 19:07
@Jujumba
Copy link
Author

Jujumba commented Apr 18, 2025

Ohh, just noticed that edit_distance::closest_msg appends two '\n' at the begging of the string, messing up the output

@Jujumba
Copy link
Author

Jujumba commented Apr 18, 2025

Ohh, just noticed that edit_distance::closest_msg appends two '\n' at the begging of the string, messing up the output

I think we have to rollback to edit_distance::closest or add the help message at the end

@epage

@Jujumba
Copy link
Author

Jujumba commented Apr 18, 2025

Also, how should I approach fixing other tests? Some of them fail because output of cargo add changed

@weihanglo
Copy link
Member

https://github.com/rust-lang/cargo/actions/runs/14540352012/job/40796970702#step:13:4593

Set the environment variable SNAPSHOTS=overwrite. See https://doc.crates.io/contrib/tests/writing.html#updating-snapshots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-add 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.

Feature Request: add suggestion for similarly named features with cargo add
4 participants