[Repo Assist] Fix trailing indented comment after last match clause / DU case de-indented to column 0#3306
Closed
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
…s in mutually recursive type (fixes #3174) Root cause: genOnelinerAttributes merged all AttributeListNodes into a single one-liner, dropping ContentBefore trivia (including #if/#endif directives) from all but the MultipleAttributeListNode itself. When the define was active, extra attribute lists existed and their per-list directives were silently dropped, producing a different hash-fragment count than the no-define variant and causing mergeMultipleFormatResults to throw a FormatException. Fix (CodePrinter.fs): - genOnelinerAttributes detects when any AttributeListNode at index ≥ 1 has a compiler directive in its ContentBefore, and falls back to rendering each list individually via genNode (preserving ContentBefore trivia) with sepNln between lists and sepSpace after the last, keeping the type name on the same line as the final attribute. - genTypeDefn detects directive-containing attribute lists for 'and' type definitions and forces indent/unindent so the formatted output is valid F# in both define variants (column-0 attributes after 'and' are a parse error). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… de-indented to column 0 Closes #2653 Closes #2606 Root cause: when a trailing comment appears after the last match clause or discriminated union case, its range falls outside the range of ExprMatchNode / TypeDefnUnionNode. However, because includeTrivia extends Oak.Range to cover all code comments, findNodeWhereRangeFitsIn returns Some(Oak). simpleTriviaToTriviaInstruction then attaches the comment as ContentAfter on ModuleOrNamespaceNode (which has indent 0), causing the comment to be printed at column 0 instead of its original column. Fix (Trivia.fs): Before falling back to the last-child AddAfter attachment, check whether there is a shallower node that ends on the line immediately before the comment and whose start column matches the comment's start column. findNodeEndingOnLine uses a shallowest-first traversal so that it finds ExprMatchNode (or TypeDefnUnionNode) rather than a deeply nested child token that happens to share the same end position. The comment is then attached as ContentAfter on that node, which is rendered at the correct indentation level. Fix (CodePrinter.fs): addFinalNewline previously checked only the head WriterEvent. Because the trivia-triggered WriteLineBecauseOfTrivia is now emitted inside atCurrentColumn, structural RestoreAtColumn/RestoreIndent events appear after it. Updated addFinalNewline to skip those non-content events (matching the approach already used by lastWriteEventIsNewline) so that a trailing trivia newline is still recognised and no extra blank line is appended. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Insufficient |
33 tasks
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 was created by Repo Assist, an automated AI assistant.
Closes #2653
Closes #2606
Root Cause
When a trailing comment appears after the last match clause or discriminated union case, its range falls outside the range of
ExprMatchNode/TypeDefnUnionNode. However,includeTriviainASTTransformer.fsextendsOak.Rangeto cover all code comments, sofindNodeWhereRangeFitsInreturnsSome(Oak).simpleTriviaToTriviaInstructionthen falls through to the "last child AddAfter" path and attaches the comment asContentAfteronModuleOrNamespaceNode(indent = 0), causing it to be printed at column 0 instead of its original column.Before:
After:
All 2742 tests pass including the two new regression tests.