fix: Move AOT entry comments with reordered entries - #275
Merged
Conversation
Normalize trailing comments parsed inside consecutive AOT entries to Document-level siblings so resolveSlots can assign them correctly. Move entire slots (entry + owned comments) as a unit during reorder so comments follow their entries when updateOrder is enabled. Fixes two test.fails tests for AOT comment reordering.
There was a problem hiding this comment.
Pull request overview
This PR improves array-of-tables (AOT) reordering so that entry-associated comments move together with their [[...]] entries during a reorder (notably when updateOrder is enabled), addressing a parser quirk where comments between consecutive [[x]] headers are initially attached to the preceding entry.
Changes:
- Add a CST normalization pass to promote “between-entry” trailing comments to document-level siblings so slot ownership can be resolved correctly.
- Update the AOT move/reorder path to move an entire resolved “slot” (entry + owned comments) instead of just the entry node.
- Enable and adjust tests that validate comment behavior during AOT entry reorders.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/patch.ts | Normalizes AOT comment placement and moves resolved ownership slots during AOT reorders. |
| src/tests/patch.test.ts | Updates reorder tests to assert comment placement now matches reordered AOT entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add optional leadingLines parameter to insert()/insertOnNewLine() so callers can override the default blank-line spacing. Use leadingLines: 1 when inserting a TableArray that follows a comment in the same slot, avoiding the extra blank line insert() normally adds between them. Compensate reduced exit offset on non-prepend inserts by shifting subsequent items down.
Compute leadingLines from the original document spacing rather than hardcoding values, so blank lines between comments and entries, and between consecutive entries, are preserved exactly as in the source. Only applies when both source and target slots have leading comments (a true swap of commented AOT entries). Also restores the original gap between the moved slot and subsequent items via exit-offset compensation.
Expand leadingLines override to also apply when the source has comments and there is content before the insertion point — not just when both source and target slots have leading comments. This preserves the original blank line between a severed (R3) comment and the moved entry in mixed-spacing documents.
DecimalTurn
marked this pull request as ready for review
August 8, 2026 07:17
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.
Move entire slots (entry + owned comments) as a unit during reorder so comments follow their entries when updateOrder is enabled.