Don't duplicate separators when there is a comment before and after a list separator - #7091
Open
randomPoison wants to merge 1 commit into
Open
Don't duplicate separators when there is a comment before and after a list separator#7091randomPoison wants to merge 1 commit into
randomPoison wants to merge 1 commit into
Conversation
…ator - Update get_comment_end to split the post-snippet at the separator if there are comments before and after the separator. - Update extract_post_comment to handle a separator in the middle of the final item's post-snippet, since the final item has special handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the following issues:
This fix relates to the list formatting machinery in
lists.rs, specifically the way that the post-snippet for a list item is parsed in order to extract comments. In the case where there is a comment both before and after a separator in a list,get_comment_endwould include the entire gap between the items as the post-snippet of the preceding item. This means that the separator gets included in the post-comment of the preceding item. Whenwrite_listthen lays out the pieces of the list, it prints a separator and then the entire post-comment, which duplicates the separator.There are two related fixes for this behavior:
get_comment_endto split the post-snippet at the separator if there are comments before and after the separator. This means that the comment before the separator becomes the post-comment of the preceding item, and the comment after the separator becomes the pre-comment for the following item.extract_post_commentto handle a separator in the middle of the final item's post-snippet. This is necessary because the new splitting rule inget_comment_enddoesn't apply the snippet following the final item, since there's no subsequent item to own the comment that follows the separator. To handle this case, we just remove the separator from the post-snippet, which then allowswrite_listto lay out the separator before the post-comment.I added a test to cover the cases described in #6759 and #6797.
LLM Usage Disclosure
I used an LLM, specifically gpt-5.6 Sol, as a coding aid while working on this fix:
extract_post_commentwere written by LLM and then heavily rewritten by me. The only thing LLM-written that stayed verbatim is the logic for extracting the separator from the post-snippet.