@@ -246,7 +246,7 @@ module FourSlash {
246
246
247
247
export class TestState {
248
248
// Language service instance
249
- private languageServiceAdaptorHost : Harness . LanguageService . LanguageServiceAdaptorHost ;
249
+ private languageServiceAdapterHost : Harness . LanguageService . LanguageServiceAdapterHost ;
250
250
private languageService : ts . LanguageService ;
251
251
private cancellationToken : TestCancellationToken ;
252
252
@@ -272,32 +272,28 @@ module FourSlash {
272
272
private addMatchedInputFile ( referenceFilePath : string ) {
273
273
var inputFile = this . inputFiles [ referenceFilePath ] ;
274
274
if ( inputFile && ! Harness . isLibraryFile ( referenceFilePath ) ) {
275
- this . languageServiceAdaptorHost . addScript ( referenceFilePath , inputFile ) ;
275
+ this . languageServiceAdapterHost . addScript ( referenceFilePath , inputFile ) ;
276
276
}
277
277
}
278
278
279
- private getLanguageServiceAdaptor ( testType : FourSlashTestType ) :
280
- { new ( cancellationToken ?: ts . CancellationToken , options ?: ts . CompilerOptions ) : Harness . LanguageService . LanguageServiceAdaptor } {
279
+ private getLanguageServiceAdapter ( testType : FourSlashTestType , cancellationToken : TestCancellationToken , compilationOptions : ts . CompilerOptions ) : Harness . LanguageService . LanguageServiceAdapter {
281
280
switch ( testType ) {
282
281
case FourSlashTestType . Native :
283
- return Harness . LanguageService . NativeLanugageServiceAdaptor ;
284
- break ;
282
+ return new Harness . LanguageService . NativeLanugageServiceAdapter ( cancellationToken , compilationOptions ) ;
285
283
case FourSlashTestType . Shims :
286
- return Harness . LanguageService . ShimLanugageServiceAdaptor ;
287
- break ;
284
+ return new Harness . LanguageService . ShimLanugageServiceAdapter ( cancellationToken , compilationOptions ) ;
288
285
default :
289
286
throw new Error ( "Unknown FourSlash test type: " ) ;
290
287
}
291
288
}
292
289
293
290
constructor ( private basePath : string , private testType : FourSlashTestType , public testData : FourSlashData ) {
294
- // Create a new Services Adaptor
291
+ // Create a new Services Adapter
295
292
this . cancellationToken = new TestCancellationToken ( ) ;
296
293
var compilationOptions = convertGlobalOptionsToCompilerOptions ( this . testData . globalOptions ) ;
297
- var languageserviceAdaptorFactory = this . getLanguageServiceAdaptor ( testType ) ;
298
- var languageServiceAdaptor = new languageserviceAdaptorFactory ( this . cancellationToken , compilationOptions ) ;
299
- this . languageServiceAdaptorHost = languageServiceAdaptor . getHost ( ) ;
300
- this . languageService = languageServiceAdaptor . getLanguageService ( ) ;
294
+ var languageServiceAdapter = this . getLanguageServiceAdapter ( testType , this . cancellationToken , compilationOptions ) ;
295
+ this . languageServiceAdapterHost = languageServiceAdapter . getHost ( ) ;
296
+ this . languageService = languageServiceAdapter . getLanguageService ( ) ;
301
297
302
298
// Initialize the language service with all the scripts
303
299
var startResolveFileRef : FourSlashFile ;
@@ -315,16 +311,16 @@ module FourSlash {
315
311
316
312
if ( startResolveFileRef ) {
317
313
// Add the entry-point file itself into the languageServiceShimHost
318
- this . languageServiceAdaptorHost . addScript ( startResolveFileRef . fileName , startResolveFileRef . content ) ;
314
+ this . languageServiceAdapterHost . addScript ( startResolveFileRef . fileName , startResolveFileRef . content ) ;
319
315
320
- var resolvedResult = languageServiceAdaptor . getPreProcessedFileInfo ( startResolveFileRef . fileName , startResolveFileRef . content ) ;
316
+ var resolvedResult = languageServiceAdapter . getPreProcessedFileInfo ( startResolveFileRef . fileName , startResolveFileRef . content ) ;
321
317
var referencedFiles : ts . FileReference [ ] = resolvedResult . referencedFiles ;
322
318
var importedFiles : ts . FileReference [ ] = resolvedResult . importedFiles ;
323
319
324
320
// Add triple reference files into language-service host
325
321
ts . forEach ( referencedFiles , referenceFile => {
326
322
// Fourslash insert tests/cases/fourslash into inputFile.unitName so we will properly append the same base directory to refFile path
327
- var referenceFilePath = this . basePath + '/' + referenceFile . fileName ;
323
+ var referenceFilePath = this . basePath + '/' + referenceFile . fileName ;
328
324
this . addMatchedInputFile ( referenceFilePath ) ;
329
325
} ) ;
330
326
@@ -338,16 +334,16 @@ module FourSlash {
338
334
339
335
// Check if no-default-lib flag is false and if so add default library
340
336
if ( ! resolvedResult . isLibFile ) {
341
- this . languageServiceAdaptorHost . addScript ( Harness . Compiler . defaultLibFileName , Harness . Compiler . defaultLibSourceFile . text ) ;
337
+ this . languageServiceAdapterHost . addScript ( Harness . Compiler . defaultLibFileName , Harness . Compiler . defaultLibSourceFile . text ) ;
342
338
}
343
339
} else {
344
340
// resolveReference file-option is not specified then do not resolve any files and include all inputFiles
345
341
ts . forEachKey ( this . inputFiles , fileName => {
346
342
if ( ! Harness . isLibraryFile ( fileName ) ) {
347
- this . languageServiceAdaptorHost . addScript ( fileName , this . inputFiles [ fileName ] ) ;
343
+ this . languageServiceAdapterHost . addScript ( fileName , this . inputFiles [ fileName ] ) ;
348
344
}
349
345
} ) ;
350
- this . languageServiceAdaptorHost . addScript ( Harness . Compiler . defaultLibFileName , Harness . Compiler . defaultLibSourceFile . text ) ;
346
+ this . languageServiceAdapterHost . addScript ( Harness . Compiler . defaultLibFileName , Harness . Compiler . defaultLibSourceFile . text ) ;
351
347
}
352
348
353
349
this . formatCodeOptions = {
@@ -376,7 +372,7 @@ module FourSlash {
376
372
}
377
373
378
374
private getFileContent ( fileName : string ) : string {
379
- var script = this . languageServiceAdaptorHost . getScriptInfo ( fileName ) ;
375
+ var script = this . languageServiceAdapterHost . getScriptInfo ( fileName ) ;
380
376
return script . content ;
381
377
}
382
378
@@ -464,7 +460,7 @@ module FourSlash {
464
460
private getAllDiagnostics ( ) : ts . Diagnostic [ ] {
465
461
var diagnostics : ts . Diagnostic [ ] = [ ] ;
466
462
467
- var fileNames = this . languageServiceAdaptorHost . getFilenames ( ) ;
463
+ var fileNames = this . languageServiceAdapterHost . getFilenames ( ) ;
468
464
for ( var i = 0 , n = fileNames . length ; i < n ; i ++ ) {
469
465
diagnostics . push . apply ( this . getDiagnostics ( fileNames [ i ] ) ) ;
470
466
}
@@ -1255,7 +1251,7 @@ module FourSlash {
1255
1251
}
1256
1252
1257
1253
public printContext ( ) {
1258
- ts . forEach ( this . languageServiceAdaptorHost . getFilenames ( ) , Harness . IO . log ) ;
1254
+ ts . forEach ( this . languageServiceAdapterHost . getFilenames ( ) , Harness . IO . log ) ;
1259
1255
}
1260
1256
1261
1257
public deleteChar ( count = 1 ) {
@@ -1268,7 +1264,7 @@ module FourSlash {
1268
1264
1269
1265
for ( var i = 0 ; i < count ; i ++ ) {
1270
1266
// Make the edit
1271
- this . languageServiceAdaptorHost . editScript ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1267
+ this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1272
1268
this . updateMarkersForEdit ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1273
1269
1274
1270
if ( i % checkCadence === 0 ) {
@@ -1295,7 +1291,7 @@ module FourSlash {
1295
1291
public replace ( start : number , length : number , text : string ) {
1296
1292
this . taoInvalidReason = 'replace NYI' ;
1297
1293
1298
- this . languageServiceAdaptorHost . editScript ( this . activeFile . fileName , start , start + length , text ) ;
1294
+ this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , start , start + length , text ) ;
1299
1295
this . updateMarkersForEdit ( this . activeFile . fileName , start , start + length , text ) ;
1300
1296
this . checkPostEditInvariants ( ) ;
1301
1297
}
@@ -1310,7 +1306,7 @@ module FourSlash {
1310
1306
for ( var i = 0 ; i < count ; i ++ ) {
1311
1307
offset -- ;
1312
1308
// Make the edit
1313
- this . languageServiceAdaptorHost . editScript ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1309
+ this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1314
1310
this . updateMarkersForEdit ( this . activeFile . fileName , offset , offset + 1 , ch ) ;
1315
1311
1316
1312
if ( i % checkCadence === 0 ) {
@@ -1355,7 +1351,7 @@ module FourSlash {
1355
1351
for ( var i = 0 ; i < text . length ; i ++ ) {
1356
1352
// Make the edit
1357
1353
var ch = text . charAt ( i ) ;
1358
- this . languageServiceAdaptorHost . editScript ( this . activeFile . fileName , offset , offset , ch ) ;
1354
+ this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , offset , offset , ch ) ;
1359
1355
this . languageService . getBraceMatchingAtPosition ( this . activeFile . fileName , offset ) ;
1360
1356
1361
1357
this . updateMarkersForEdit ( this . activeFile . fileName , offset , offset , ch ) ;
@@ -1398,7 +1394,7 @@ module FourSlash {
1398
1394
1399
1395
var start = this . currentCaretPosition ;
1400
1396
var offset = this . currentCaretPosition ;
1401
- this . languageServiceAdaptorHost . editScript ( this . activeFile . fileName , offset , offset , text ) ;
1397
+ this . languageServiceAdapterHost . editScript ( this . activeFile . fileName , offset , offset , text ) ;
1402
1398
this . updateMarkersForEdit ( this . activeFile . fileName , offset , offset , text ) ;
1403
1399
this . checkPostEditInvariants ( ) ;
1404
1400
offset += text . length ;
@@ -1461,7 +1457,7 @@ module FourSlash {
1461
1457
// Get a snapshot of the content of the file so we can make sure any formatting edits didn't destroy non-whitespace characters
1462
1458
var oldContent = this . getFileContent ( this . activeFile . fileName ) ;
1463
1459
for ( var j = 0 ; j < edits . length ; j ++ ) {
1464
- this . languageServiceAdaptorHost . editScript ( fileName , edits [ j ] . span . start + runningOffset , ts . textSpanEnd ( edits [ j ] . span ) + runningOffset , edits [ j ] . newText ) ;
1460
+ this . languageServiceAdapterHost . editScript ( fileName , edits [ j ] . span . start + runningOffset , ts . textSpanEnd ( edits [ j ] . span ) + runningOffset , edits [ j ] . newText ) ;
1465
1461
this . updateMarkersForEdit ( fileName , edits [ j ] . span . start + runningOffset , ts . textSpanEnd ( edits [ j ] . span ) + runningOffset , edits [ j ] . newText ) ;
1466
1462
var change = ( edits [ j ] . span . start - ts . textSpanEnd ( edits [ j ] . span ) ) + edits [ j ] . newText . length ;
1467
1463
runningOffset += change ;
@@ -1742,8 +1738,8 @@ module FourSlash {
1742
1738
1743
1739
function jsonMismatchString ( ) {
1744
1740
return ts . sys . newLine +
1745
- "expected: '" + ts . sys . newLine + JSON . stringify ( expected , ( k , v ) => v , 2 ) + "'" + ts . sys . newLine +
1746
- "actual: '" + ts . sys . newLine + JSON . stringify ( actual , ( k , v ) => v , 2 ) + "'" ;
1741
+ "expected: '" + ts . sys . newLine + JSON . stringify ( expected , ( k , v ) => v , 2 ) + "'" + ts . sys . newLine +
1742
+ "actual: '" + ts . sys . newLine + JSON . stringify ( actual , ( k , v ) => v , 2 ) + "'" ;
1747
1743
}
1748
1744
}
1749
1745
@@ -2017,7 +2013,7 @@ module FourSlash {
2017
2013
B41A
// The current caret position (in line/col terms)
2018
2014
var line = this . getCurrentCaretFilePosition ( ) . line ;
2019
2015
// The line/col of the start of this line
2020
- var pos = this . languageServiceAdaptorHost . lineColToPosition ( this . activeFile . fileName , line , 1 ) ;
2016
+ var pos = this . languageServiceAdapterHost . lineColToPosition ( this . activeFile . fileName , line , 1 ) ;
2021
2017
// The index of the current file
2022
2018
2023
2019
// The text from the start of the line to the end of the file
@@ -2037,7 +2033,7 @@ module FourSlash {
2037
2033
}
2038
2034
2039
2035
private getCurrentCaretFilePosition ( ) {
2040
- var result = this . languageServiceAdaptorHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) ;
2036
+ var result = this . languageServiceAdapterHost . positionToZeroBasedLineCol ( this . activeFile . fileName , this . currentCaretPosition ) ;
2041
2037
if ( result . line >= 0 ) {
2042
2038
result . line ++ ;
2043
2039
}
@@ -2097,7 +2093,7 @@ module FourSlash {
2097
2093
var name = < string > indexOrName ;
2098
2094
2099
2095
// names are stored in the compiler with this relative path, this allows people to use goTo.file on just the fileName
2100
- name = name . indexOf ( '/' ) === - 1 ? ( this . basePath + '/' + name ) : name ;
2096
+ name = name . indexOf ( '/' ) === - 1 ? ( this . basePath + '/' + name ) : name ;
2101
2097
2102
2098
var availableNames : string [ ] = [ ] ;
2103
2099
var foundIt = false ;
@@ -2124,7 +2120,7 @@ module FourSlash {
2124
2120
}
2125
2121
2126
2122
private getLineColStringAtPosition ( position : number ) {
2127
- var pos = this . languageServiceAdaptorHost . positionToZeroBasedLineCol ( this . activeFile . fileName , position ) ;
2123
+ var pos = this . languageServiceAdapterHost . positionToZeroBasedLineCol ( this . activeFile . fileName , position ) ;
2128
2124
return 'line ' + ( pos . line + 1 ) + ', col ' + pos . character ;
2129
2125
}
2130
2126
@@ -2285,7 +2281,7 @@ module FourSlash {
2285
2281
currentFileName = fileName ;
2286
2282
}
2287
2283
2288
- currentFileName = basePath + '/' + match [ 2 ] ;
2284
+ currentFileName = basePath + '/' + match [ 2 ] ;
2289
2285
currentFileOptions [ match [ 1 ] ] = match [ 2 ] ;
2290
2286
} else {
2291
2287
// Add other fileMetadata flag
0 commit comments