@@ -322,15 +322,14 @@ namespace ts.server {
322322 reload ( script : string ) {
323323 this . currentVersion ++ ;
324324 this . changes = [ ] ; // history wiped out by reload
325- const snap = new LineIndexSnapshot ( this . currentVersion , this ) ;
325+ const snap = new LineIndexSnapshot ( this . currentVersion , this , new LineIndex ( ) ) ;
326326
327327 // delete all versions
328328 for ( let i = 0 ; i < this . versions . length ; i ++ ) {
329329 this . versions [ i ] = undefined ;
330330 }
331331
332332 this . versions [ this . currentVersionToIndex ( ) ] = snap ;
333- snap . index = new LineIndex ( ) ;
334333 const lm = LineIndex . linesFromText ( script ) ;
335334 snap . index . load ( lm . lines ) ;
336335
@@ -344,9 +343,7 @@ namespace ts.server {
344343 for ( const change of this . changes ) {
345344 snapIndex = snapIndex . edit ( change . pos , change . deleteLen , change . insertedText ) ;
346345 }
347- snap = new LineIndexSnapshot ( this . currentVersion + 1 , this ) ;
348- snap . index = snapIndex ;
349- snap . changesSincePreviousVersion = this . changes ;
346+ snap = new LineIndexSnapshot ( this . currentVersion + 1 , this , snapIndex , this . changes ) ;
350347
351348 this . currentVersion = snap . version ;
352349 this . versions [ this . currentVersionToIndex ( ) ] = snap ;
@@ -382,21 +379,17 @@ namespace ts.server {
382379
383380 static fromString ( host : ServerHost , script : string ) {
384381 const svc = new ScriptVersionCache ( ) ;
385- const snap = new LineIndexSnapshot ( 0 , svc ) ;
382+ const snap = new LineIndexSnapshot ( 0 , svc , new LineIndex ( ) ) ;
386383 svc . versions [ svc . currentVersion ] = snap ;
387384 svc . host = host ;
388- snap . index = new LineIndex ( ) ;
389385 const lm = LineIndex . linesFromText ( script ) ;
390386 snap . index . load ( lm . lines ) ;
391387 return svc ;
392388 }
393389 }
394390
395391 export class LineIndexSnapshot implements ts . IScriptSnapshot {
396- index : LineIndex ;
397- changesSincePreviousVersion : TextChange [ ] = [ ] ;
398-
399- constructor ( readonly version : number , readonly cache : ScriptVersionCache ) {
392+ constructor ( readonly version : number , readonly cache : ScriptVersionCache , readonly index : LineIndex , readonly changesSincePreviousVersion : ReadonlyArray < TextChange > = emptyArray ) {
400393 }
401394
402395 getText ( rangeStart : number , rangeEnd : number ) {
@@ -407,37 +400,14 @@ namespace ts.server {
407400 return this . index . root . charCount ( ) ;
408401 }
409402
410- // this requires linear space so don't hold on to these
411- getLineStartPositions ( ) : number [ ] {
412- const starts : number [ ] = [ - 1 ] ;
413- let count = 1 ;
414- let pos = 0 ;
415- this . index . every ( ll => {
416- starts [ count ] = pos ;
417- count ++ ;
418- pos += ll . text . length ;
419- return true ;
420- } , 0 ) ;
421- return starts ;
422- }
423-
424- getLineMapper ( ) {
425- return ( line : number ) => {
426- return this . index . lineNumberToInfo ( line ) . offset ;
427- } ;
428- }
429-
430- getTextChangeRangeSinceVersion ( scriptVersion : number ) {
431- if ( this . version <= scriptVersion ) {
432- return ts . unchangedTextChangeRange ;
433- }
434- else {
435- return this . cache . getTextChangesBetweenVersions ( scriptVersion , this . version ) ;
436- }
437- }
438403 getChangeRange ( oldSnapshot : ts . IScriptSnapshot ) : ts . TextChangeRange {
439404 if ( oldSnapshot instanceof LineIndexSnapshot && this . cache === oldSnapshot . cache ) {
440- return this . getTextChangeRangeSinceVersion ( oldSnapshot . version ) ;
405+ if ( this . version <= oldSnapshot . version ) {
406+ return ts . unchangedTextChangeRange ;
407+ }
408+ else {
409+ return this . cache . getTextChangesBetweenVersions ( oldSnapshot . version , this . version ) ;
410+ }
441411 }
442412 }
443413 }
0 commit comments