Skip to content
Source
Sign inSign up
TanStack/highlight

Preserve source text and annotation metadata #25

MergedM-Hassan-Raza(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/25/headmerged by tannerlinsley

Ignore non-integer, empty and reversed character ranges to prevent source duplication. Preserve own line-annotation metadata keys and avoid an intermediate line-offset array.

pnpm verify passes: 118 tests and all size/benchmark budgets. Three regression tests fail against the original source.

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Warning

      Review limit reached

      You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

      Next included review available in 21 minutes.

      Check out review usage here.

      View limit details

      Limit details: You’ve used the included review currently available.

      Learn how review limits work.

      Review configuration:

      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 4f25f709-a89f-4d7a-9698-1c7faad396e9
      Commits

      Reviewing files that changed from the base of the PR and between 5b6a0db26115f2c4db080b12ae196b809063115a and 86d3adaef2a6d8ae13080a9377852ca090ae0b56.

      Files selected for processing: 7
      • .changeset/valid-decoration-offsets.md
      • docs/guides/annotations.md
      • docs/reference/core.md
      • src/core.ts
      • src/internal/render.ts
      • test/core.test.ts
      • test/hast-render-target.test.ts

      No actionable comments were generated in the recent review.

      Walkthrough

      The renderer now ignores decorations with invalid offsets, clips out-of-bounds ranges as documented, updates newline traversal, and preserves arbitrary line-decoration data keys. Tests cover invalid ranges and metadata merging.

      Changes: Decoration rendering

      Layer / File(s)Summary
      Validate and render decorations
      src/core.ts, test/core.test.ts, docs/guides/annotations.md, docs/reference/core.md, .changeset/valid-decoration-offsets.md
      The renderer filters non-integer, empty, and reversed ranges, and updates newline traversal. It creates merged metadata only when decorations provide data. Tests cover invalid offsets and metadata keys; documentation and the changeset describe the behavior.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Suggested reviewers: tannerlinsley

      Merge Risk: Minimal · previous review 5b6a0

      This change makes the renderer ignore invalid decoration ranges and keep arbitrary line metadata keys. It has regression tests and updated docs. No merge-blocking risk is evident.

      Architecture risk: Medium · up to 5b6a0

      The change affects 3 systems.

      Changed systems: src, docs, test

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — src (service) was modified; 1 changed file maps to changed impact.
      • observed — docs (service) was modified; 2 changed files map to changed impact.
      • observed — test (service) was modified; 1 changed file maps to changed impact.

      Before / after behavior

      • observed — Modified behavior in docs/guides/annotations.md: The renderer description now documents integer offsets, the start < end requirement, ignoring invalid ranges, and clipping ranges that extend beyond the source.
      • observed — Modified behavior in docs/reference/core.md: The range-offset documentation now states that non-integer offsets and ranges where start is not less than end are ignored, and that out-of-bounds ranges are clipped to the source.
      • observed — Modified behavior in src/core.ts: renderTokens now filters range decorations to integer offsets with start < end. It replaces the wrapLines flag with a direct check for line numbers or line decorations, and iterates through the code by locating newline characters.
      • observed — Modified behavior in src/core.ts: The line loop now stops when no newline remains or the next line would start at the end of the code; otherwise it emits the newline and advances. This replaces the previous hasNewline-based newline emission.

      Reliability and maintainability

      • inferred — Risk-relevant change factors for src: blast_radius_1; direct_dependents_1
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (3 skipped: 3 …Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly describes the primary changes: preserving source text and annotation metadata.
      Description check✅ PassedThe description covers the behavior changes and validation results. It includes the required Changes and Validation sections, reports 118 passing tests and size/benchmark results, but does not identif…
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (3 skipped: 3 unsupported.)

      Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Advanced

      Run ID: c873ad8c-b720-4302-86b9-324261700882

      📥 Commits

      Reviewing files that changed from the base of the PR and between 8c2a665876d44af388e21ef71abbe9b09e740156 and 5b6a0db26115f2c4db080b12ae196b809063115a.

      📒 Files selected for processing (5)
      • .changeset/valid-decoration-offsets.md
      • docs/guides/annotations.md
      • docs/reference/core.md
      • src/core.ts
      • test/core.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

    2. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 86d3adaef2a6d8ae13080a9377852ca090ae0b56

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/highlightPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    3. Thanks for working on annotation rendering! I brought the branch up to date and kept invalid ranges from changing the rendered source.

      AI review notes: The updated branch ignores non-integer, empty and reversed character ranges, preserves arbitrary own line-metadata keys, and retains streaming line scanning. The correction and regressions passed local current-main composition checks. The updated branch still needs its own current CI before merging.

    4. tannerlinsley merged this1e75b89

    5. tannerlinsley closed this

Sign in to join this conversation.