1
1
namespace ts . server {
2
- export interface ScriptInfoVersion {
3
- svc : number ;
4
- text : number ;
5
- }
6
-
7
2
/* @internal */
8
3
export class TextStorage {
9
- version : ScriptInfoVersion ;
4
+ version : string | undefined ;
10
5
11
6
/**
12
7
* Generated only on demand (based on edits, or information requested)
@@ -46,14 +41,7 @@ namespace ts.server {
46
41
*/
47
42
private pendingReloadFromDisk = false ;
48
43
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 ) {
57
45
}
58
46
59
47
public hasScriptVersionCache_TestOnly ( ) {
@@ -77,16 +65,17 @@ namespace ts.server {
77
65
public useText ( newText ?: string ) {
78
66
this . svc = undefined ;
79
67
this . text = newText ;
68
+ this . version = undefined ;
80
69
this . lineMap = undefined ;
81
70
this . fileSize = undefined ;
82
71
this . resetSourceMapInfo ( ) ;
83
- this . version . text ++ ;
84
72
}
85
73
86
74
public edit ( start : number , end : number , newText : string ) {
87
75
this . switchToScriptVersionCache ( ) . edit ( start , end - start , newText ) ;
88
76
this . ownFileText = false ;
89
77
this . text = undefined ;
78
+ this . version = undefined ;
90
79
this . lineMap = undefined ;
91
80
this . fileSize = undefined ;
92
81
this . resetSourceMapInfo ( ) ;
@@ -142,6 +131,7 @@ namespace ts.server {
142
131
143
132
public delayReloadFromFileIntoText ( ) {
144
133
this . pendingReloadFromDisk = true ;
134
+ this . version = undefined ;
145
135
}
146
136
147
137
/**
@@ -225,7 +215,6 @@ namespace ts.server {
225
215
private switchToScriptVersionCache ( ) : ScriptVersionCache {
226
216
if ( ! this . svc || this . pendingReloadFromDisk ) {
227
217
this . svc = ScriptVersionCache . fromString ( this . getOrLoadText ( ) ) ;
228
- this . version . svc ++ ;
229
218
}
230
219
return this . svc ;
231
220
}
@@ -334,10 +323,10 @@ namespace ts.server {
334
323
readonly scriptKind : ScriptKind ,
335
324
public readonly hasMixedContent : boolean ,
336
325
readonly path : Path ,
337
- initialVersion ?: ScriptInfoVersion ) {
326
+ ) {
338
327
this . isDynamic = isDynamicFileName ( fileName ) ;
339
328
340
- this . textStorage = new TextStorage ( host , this , initialVersion ) ;
329
+ this . textStorage = new TextStorage ( host , this ) ;
341
330
if ( hasMixedContent || this . isDynamic ) {
342
331
this . textStorage . reload ( "" ) ;
343
332
this . realpath = this . path ;
@@ -347,11 +336,6 @@ namespace ts.server {
347
336
: getScriptKindFromFileName ( fileName ) ;
348
337
}
349
338
350
- /*@internal */
351
- getVersion ( ) {
352
- return this . textStorage . version ;
353
- }
354
-
355
339
/*@internal */
356
340
getTelemetryFileSize ( ) {
357
341
return this . textStorage . getTelemetryFileSize ( ) ;
@@ -559,10 +543,15 @@ namespace ts.server {
559
543
}
560
544
}
561
545
562
- getLatestVersion ( ) : string {
546
+ getLatestVersion ( ) {
563
547
// 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 ;
566
555
}
567
556
568
557
saveTo ( fileName : string ) {
0 commit comments