-
-
Notifications
You must be signed in to change notification settings - Fork 115
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 by crate lexicographical order #513
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
For coherence, I think we should use the same value for Eq and Ord (even though for well-formed keys it shouldn't matter for the current PR):
- either the cleaned key (
String
) - or the dot-separated cleaned key (
Vec<String>
)
The whole issue being that we need to compare the Split instead of the String itself, I believe the only option is then to use the Split for Eq as well. |
Yes, we should use the same value for all comparisons: Eq and Ord. The choice between |
I'm not sure I understand. If we use "foo.bar" for Ord, don't we have exactly the same problem as before? |
Sorry, what I meant was |
I apologize, I still must have misunderstood something. From what I had gathered, the problem comes from the fact that the |
I thought the problem was that the order between With my solution, if I understand correctly, the order would be the same because in both cases we would be comparing But if you not only want consistency, but also proper ordering (i.e. one of |
Ok, got it now, thanks. Then I think I don't have new modifications to write. I'm not sure what's the correct process now: should I re-ask for a review or is that implied by this conversation? |
I apologize, I realize my previous message was far from clear 🥲 Thanks to your explanations, I now see how your solution provides consistency, but I would prefer the solution where that ordering is also consistent with the "classical" alphabetical order ( |
Yes, both were fine with me. So let's modify the |
No problem, thanks, I'll push the Vec modification in a min. For my curiosity (still learning :) ): wouldn't that require more allocations than just splitting in place every time? Do you prefer it because it's easier to read at the (arguably low) cost of a few additional allocation? |
Yes, there's one more allocation, but this is not high performance code (as you might have seen by the previous code allocating strings on every comparison) so it's not a concern. However readability and correctness by construction is more important here. In particular the fact that the comparison key exists in only one place is the key factor. Even without the comparison key being cached I would have been fine (i.e. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me modulo the import formatting.
Thanks for the explanations, very clear and makes a lot of sense! |
Thanks, I appreciate your patience and comments/explanations during my first contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Out of curiosity, how does the release process work ? I've seen that the commit has been released as part of release-taplo-0.13.0, and I was wondering how it translates in terms of the vscode extension. Thanks for your insights |
Fixes #511.
First time contributing to an open-source project, so please let me know if I've done anything wrong or how I can improve. Also should I squash my commits before submitting the PR?
And running cargo fmt completely changes the way the imports are structured, so I ended up saving without formatting, but I'm not sure if that's what's intended