Skip to content

fix: Move AOT entry comments with reordered entries - #275

Merged
DecimalTurn merged 10 commits into
latestfrom
dev-fix-aot-tests
Aug 9, 2026
Merged

fix: Move AOT entry comments with reordered entries#275
DecimalTurn merged 10 commits into
latestfrom
dev-fix-aot-tests

Conversation

@DecimalTurn

Copy link
Copy Markdown
Owner

Move entire slots (entry + owned comments) as a unit during reorder so comments follow their entries when updateOrder is enabled.

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.
Copilot AI lite review requested due to automatic review settings August 7, 2026 18:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/patch.ts
Comment thread src/__tests__/patch.test.ts
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
DecimalTurn marked this pull request as ready for review August 8, 2026 07:17
@DecimalTurn
DecimalTurn merged commit db61dec into latest Aug 9, 2026
8 checks passed
@DecimalTurn
DecimalTurn deleted the dev-fix-aot-tests branch August 9, 2026 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants