Skip to content

Extract shared diff spatial types#154

Merged
benvinegar merged 1 commit intomainfrom
pi/extract-diff-spatial-types
Apr 1, 2026
Merged

Extract shared diff spatial types#154
benvinegar merged 1 commit intomainfrom
pi/extract-diff-spatial-types

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • extract reusable VerticalBounds and SectionGeometry types into src/ui/lib/diffSpatial.ts
  • update planned review row geometry and diff section geometry to share the same spatial model
  • keep the existing hunk-specific metadata layered on top of the shared bounds types

Testing

  • bun run typecheck
  • bun test test/diff-section-geometry.test.ts test/ui-lib.test.ts

This PR description was generated by Pi using OpenAI o3

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR extracts the shared spatial primitive types VerticalBounds and SectionGeometry<THunkBounds> from the two geometry modules into a new src/ui/lib/diffSpatial.ts file, then threads them through PlannedHunkBounds, PlannedSectionGeometry, DiffSectionRowBounds, and DiffSectionGeometry via extends/type aliases. There are no functional changes — only structural deduplication of previously inline type declarations.

  • New diffSpatial.ts introduces VerticalBounds (top, height) and the generic SectionGeometry<THunkBounds extends VerticalBounds>.
  • PlannedHunkBounds now extends VerticalBounds and PlannedSectionGeometry becomes a type alias for SectionGeometry<PlannedHunkBounds>.
  • DiffSectionRowBounds and DiffSectionGeometry similarly adopt the shared base types while preserving their extra fields (rowBounds, rowBoundsByKey).
  • The private rowContributesToHunkBounds helper remains duplicated in both plannedReviewRows.ts and diffSectionGeometry.ts; since the PR is already consolidating shared spatial code, extracting this helper as a follow-up would complete the unification.

Confidence Score: 5/5

Safe to merge — this is a pure type-level refactor with no functional changes to runtime logic.

All three changed files produce structurally identical TypeScript shapes to their pre-PR versions; the only change is where the top/height/bodyHeight/hunkAnchorRows/hunkBounds properties are declared. No logic, caching, or measurement code was altered. The single P2 comment flags a pre-existing duplicate helper that could be consolidated but does not block merging.

No files require special attention.

Important Files Changed

Filename Overview
src/ui/lib/diffSpatial.ts New file introducing the shared VerticalBounds and generic SectionGeometry<THunkBounds> types extracted from both geometry modules; clean and well-documented.
src/ui/diff/plannedReviewRows.ts PlannedHunkBounds now extends VerticalBounds and PlannedSectionGeometry is aliased to SectionGeometry<PlannedHunkBounds>; structurally identical to the previous inline declarations, no functional change.
src/ui/lib/diffSectionGeometry.ts DiffSectionRowBounds and DiffSectionGeometry now derive from the shared types; all fields preserved, caching and measurement logic unchanged.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class VerticalBounds {
        +number top
        +number height
    }

    class SectionGeometry~THunkBounds~ {
        +number bodyHeight
        +Map~number,number~ hunkAnchorRows
        +Map~number,THunkBounds~ hunkBounds
    }

    class PlannedHunkBounds {
        +string startRowId
        +string endRowId
    }

    class PlannedSectionGeometry

    class DiffSectionRowBounds {
        +string key
    }

    class DiffSectionGeometry {
        +DiffSectionRowBounds[] rowBounds
        +Map~string,DiffSectionRowBounds~ rowBoundsByKey
    }

    VerticalBounds <|-- PlannedHunkBounds : extends
    VerticalBounds <|-- DiffSectionRowBounds : extends
    SectionGeometry <|.. PlannedSectionGeometry : alias (THunkBounds=PlannedHunkBounds)
    SectionGeometry <|-- DiffSectionGeometry : extends (THunkBounds=PlannedHunkBounds)
Loading

Comments Outside Diff (1)

  1. src/ui/diff/plannedReviewRows.ts, line 28-32 (link)

    P2 Duplicated rowContributesToHunkBounds function

    An identical rowContributesToHunkBounds function lives in both src/ui/diff/plannedReviewRows.ts (lines 28–32) and src/ui/lib/diffSectionGeometry.ts (lines 83–87). Since this PR is already extracting shared spatial utilities into diffSpatial.ts, this helper could be moved there (or a sibling shared module) and imported by both callers, keeping the rule consistent in one place.

Reviews (1): Last reviewed commit: "Extract shared diff spatial types" | Re-trigger Greptile

@benvinegar benvinegar merged commit 24fe074 into main Apr 1, 2026
3 checks passed
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.

1 participant