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 4 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?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too sure what you are looking for with this question. As I said, 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.

I'm not too sure what you are looking for with this question. As I said, I lean towards only showing the suggestion.

Sorry for the confusion, I mean: how should the suggestion look like? Just say that there N similarly spelled features, or perhaps something else?

Also, closest_msg appends two line breaks into the middle of the message, so maybe I should use different function?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the confusion, I mean: how should the suggestion look like? Just say that there N similarly spelled features, or perhaps something else?

Unless we have a good reason, we should be use closest_msg. If we do have a good reason, we should mirror it. So that means we don't say there are "N similarly spelled features".

Also, closest_msg appends two line breaks into the middle of the message, so maybe I should use different function?

I commented on that at
#15438 (comment) . Other messages don't show two blank lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

To double check, earlier in this thread, I asked about not showing deactivated or activated features. Unless I'm misunderstanding something, it looks like that isn't done yet.

@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

@Jujumba
Copy link
Author

Jujumba commented Apr 27, 2025

@rustbot ready

Comment on lines 32 to 37
<tspan x="10px" y="118px"><tspan>help: a feature with a similar name exists: `bar`</tspan>
</tspan>
<tspan x="10px" y="136px">
</tspan>
<tspan x="10px" y="154px">
</tspan>
Copy link
Contributor

Choose a reason for hiding this comment

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

We're showing two blank lines.

This may be an artifact of how closest_msg expects error message newlines to be handled. Could you do a refactor before this commit so that this commit only shows one visible line?

Copy link
Author

@Jujumba Jujumba Apr 28, 2025

Choose a reason for hiding this comment

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

I'm not quite sure: do you mean removing blank lines or just leaving only one blank line per suggestion?

Sorry if I'm asking too much questions 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be two blank lines between items, only one.

This is likely an outcome of other error messages not being expected to have a trailing newline, so closest_msg adds it and then adds a blank line. But since we have a trailing newline, it makes two blank lines.

We likely need to just these messages to not have a trailing newline.

@Jujumba
Copy link
Author

Jujumba commented Apr 28, 2025

@rustbot ready

@Jujumba Jujumba requested a review from epage April 28, 2025 18:57
@epage
Copy link
Contributor

epage commented Apr 28, 2025

I know it can sometimes be a pain to clean up commits but could you

  • Pull out the change in newlines to be before any future work was done
  • Squash the feature work

That'll be a big help for reviewing

@Jujumba
Copy link
Author

Jujumba commented Apr 28, 2025

I know it can sometimes be a pain to clean up commits but could you

  • Pull out the change in newlines to be before any future work was done

  • Squash the feature work

That'll be a big help for reviewing

Sure, I'll ping you once done

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