11import { sampledChecksum } from "@opencode-ai/shared/util/encode"
22import {
3- DEFAULT_VIRTUAL_FILE_METRICS ,
43 type DiffLineAnnotation ,
54 type FileContents ,
65 type FileDiffMetadata ,
@@ -10,10 +9,6 @@ import {
109 type FileOptions ,
1110 type LineAnnotation ,
1211 type SelectedLineRange ,
13- type VirtualFileMetrics ,
14- VirtualizedFile ,
15- VirtualizedFileDiff ,
16- Virtualizer ,
1712} from "@pierre/diffs"
1813import { type PreloadFileDiffResult , type PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
1914import { createMediaQuery } from "@solid-primitives/media"
@@ -40,19 +35,10 @@ import {
4035 readShadowLineSelection ,
4136} from "../pierre/file-selection"
4237import { createLineNumberSelectionBridge , restoreShadowTextSelection } from "../pierre/selection-bridge"
43- import { acquireVirtualizer , virtualMetrics } from "../pierre/virtualizer"
4438import { getWorkerPool } from "../pierre/worker"
4539import { FileMedia , type FileMediaOptions } from "./file-media"
4640import { FileSearchBar } from "./file-search"
4741
48- const VIRTUALIZE_BYTES = 500_000
49-
50- const codeMetrics = {
51- ...DEFAULT_VIRTUAL_FILE_METRICS ,
52- lineHeight : 24 ,
53- fileGap : 0 ,
54- } satisfies Partial < VirtualFileMetrics >
55-
5642type SharedProps < T > = {
5743 annotations ?: LineAnnotation < T > [ ] | DiffLineAnnotation < T > [ ]
5844 selectedLines ?: SelectedLineRange | null
@@ -386,11 +372,6 @@ type AnnotationTarget<A> = {
386372 rerender : ( ) => void
387373}
388374
389- type VirtualStrategy = {
390- get : ( ) => Virtualizer | undefined
391- cleanup : ( ) => void
392- }
393-
394375function useModeViewer ( config : ModeConfig , adapter : ModeAdapter ) {
395376 return useFileViewer ( {
396377 enableLineSelection : config . enableLineSelection ,
@@ -532,64 +513,6 @@ function scrollParent(el: HTMLElement): HTMLElement | undefined {
532513 }
533514}
534515
535- function createLocalVirtualStrategy ( host : ( ) => HTMLDivElement | undefined , enabled : ( ) => boolean ) : VirtualStrategy {
536- let virtualizer : Virtualizer | undefined
537- let root : Document | HTMLElement | undefined
538-
539- const release = ( ) => {
540- virtualizer ?. cleanUp ( )
541- virtualizer = undefined
542- root = undefined
543- }
544-
545- return {
546- get : ( ) => {
547- if ( ! enabled ( ) ) {
548- release ( )
549- return
550- }
551- if ( typeof document === "undefined" ) return
552-
553- const wrapper = host ( )
554- if ( ! wrapper ) return
555-
556- const next = scrollParent ( wrapper ) ?? document
557- if ( virtualizer && root === next ) return virtualizer
558-
559- release ( )
560- virtualizer = new Virtualizer ( )
561- root = next
562- virtualizer . setup ( next , next instanceof Document ? undefined : wrapper )
563- return virtualizer
564- } ,
565- cleanup : release ,
566- }
567- }
568-
569- function createSharedVirtualStrategy ( host : ( ) => HTMLDivElement | undefined ) : VirtualStrategy {
570- let shared : NonNullable < ReturnType < typeof acquireVirtualizer > > | undefined
571-
572- const release = ( ) => {
573- shared ?. release ( )
574- shared = undefined
575- }
576-
577- return {
578- get : ( ) => {
579- if ( shared ) return shared . virtualizer
580-
581- const container = host ( )
582- if ( ! container ) return
583-
584- const result = acquireVirtualizer ( container )
585- if ( ! result ) return
586- shared = result
587- return result . virtualizer
588- } ,
589- cleanup : release ,
590- }
591- }
592-
593516function parseLine ( node : HTMLElement ) {
594517 if ( ! node . dataset . line ) return
595518 const value = parseInt ( node . dataset . line , 10 )
@@ -688,7 +611,7 @@ function ViewerShell(props: {
688611// ---------------------------------------------------------------------------
689612
690613function TextViewer < T > ( props : TextFileProps < T > ) {
691- let instance : PierreFile < T > | VirtualizedFile < T > | undefined
614+ let instance : PierreFile < T > | undefined
692615 let viewer ! : Viewer
693616
694617 const [ local , others ] = splitProps ( props , textKeys )
@@ -708,36 +631,12 @@ function TextViewer<T>(props: TextFileProps<T>) {
708631 return Math . max ( 1 , total )
709632 }
710633
711- const bytes = createMemo ( ( ) => {
712- const value = local . file . contents as unknown
713- if ( typeof value === "string" ) return value . length
714- if ( Array . isArray ( value ) ) {
715- return value . reduce (
716- // oxlint-disable-next-line no-base-to-string -- array parts coerced intentionally
717- ( sum , part ) => sum + ( typeof part === "string" ? part . length + 1 : String ( part ) . length + 1 ) ,
718- 0 ,
719- )
720- }
721- if ( value == null ) return 0
722- // oxlint-disable-next-line no-base-to-string -- file contents cast to unknown, coercion is intentional
723- return String ( value ) . length
724- } )
725-
726- const virtual = createMemo ( ( ) => bytes ( ) > VIRTUALIZE_BYTES )
727-
728- const virtuals = createLocalVirtualStrategy ( ( ) => viewer . wrapper , virtual )
729-
730634 const lineFromMouseEvent = ( event : MouseEvent ) : MouseHit => mouseHit ( event , parseLine )
731635
732636 const applySelection = ( range : SelectedLineRange | null ) => {
733637 const current = instance
734638 if ( ! current ) return false
735639
736- if ( virtual ( ) ) {
737- current . setSelectedLines ( range )
738- return true
739- }
740-
741640 const root = viewer . getRoot ( )
742641 if ( ! root ) return false
743642
@@ -836,10 +735,7 @@ function TextViewer<T>(props: TextFileProps<T>) {
836735 const notify = ( ) => {
837736 notifyRendered ( {
838737 viewer,
839- isReady : ( root ) => {
840- if ( virtual ( ) ) return root . querySelector ( "[data-line]" ) != null
841- return root . querySelectorAll ( "[data-line]" ) . length >= lineCount ( )
842- } ,
738+ isReady : ( root ) => root . querySelectorAll ( "[data-line]" ) . length >= lineCount ( ) ,
843739 onReady : ( ) => {
844740 applySelection ( viewer . lastSelection )
845741 viewer . find . refresh ( { reset : true } )
@@ -858,17 +754,11 @@ function TextViewer<T>(props: TextFileProps<T>) {
858754 createEffect ( ( ) => {
859755 const opts = options ( )
860756 const workerPool = getWorkerPool ( "unified" )
861- const isVirtual = virtual ( )
862-
863- const virtualizer = virtuals . get ( )
864757
865758 renderViewer ( {
866759 viewer,
867760 current : instance ,
868- create : ( ) =>
869- isVirtual && virtualizer
870- ? new VirtualizedFile < T > ( opts , virtualizer , codeMetrics , workerPool )
871- : new PierreFile < T > ( opts , workerPool ) ,
761+ create : ( ) => new PierreFile < T > ( opts , workerPool ) ,
872762 assign : ( value ) => {
873763 instance = value
874764 } ,
@@ -895,7 +785,6 @@ function TextViewer<T>(props: TextFileProps<T>) {
895785 onCleanup ( ( ) => {
896786 instance ?. cleanUp ( )
897787 instance = undefined
898- virtuals . cleanup ( )
899788 } )
900789
901790 return < ViewerShell mode = "text" viewer = { viewer } class = { local . class } classList = { local . classList } />
@@ -991,8 +880,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
991880 adapter ,
992881 )
993882
994- const virtuals = createSharedVirtualStrategy ( ( ) => viewer . container )
995-
996883 const large = createMemo ( ( ) => {
997884 if ( local . fileDiff ) {
998885 const before = local . fileDiff . deletionLines . join ( "" )
@@ -1055,7 +942,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1055942 createEffect ( ( ) => {
1056943 const opts = options ( )
1057944 const workerPool = large ( ) ? getWorkerPool ( "unified" ) : getWorkerPool ( props . diffStyle )
1058- const virtualizer = virtuals . get ( )
1059945 const beforeContents = typeof local . before ?. contents === "string" ? local . before . contents : ""
1060946 const afterContents = typeof local . after ?. contents === "string" ? local . after . contents : ""
1061947 const done = preserve ( viewer )
@@ -1070,10 +956,7 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1070956 renderViewer ( {
1071957 viewer,
1072958 current : instance ,
1073- create : ( ) =>
1074- virtualizer
1075- ? new VirtualizedFileDiff < T > ( opts , virtualizer , virtualMetrics , workerPool )
1076- : new FileDiff < T > ( opts , workerPool ) ,
959+ create : ( ) => new FileDiff < T > ( opts , workerPool ) ,
1077960 assign : ( value ) => {
1078961 instance = value
1079962 } ,
@@ -1111,7 +994,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1111994 onCleanup ( ( ) => {
1112995 instance ?. cleanUp ( )
1113996 instance = undefined
1114- virtuals . cleanup ( )
1115997 dragSide = undefined
1116998 dragEndSide = undefined
1117999 } )
0 commit comments