11namespace ts . server {
2- export interface ScriptInfoVersion {
3- svc : number ;
4- text : number ;
5- }
6-
72 /* @internal */
83 export class TextStorage {
9- version : ScriptInfoVersion ;
4+ version : string | undefined ;
105
116 /**
127 * Generated only on demand (based on edits, or information requested)
@@ -46,14 +41,7 @@ namespace ts.server {
4641 */
4742 private pendingReloadFromDisk = false ;
4843
49- constructor ( private readonly host : ServerHost , private readonly info : ScriptInfo , initialVersion ?: ScriptInfoVersion ) {
50- this . version = initialVersion || { svc : 0 , text : 0 } ;
51- }
52-
53- public getVersion ( ) {
54- return this . svc
55- ? `SVC-${ this . version . svc } -${ this . svc . getSnapshotVersion ( ) } `
56- : `Text-${ this . version . text } ` ;
44+ constructor ( private readonly host : ServerHost , private readonly info : ScriptInfo ) {
5745 }
5846
5947 public hasScriptVersionCache_TestOnly ( ) {
@@ -77,16 +65,17 @@ namespace ts.server {
7765 public useText ( newText ?: string ) {
7866 this . svc = undefined ;
7967 this . text = newText ;
68+ this . version = undefined ;
8069 this . lineMap = undefined ;
8170 this . fileSize = undefined ;
8271 this . resetSourceMapInfo ( ) ;
83- this . version . text ++ ;
8472 }
8573
8674 public edit ( start : number , end : number , newText : string ) {
8775 this . switchToScriptVersionCache ( ) . edit ( start , end - start , newText ) ;
8876 this . ownFileText = false ;
8977 this . text = undefined ;
78+ this . version = undefined ;
9079 this . lineMap = undefined ;
9180 this . fileSize = undefined ;
9281 this . resetSourceMapInfo ( ) ;
@@ -142,6 +131,7 @@ namespace ts.server {
142131
143132 public delayReloadFromFileIntoText ( ) {
144133 this . pendingReloadFromDisk = true ;
134+ this . version = undefined ;
145135 }
146136
147137 /**
@@ -225,7 +215,6 @@ namespace ts.server {
225215 private switchToScriptVersionCache ( ) : ScriptVersionCache {
226216 if ( ! this . svc || this . pendingReloadFromDisk ) {
227217 this . svc = ScriptVersionCache . fromString ( this . getOrLoadText ( ) ) ;
228- this . version . svc ++ ;
229218 }
230219 return this . svc ;
231220 }
@@ -334,10 +323,10 @@ namespace ts.server {
334323 readonly scriptKind : ScriptKind ,
335324 public readonly hasMixedContent : boolean ,
336325 readonly path : Path ,
337- initialVersion ?: ScriptInfoVersion ) {
326+ ) {
338327 this . isDynamic = isDynamicFileName ( fileName ) ;
339328
340- this . textStorage = new TextStorage ( host , this , initialVersion ) ;
329+ this . textStorage = new TextStorage ( host , this ) ;
341330 if ( hasMixedContent || this . isDynamic ) {
342331 this . textStorage . reload ( "" ) ;
343332 this . realpath = this . path ;
@@ -347,11 +336,6 @@ namespace ts.server {
347336 : getScriptKindFromFileName ( fileName ) ;
348337 }
349338
350- /*@internal */
351- getVersion ( ) {
352- return this . textStorage . version ;
353- }
354-
355339 /*@internal */
356340 getTelemetryFileSize ( ) {
357341 return this . textStorage . getTelemetryFileSize ( ) ;
@@ -559,10 +543,15 @@ namespace ts.server {
559543 }
560544 }
561545
562- getLatestVersion ( ) : string {
546+ getLatestVersion ( ) {
563547 // Ensure we have updated snapshot to give back latest version
564- this . textStorage . getSnapshot ( ) ;
565- return this . textStorage . getVersion ( ) ;
548+ const snapShot = this . textStorage . getSnapshot ( ) ;
549+ if ( this . textStorage . version === undefined ) {
550+ // Ensure we have updated snapshot to give back latest version
551+ const text = getSnapshotText ( snapShot ) ;
552+ this . textStorage . version = this . host . createHash ? this . host . createHash ( text ) : generateDjb2Hash ( text ) ;
553+ }
554+ return this . textStorage . version ;
566555 }
567556
568557 saveTo ( fileName : string ) {
0 commit comments