55namespace ts . server {
66 const lineCollectionCapacity = 4 ;
77
8- export interface LineCollection {
8+ interface LineCollection {
99 charCount ( ) : number ;
1010 lineCount ( ) : number ;
1111 isLeaf ( ) : this is LineLeaf ;
@@ -17,7 +17,7 @@ namespace ts.server {
1717 lineText : string | undefined ;
1818 }
1919
20- export enum CharRangeSection {
20+ const enum CharRangeSection {
2121 PreStart ,
2222 Start ,
2323 Entire ,
@@ -26,7 +26,7 @@ namespace ts.server {
2626 PostEnd
2727 }
2828
29- export interface ILineIndexWalker {
29+ interface ILineIndexWalker {
3030 goSubtree : boolean ;
3131 done : boolean ;
3232 leaf ( relativeStart : number , relativeLength : number , lineCollection : LineLeaf ) : void ;
@@ -243,7 +243,7 @@ namespace ts.server {
243243 }
244244
245245 // text change information
246- export class TextChange {
246+ class TextChange {
247247 constructor ( public pos : number , public deleteLen : number , public insertedText ?: string ) {
248248 }
249249
@@ -285,17 +285,6 @@ namespace ts.server {
285285 }
286286 }
287287
288- latest ( ) {
289- return this . versions [ this . currentVersionToIndex ( ) ] ;
290- }
291-
292- latestVersion ( ) {
293- if ( this . changes . length > 0 ) {
294- this . getSnapshot ( ) ;
295- }
296- return this . currentVersion ;
297- }
298-
299288 // reload whole script, leaving no change history behind reload
300289 reload ( script : string ) {
301290 this . currentVersion ++ ;
@@ -314,7 +303,9 @@ namespace ts.server {
314303 this . minVersion = this . currentVersion ;
315304 }
316305
317- getSnapshot ( ) {
306+ getSnapshot ( ) : IScriptSnapshot { return this . _getSnapshot ( ) ; }
307+
308+ private _getSnapshot ( ) : LineIndexSnapshot {
318309 let snap = this . versions [ this . currentVersionToIndex ( ) ] ;
319310 if ( this . changes . length > 0 ) {
320311 let snapIndex = snap . index ;
@@ -334,6 +325,29 @@ namespace ts.server {
334325 return snap ;
335326 }
336327
328+ getSnapshotVersion ( ) : number {
329+ return this . _getSnapshot ( ) . version ;
330+ }
331+
332+ getLineInfo ( line : number ) : AbsolutePositionAndLineText {
333+ return this . _getSnapshot ( ) . index . lineNumberToInfo ( line ) ;
334+ }
335+
336+ lineOffsetToPosition ( line : number , column : number ) : number {
337+ return this . _getSnapshot ( ) . index . absolutePositionOfStartOfLine ( line ) + ( column - 1 ) ;
338+ }
339+
340+ positionToLineOffset ( position : number ) : protocol . Location {
341+ return this . _getSnapshot ( ) . index . positionToLineOffset ( position ) ;
342+ }
343+
344+ lineToTextSpan ( line : number ) : TextSpan {
345+ const index = this . _getSnapshot ( ) . index ;
346+ const { lineText, absolutePosition } = index . lineNumberToInfo ( line + 1 ) ;
347+ const len = lineText !== undefined ? lineText . length : index . absolutePositionOfStartOfLine ( line + 2 ) - absolutePosition ;
348+ return createTextSpan ( absolutePosition , len ) ;
349+ }
350+
337351 getTextChangesBetweenVersions ( oldVersion : number , newVersion : number ) {
338352 if ( oldVersion < newVersion ) {
339353 if ( oldVersion >= this . minVersion ) {
@@ -365,7 +379,7 @@ namespace ts.server {
365379 }
366380 }
367381
368- export class LineIndexSnapshot implements IScriptSnapshot {
382+ class LineIndexSnapshot implements IScriptSnapshot {
369383 constructor ( readonly version : number , readonly cache : ScriptVersionCache , readonly index : LineIndex , readonly changesSincePreviousVersion : ReadonlyArray < TextChange > = emptyArray ) {
370384 }
371385
@@ -389,6 +403,7 @@ namespace ts.server {
389403 }
390404 }
391405
406+ /* @internal */
392407 export class LineIndex {
393408 root : LineNode ;
394409 // set this to true to check each edit for accuracy
@@ -561,7 +576,7 @@ namespace ts.server {
561576 }
562577 }
563578
564- export class LineNode implements LineCollection {
579+ class LineNode implements LineCollection {
565580 totalChars = 0 ;
566581 totalLines = 0 ;
567582
@@ -844,7 +859,7 @@ namespace ts.server {
844859 }
845860 }
846861
847- export class LineLeaf implements LineCollection {
862+ class LineLeaf implements LineCollection {
848863 constructor ( public text : string ) {
849864 }
850865
0 commit comments