@@ -18,7 +18,7 @@ namespace ts.textStorage {
18
18
const ts2 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
19
19
20
20
ts1 . useScriptVersionCache_TestOnly ( ) ;
21
- ts2 . useText ( ) ;
21
+ ts2 . useText_TestOnly ( ) ;
22
22
23
23
const lineMap = computeLineStarts ( f . content ) ;
24
24
@@ -29,20 +29,20 @@ namespace ts.textStorage {
29
29
for ( let offset = 0 ; offset < end - start ; offset ++ ) {
30
30
const pos1 = ts1 . lineOffsetToPosition ( line + 1 , offset + 1 ) ;
31
31
const pos2 = ts2 . lineOffsetToPosition ( line + 1 , offset + 1 ) ;
32
- assert . isTrue ( pos1 === pos2 , `lineOffsetToPosition ${ line + 1 } -${ offset + 1 } : expected ${ pos1 } to equal ${ pos2 } ` ) ;
32
+ assert . strictEqual ( pos1 , pos2 , `lineOffsetToPosition ${ line + 1 } -${ offset + 1 } : expected ${ pos1 } to equal ${ pos2 } ` ) ;
33
33
}
34
34
35
35
const { start : start1 , length : length1 } = ts1 . lineToTextSpan ( line ) ;
36
36
const { start : start2 , length : length2 } = ts2 . lineToTextSpan ( line ) ;
37
- assert . isTrue ( start1 === start2 , `lineToTextSpan ${ line } ::start:: expected ${ start1 } to equal ${ start2 } ` ) ;
38
- assert . isTrue ( length1 === length2 , `lineToTextSpan ${ line } ::length:: expected ${ length1 } to equal ${ length2 } ` ) ;
37
+ assert . strictEqual ( start1 , start2 , `lineToTextSpan ${ line } ::start:: expected ${ start1 } to equal ${ start2 } ` ) ;
38
+ assert . strictEqual ( length1 , length2 , `lineToTextSpan ${ line } ::length:: expected ${ length1 } to equal ${ length2 } ` ) ;
39
39
}
40
40
41
41
for ( let pos = 0 ; pos < f . content . length ; pos ++ ) {
42
42
const { line : line1 , offset : offset1 } = ts1 . positionToLineOffset ( pos ) ;
43
43
const { line : line2 , offset : offset2 } = ts2 . positionToLineOffset ( pos ) ;
44
- assert . isTrue ( line1 === line2 , `positionToLineOffset ${ pos } ::line:: expected ${ line1 } to equal ${ line2 } ` ) ;
45
- assert . isTrue ( offset1 === offset2 , `positionToLineOffset ${ pos } ::offset:: expected ${ offset1 } to equal ${ offset2 } ` ) ;
44
+ assert . strictEqual ( line1 , line2 , `positionToLineOffset ${ pos } ::line:: expected ${ line1 } to equal ${ line2 } ` ) ;
45
+ assert . strictEqual ( offset1 , offset2 , `positionToLineOffset ${ pos } ::offset:: expected ${ offset1 } to equal ${ offset2 } ` ) ;
46
46
}
47
47
} ) ;
48
48
@@ -52,16 +52,93 @@ namespace ts.textStorage {
52
52
const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
53
53
54
54
ts1 . getSnapshot ( ) ;
55
- assert . isTrue ( ! ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 1" ) ;
55
+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 1" ) ;
56
56
57
57
ts1 . edit ( 0 , 5 , " " ) ;
58
58
assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) , "have script version cache - 1" ) ;
59
59
60
- ts1 . useText ( ) ;
61
- assert . isTrue ( ! ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 2" ) ;
60
+ ts1 . useText_TestOnly ( ) ;
61
+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) , "should not have script version cache - 2" ) ;
62
62
63
63
ts1 . getLineInfo ( 0 ) ;
64
64
assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) , "have script version cache - 2" ) ;
65
65
} ) ;
66
+
67
+ it ( "should be able to return the file size immediately after construction" , ( ) => {
68
+ const host = projectSystem . createServerHost ( [ f ] ) ;
69
+ // Since script info is not used in these tests, just cheat by passing undefined
70
+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
71
+
72
+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
73
+ } ) ;
74
+
75
+ it ( "should be able to return the file size when backed by text" , ( ) => {
76
+ const host = projectSystem . createServerHost ( [ f ] ) ;
77
+ // Since script info is not used in these tests, just cheat by passing undefined
78
+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
79
+
80
+ ts1 . useText_TestOnly ( f . content ) ;
81
+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
82
+
83
+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
84
+ } ) ;
85
+
86
+ it ( "should be able to return the file size when backed by a script version cache" , ( ) => {
87
+ const host = projectSystem . createServerHost ( [ f ] ) ;
88
+ // Since script info is not used in these tests, just cheat by passing undefined
89
+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( f . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
90
+
91
+ ts1 . useScriptVersionCache_TestOnly ( ) ;
92
+ assert . isTrue ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
93
+
94
+ assert . strictEqual ( f . content . length , ts1 . getTelemetryFileSize ( ) ) ;
95
+ } ) ;
96
+
97
+ it ( "should be able to return the file size when a JS file is too large to load into text" , ( ) => {
98
+ const largeFile = {
99
+ path : "/a/large.js" ,
100
+ content : " " . repeat ( server . maxFileSize + 1 )
101
+ } ;
102
+
103
+ const host = projectSystem . createServerHost ( [ largeFile ] ) ;
104
+
105
+ // The large-file handling requires a ScriptInfo with a containing project
106
+ const projectService = projectSystem . createProjectService ( host ) ;
107
+ projectService . openClientFile ( largeFile . path ) ;
108
+ const scriptInfo = projectService . getScriptInfo ( largeFile . path ) ;
109
+
110
+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( largeFile . path ) , /*initialVersion*/ undefined , scriptInfo ! ) ;
111
+
112
+ assert . isTrue ( ts1 . reloadFromDisk ( ) ) ;
113
+ assert . isFalse ( ts1 . hasScriptVersionCache_TestOnly ( ) ) ;
114
+
115
+ assert . strictEqual ( largeFile . content . length , ts1 . getTelemetryFileSize ( ) ) ;
116
+ } ) ;
117
+
118
+ it ( "should return the file size without reloading the file" , ( ) => {
119
+ const oldText = "hello" ;
120
+ const newText = "goodbye" ;
121
+
122
+ const changingFile = {
123
+ path : "/a/changing.ts" ,
124
+ content : oldText
125
+ } ;
126
+
127
+ const host = projectSystem . createServerHost ( [ changingFile ] ) ;
128
+ // Since script info is not used in these tests, just cheat by passing undefined
129
+ const ts1 = new server . TextStorage ( host , server . asNormalizedPath ( changingFile . path ) , /*initialVersion*/ undefined , /*info*/ undefined ! ) ;
130
+
131
+ assert . isTrue ( ts1 . reloadFromDisk ( ) ) ;
132
+
133
+ // Refresh the file and notify TextStorage
134
+ host . writeFile ( changingFile . path , newText ) ;
135
+ ts1 . delayReloadFromFileIntoText ( ) ;
136
+
137
+ assert . strictEqual ( oldText . length , ts1 . getTelemetryFileSize ( ) ) ;
138
+
139
+ assert . isTrue ( ts1 . reloadWithFileText ( ) ) ;
140
+
141
+ assert . strictEqual ( newText . length , ts1 . getTelemetryFileSize ( ) ) ;
142
+ } ) ;
66
143
} ) ;
67
144
}
0 commit comments