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

Sort the members lists of the workspace even if they were previously unordered #14809

Open
linyihai opened this issue Nov 12, 2024 · 4 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.

Comments

@linyihai
Copy link
Contributor

Problem

If the list of working interval members is long and unordered, and then append the members via the 'cargo new' command, only manual sorting of the member list can be done.

The current design of cargo is that if the members list is in order, then the 'cargo new' command will sort the members list, thus ensuring that the members list is in order.
The current design should be to scramble the contents of the members list, if it was previously out of order.
But as I explained earlier, if the user wants to have an ordered list of members, then the user will have to work it out on their own

Proposed Solution

The one I can think of so far is the 'cargo new' subcommand that lets the user choose whether to sort the members list by adding an option.

Notes

No response

@linyihai linyihai added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Nov 12, 2024
@linyihai
Copy link
Contributor Author

The current design of cargo is that if the members list is in order, then the 'cargo new' command will sort the members list, thus ensuring that the members list is in order.

This is the corresponding code

let was_sorted = members.iter().map(Value::as_str).is_sorted();
members.push(display_path);
if was_sorted {
members.sort_by(|lhs, rhs| lhs.as_str().cmp(&rhs.as_str()));
}

I had a big list of members, so i need to hack these code to sort the members.

@epage
Copy link
Contributor

epage commented Nov 12, 2024

When we added cargo add to Cargo, we removed a --sort flag, instead saying formatting control is outside of the scope of that command and should instead live in a dedicated formatter. There is an issue for adding formatting to cargo fmt and I think that should instead be the focusd

@linyihai
Copy link
Contributor Author

There is an issue for adding formatting to cargo fmt and I think that should instead be the focusd

Yes, after the sorting is done, it actually needs additional formatting.

@epage
Copy link
Contributor

epage commented Nov 12, 2024

Sorting is part of formatting, like formatting of uses in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants