3
3
compareStringsCaseSensitive ,
4
4
Debug ,
5
5
identity ,
6
+ isString ,
6
7
noop ,
7
8
} from "./_namespaces/ts" ;
8
9
import {
@@ -15,6 +16,8 @@ import {
15
16
ProjectKind ,
16
17
ProjectService ,
17
18
ScriptInfo ,
19
+ SourceMapFileWatcher ,
20
+ TextStorage ,
18
21
} from "./_namespaces/ts.server" ;
19
22
import {
20
23
LoggerWithInMemoryLogs ,
@@ -24,18 +27,26 @@ interface ProjectData {
24
27
projectStateVersion : Project [ "projectStateVersion" ] ;
25
28
projectProgramVersion : Project [ "projectProgramVersion" ] ;
26
29
dirty : Project [ "dirty" ] ;
27
- isClosed : boolean ;
28
- isOrphan : boolean ;
30
+ isClosed : ReturnType < Project [ "isClosed" ] > ;
31
+ isOrphan : ReturnType < Project [ "isOrphan" ] > ;
29
32
noOpenRef : boolean ;
30
33
autoImportProviderHost : Project [ "autoImportProviderHost" ] ;
31
34
noDtsResolutionProject : Project [ "noDtsResolutionProject" ] ;
32
35
originalConfiguredProjects : Project [ "originalConfiguredProjects" ] ;
33
36
}
34
37
38
+ interface SourceMapFileWatcherData {
39
+ sourceInfos : SourceMapFileWatcher [ "sourceInfos" ] ;
40
+ }
41
+
35
42
interface ScriptInfoData {
36
- open : boolean ;
37
- version : string ;
38
- pendingReloadFromDisk : boolean ;
43
+ open : ReturnType < ScriptInfo [ "isScriptOpen" ] > ;
44
+ version : ReturnType < TextStorage [ "getVersion" ] > ;
45
+ pendingReloadFromDisk : TextStorage [ "pendingReloadFromDisk" ] ;
46
+ sourceMapFilePath : Exclude < ScriptInfo [ "sourceMapFilePath" ] , SourceMapFileWatcher > | SourceMapFileWatcherData | undefined ;
47
+ declarationInfoPath : ScriptInfo [ "declarationInfoPath" ] ;
48
+ sourceInfos : ScriptInfo [ "sourceInfos" ] ;
49
+ documentPositionMapper : ScriptInfo [ "documentPositionMapper" ] ;
39
50
containingProjects : Set < Project > ;
40
51
}
41
52
@@ -46,7 +57,8 @@ enum Diff {
46
57
Deleted = " *deleted*" ,
47
58
}
48
59
49
- type StateItemLog = [ string , ...string [ ] [ ] ] ;
60
+ type StatePropertyLog = string | string [ ] ;
61
+ type StateItemLog = [ string , StatePropertyLog [ ] ] ;
50
62
51
63
export function patchServiceForStateBaseline ( service : ProjectService ) {
52
64
if ( ! service . logger . isTestLogger || ! service . logger . hasLevel ( LogLevel . verbose ) ) return ;
@@ -69,9 +81,9 @@ export function patchServiceForStateBaseline(service: ProjectService) {
69
81
if ( ! logs ) return ;
70
82
logger . log ( title ) ;
71
83
logs . sort ( ( a , b ) => compareStringsCaseSensitive ( a [ 0 ] , b [ 0 ] ) )
72
- . forEach ( ( [ title , ... propertyLogs ] ) => {
84
+ . forEach ( ( [ title , propertyLogs ] ) => {
73
85
logger . log ( title ) ;
74
- propertyLogs . forEach ( p => p . forEach ( s => logger . log ( s ) ) ) ;
86
+ propertyLogs . forEach ( p => isString ( p ) ? logger . log ( p ) : p . forEach ( s => logger . log ( s ) ) ) ;
75
87
} ) ;
76
88
logger . log ( "" ) ;
77
89
}
@@ -99,11 +111,11 @@ export function patchServiceForStateBaseline(service: ProjectService) {
99
111
logs ,
100
112
`${ project . projectName } (${ ProjectKind [ project . projectKind ] } )` ,
101
113
PrintPropertyWhen . DefinedOrChangedOrNew ,
114
+ data ?. originalConfiguredProjects ,
102
115
"originalConfiguredProjects" ,
103
- projectPropertyLogs ,
104
- projectDiff ,
105
116
project . originalConfiguredProjects ,
106
- data ?. originalConfiguredProjects ,
117
+ projectDiff ,
118
+ projectPropertyLogs ,
107
119
identity ,
108
120
) ;
109
121
} ,
@@ -132,6 +144,10 @@ export function patchServiceForStateBaseline(service: ProjectService) {
132
144
infoDiff = printProperty ( PrintPropertyWhen . Changed , data , "open" , isOpen , infoDiff , infoPropertyLogs ) ;
133
145
infoDiff = printProperty ( PrintPropertyWhen . Always , data , "version" , info . textStorage . getVersion ( ) , infoDiff , infoPropertyLogs ) ;
134
146
infoDiff = printProperty ( PrintPropertyWhen . TruthyOrChangedOrNew , data , "pendingReloadFromDisk" , info . textStorage . pendingReloadFromDisk , infoDiff , infoPropertyLogs ) ;
147
+ infoDiff = printScriptInfoSourceMapFilePath ( data , info , infoDiff , infoPropertyLogs ) ;
148
+ infoDiff = printProperty ( PrintPropertyWhen . DefinedOrChangedOrNew , data , "declarationInfoPath" , info . declarationInfoPath , infoDiff , infoPropertyLogs ) ;
149
+ infoDiff = printSetPropertyValueWorker ( PrintPropertyWhen . DefinedOrChangedOrNew , data ?. sourceInfos , "sourceInfos" , info . sourceInfos , infoDiff , infoPropertyLogs , identity ) ;
150
+ infoDiff = printProperty ( PrintPropertyWhen . DefinedOrChangedOrNew , data , "documentPositionMapper" , info . documentPositionMapper , infoDiff , infoPropertyLogs , info . documentPositionMapper ? "DocumentPositionMapper" : undefined ) ;
135
151
let defaultProject : Project | undefined ;
136
152
try {
137
153
if ( isOpen ) defaultProject = info . getDefaultProject ( ) ;
@@ -143,18 +159,24 @@ export function patchServiceForStateBaseline(service: ProjectService) {
143
159
logs ,
144
160
`${ info . fileName } ${ info . isDynamic ? " (Dynamic)" : "" } ${ isOpen ? " (Open)" : "" } ` ,
145
161
PrintPropertyWhen . Always ,
162
+ data ?. containingProjects ,
146
163
"containingProjects" ,
147
- infoPropertyLogs ,
148
- infoDiff ,
149
164
new Set ( info . containingProjects ) ,
150
- data ?. containingProjects ,
165
+ infoDiff ,
166
+ infoPropertyLogs ,
151
167
project => `${ project . projectName } ${ defaultProject === project ? " *default*" : "" } ` ,
152
168
) ;
153
169
} ,
154
170
info => ( {
155
171
open : info . isScriptOpen ( ) ,
156
172
version : info . textStorage . getVersion ( ) ,
157
173
pendingReloadFromDisk : info . textStorage . pendingReloadFromDisk ,
174
+ sourceMapFilePath : info . sourceMapFilePath && ! isString ( info . sourceMapFilePath ) ?
175
+ { original : info . sourceMapFilePath , sourceInfos : new Set ( info . sourceMapFilePath . sourceInfos ) } :
176
+ info . sourceMapFilePath ,
177
+ declarationInfoPath : info . declarationInfoPath ,
178
+ sourceInfos : info . sourceInfos && new Set ( info . sourceInfos ) ,
179
+ documentPositionMapper : info . documentPositionMapper ,
158
180
containingProjects : new Set ( info . containingProjects ) ,
159
181
} ) ,
160
182
) ;
@@ -207,40 +229,40 @@ export function patchServiceForStateBaseline(service: ProjectService) {
207
229
key : Key ,
208
230
value : Data [ Key ] ,
209
231
dataDiff : Diff ,
210
- propertyLogs : string [ ] ,
232
+ propertyLogs : StatePropertyLog [ ] ,
211
233
stringValue ?: Data [ Key ] | string ,
212
234
) {
213
235
return printPropertyWorker (
214
236
printWhen ,
215
- `${ key } : ${ stringValue === undefined ? value : stringValue } ` ,
216
- propertyLogs ,
217
- dataDiff ,
237
+ value ,
218
238
! ! data && data [ key ] !== value ,
219
239
Diff . Change ,
220
- value ,
240
+ dataDiff ,
241
+ propertyLogs ,
242
+ `${ key } : ${ stringValue === undefined ? value : stringValue } ` ,
221
243
) ;
222
244
}
223
245
224
246
function printSetPropertyValueWorker < T > (
225
247
printWhen : PrintPropertyWhen . Always | PrintPropertyWhen . DefinedOrChangedOrNew ,
248
+ dataValue : Set < T > | undefined ,
226
249
propertyName : string ,
227
- propertyLogs : string [ ] ,
228
- dataDiff : Diff ,
229
250
propertyValue : Set < T > | undefined ,
230
- dataValue : Set < T > | undefined ,
251
+ dataDiff : Diff ,
252
+ propertyLogs : StatePropertyLog [ ] ,
231
253
toStringPropertyValue : ( v : T ) => string ,
232
254
) {
233
255
const setPropertyLogs = [ ] as string [ ] ;
234
256
let setPropertyDiff = Diff . None ;
235
257
propertyValue ?. forEach ( p =>
236
258
setPropertyDiff = printPropertyWorker (
237
259
PrintPropertyWhen . Always ,
238
- ` ${ toStringPropertyValue ( p ) } ` ,
239
- setPropertyLogs ,
240
- setPropertyDiff ,
260
+ p ,
241
261
dataDiff !== Diff . New && ! dataValue ?. has ( p ) ,
242
262
Diff . New ,
243
- p ,
263
+ setPropertyDiff ,
264
+ setPropertyLogs ,
265
+ ` ${ toStringPropertyValue ( p ) } ` ,
244
266
)
245
267
) ;
246
268
dataValue ?. forEach ( p => {
@@ -250,24 +272,25 @@ export function patchServiceForStateBaseline(service: ProjectService) {
250
272
} ) ;
251
273
dataDiff = printPropertyWorker (
252
274
printWhen ,
253
- `${ propertyName } : ${ propertyValue ?. size || 0 } ` ,
254
- propertyLogs ,
255
- dataDiff ,
275
+ propertyValue ,
256
276
! ! setPropertyDiff ,
257
277
Diff . Change ,
258
- propertyValue ,
278
+ dataDiff ,
279
+ propertyLogs ,
280
+ `${ propertyName } : ${ propertyValue ?. size || 0 } ` ,
259
281
) ;
260
- return { dataDiff, setPropertyLogs } ;
282
+ propertyLogs . push ( setPropertyLogs ) ;
283
+ return dataDiff ;
261
284
}
262
285
263
286
function printPropertyWorker (
264
287
printWhen : PrintPropertyWhen ,
265
- stringValue : string ,
266
- propertyLogs : string [ ] ,
267
- dataDiff : Diff ,
288
+ value : any ,
268
289
propertyChanged : boolean ,
269
290
propertyChangeDiff : Diff . Change | Diff . New ,
270
- value : any ,
291
+ dataDiff : Diff ,
292
+ propertyLogs : StatePropertyLog [ ] ,
293
+ stringValue : string ,
271
294
) {
272
295
const propertyDiff = propertyChanged ? propertyChangeDiff : Diff . None ;
273
296
const result = ! dataDiff && propertyDiff ? propertyChangeDiff : dataDiff ;
@@ -294,27 +317,52 @@ export function patchServiceForStateBaseline(service: ProjectService) {
294
317
logs : StateItemLog [ ] ,
295
318
header : string ,
296
319
printWhen : PrintPropertyWhen . Always | PrintPropertyWhen . DefinedOrChangedOrNew ,
320
+ dataValue : Set < T > | undefined ,
297
321
propertyName : string ,
298
- propertyLogs : string [ ] ,
299
- dataDiff : Diff ,
300
322
propertyValue : Set < T > | undefined ,
301
- dataValue : Set < T > | undefined ,
323
+ dataDiff : Diff ,
324
+ propertyLogs : StatePropertyLog [ ] ,
302
325
toStringPropertyValue : ( v : T ) => string ,
303
326
) {
304
- const result = printSetPropertyValueWorker (
327
+ dataDiff = printSetPropertyValueWorker (
305
328
printWhen ,
329
+ dataValue ,
306
330
propertyName ,
307
- propertyLogs ,
308
- dataDiff ,
309
331
propertyValue ,
310
- dataValue ,
332
+ dataDiff ,
333
+ propertyLogs ,
311
334
toStringPropertyValue ,
312
335
) ;
313
336
logs . push ( [
314
- `${ header } ${ result . dataDiff } ` ,
337
+ `${ header } ${ dataDiff } ` ,
315
338
propertyLogs ,
316
- result . setPropertyLogs ,
317
339
] ) ;
318
- return result . dataDiff ;
340
+ return dataDiff ;
341
+ }
342
+
343
+ function printScriptInfoSourceMapFilePath (
344
+ data : ScriptInfoData | undefined ,
345
+ info : ScriptInfo ,
346
+ infoDiff : Diff ,
347
+ infoPropertyLogs : StatePropertyLog [ ] ,
348
+ ) {
349
+ return ! info . sourceMapFilePath || isString ( info . sourceMapFilePath ) ?
350
+ printProperty (
351
+ PrintPropertyWhen . DefinedOrChangedOrNew ,
352
+ data ,
353
+ "sourceMapFilePath" ,
354
+ info . sourceMapFilePath ,
355
+ infoDiff ,
356
+ infoPropertyLogs ,
357
+ ) :
358
+ printSetPropertyValueWorker (
359
+ PrintPropertyWhen . DefinedOrChangedOrNew ,
360
+ data ?. sourceMapFilePath && ! isString ( data ?. sourceMapFilePath ) ? data . sourceMapFilePath . sourceInfos : undefined ,
361
+ "sourceMapFilePath sourceInfos" ,
362
+ info . sourceMapFilePath . sourceInfos ,
363
+ infoDiff ,
364
+ infoPropertyLogs ,
365
+ identity ,
366
+ ) ;
319
367
}
320
368
}
0 commit comments