@@ -365,7 +365,6 @@ namespace FourSlash {
365
365
366
366
function memoWrap ( ls : ts . LanguageService , target : TestState ) : ts . LanguageService {
367
367
const cacheableMembers : ( keyof typeof ls ) [ ] = [
368
- "getCompletionsAtPosition" ,
369
368
"getCompletionEntryDetails" ,
370
369
"getCompletionEntrySymbol" ,
371
370
"getQuickInfoAtPosition" ,
@@ -1228,8 +1227,8 @@ Actual: ${stringify(fullActual)}`);
1228
1227
return this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , this . currentCaretPosition , options ) ;
1229
1228
}
1230
1229
1231
- private getCompletionEntryDetails ( entryName : string , source ?: string ) : ts . CompletionEntryDetails {
1232
- return this . languageService . getCompletionEntryDetails ( this . activeFile . fileName , this . currentCaretPosition , entryName , this . formatCodeSettings , source ) ;
1230
+ private getCompletionEntryDetails ( entryName : string , source ?: string , preferences ?: ts . UserPreferences ) : ts . CompletionEntryDetails {
1231
+ return this . languageService . getCompletionEntryDetails ( this . activeFile . fileName , this . currentCaretPosition , entryName , this . formatCodeSettings , source , preferences ) ;
1233
1232
}
1234
1233
1235
1234
private getReferencesAtCaret ( ) {
@@ -1728,8 +1727,8 @@ Actual: ${stringify(fullActual)}`);
1728
1727
Harness . IO . log ( stringify ( sigHelp ) ) ;
1729
1728
}
1730
1729
1731
- public printCompletionListMembers ( options : ts . GetCompletionsAtPositionOptions | undefined ) {
1732
- const completions = this . getCompletionListAtCaret ( options ) ;
1730
+ public printCompletionListMembers ( preferences : ts . UserPreferences | undefined ) {
1731
+ const completions = this . getCompletionListAtCaret ( preferences ) ;
1733
1732
this . printMembersOrCompletions ( completions ) ;
1734
1733
}
1735
1734
@@ -1827,7 +1826,7 @@ Actual: ${stringify(fullActual)}`);
1827
1826
}
1828
1827
else if ( prevChar === " " && / A - Z a - z _ / . test ( ch ) ) {
1829
1828
/* Completions */
1830
- this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset , { includeExternalModuleExports : false , includeInsertTextCompletions : false } ) ;
1829
+ this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset , ts . defaultPreferences ) ;
1831
1830
}
1832
1831
1833
1832
if ( i % checkCadence === 0 ) {
@@ -2402,14 +2401,14 @@ Actual: ${stringify(fullActual)}`);
2402
2401
public applyCodeActionFromCompletion ( markerName : string , options : FourSlashInterface . VerifyCompletionActionOptions ) {
2403
2402
this . goToMarker ( markerName ) ;
2404
2403
2405
- const actualCompletion = this . getCompletionListAtCaret ( { includeExternalModuleExports : true , includeInsertTextCompletions : false } ) . entries . find ( e =>
2404
+ const actualCompletion = this . getCompletionListAtCaret ( { ... ts . defaultPreferences , includeCompletionsForModuleExports : true } ) . entries . find ( e =>
2406
2405
e . name === options . name && e . source === options . source ) ;
2407
2406
2408
2407
if ( ! actualCompletion . hasAction ) {
2409
2408
this . raiseError ( `Completion for ${ options . name } does not have an associated action.` ) ;
2410
2409
}
2411
2410
2412
- const details = this . getCompletionEntryDetails ( options . name , actualCompletion . source ) ;
2411
+ const details = this . getCompletionEntryDetails ( options . name , actualCompletion . source , options . preferences ) ;
2413
2412
if ( details . codeActions . length !== 1 ) {
2414
2413
this . raiseError ( `Expected one code action, got ${ details . codeActions . length } ` ) ;
2415
2414
}
@@ -2454,7 +2453,7 @@ Actual: ${stringify(fullActual)}`);
2454
2453
const { fixId, newFileContent } = options ;
2455
2454
const fixIds = ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . fixId ) ;
2456
2455
ts . Debug . assert ( ts . contains ( fixIds , fixId ) , "No available code fix has that group id." , ( ) => `Expected '${ fixId } '. Available action ids: ${ fixIds } ` ) ;
2457
- const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings ) ;
2456
+ const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings , ts . defaultPreferences ) ;
2458
2457
assert . deepEqual ( commands , options . commands ) ;
2459
2458
assert ( changes . every ( c => c . fileName === this . activeFile . fileName ) , "TODO: support testing codefixes that touch multiple files" ) ;
2460
2459
this . applyChanges ( changes ) ;
@@ -2483,7 +2482,7 @@ Actual: ${stringify(fullActual)}`);
2483
2482
2484
2483
public verifyCodeFix ( options : FourSlashInterface . VerifyCodeFixOptions ) {
2485
2484
const fileName = this . activeFile . fileName ;
2486
- const actions = this . getCodeFixes ( fileName , options . errorCode ) ;
2485
+ const actions = this . getCodeFixes ( fileName , options . errorCode , options . preferences ) ;
2487
2486
let index = options . index ;
2488
2487
if ( index === undefined ) {
2489
2488
if ( ! ( actions && actions . length === 1 ) ) {
@@ -2522,7 +2521,7 @@ Actual: ${stringify(fullActual)}`);
2522
2521
* Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
2523
2522
* @param fileName Path to file where error should be retrieved from.
2524
2523
*/
2525
- private getCodeFixes ( fileName : string , errorCode ?: number ) : ts . CodeFixAction [ ] {
2524
+ private getCodeFixes ( fileName : string , errorCode ?: number , preferences : ts . UserPreferences = ts . defaultPreferences ) : ts . CodeFixAction [ ] {
2526
2525
const diagnosticsForCodeFix = this . getDiagnostics ( fileName , /*includeSuggestions*/ true ) . map ( diagnostic => ( {
2527
2526
start : diagnostic . start ,
2528
2527
length : diagnostic . length ,
@@ -2534,7 +2533,7 @@ Actual: ${stringify(fullActual)}`);
2534
2533
return ;
2535
2534
}
2536
2535
2537
- return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . start + diagnostic . length , [ diagnostic . code ] , this . formatCodeSettings ) ;
2536
+ return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . start + diagnostic . length , [ diagnostic . code ] , this . formatCodeSettings , preferences ) ;
2538
2537
} ) ;
2539
2538
}
2540
2539
@@ -2560,15 +2559,15 @@ Actual: ${stringify(fullActual)}`);
2560
2559
}
2561
2560
}
2562
2561
2563
- public verifyImportFixAtPosition ( expectedTextArray : string [ ] , errorCode ? : number ) {
2562
+ public verifyImportFixAtPosition ( expectedTextArray : string [ ] , errorCode : number | undefined , preferences : ts . UserPreferences | undefined ) {
2564
2563
const { fileName } = this . activeFile ;
2565
2564
const ranges = this . getRanges ( ) . filter ( r => r . fileName === fileName ) ;
2566
2565
if ( ranges . length !== 1 ) {
2567
2566
this . raiseError ( "Exactly one range should be specified in the testfile." ) ;
2568
2567
}
2569
2568
const range = ts . first ( ranges ) ;
2570
2569
2571
- const codeFixes = this . getCodeFixes ( fileName , errorCode ) ;
2570
+ const codeFixes = this . getCodeFixes ( fileName , errorCode , preferences ) ;
2572
2571
2573
2572
if ( codeFixes . length === 0 ) {
2574
2573
if ( expectedTextArray . length !== 0 ) {
@@ -2938,7 +2937,7 @@ Actual: ${stringify(fullActual)}`);
2938
2937
2939
2938
public verifyApplicableRefactorAvailableAtMarker ( negative : boolean , markerName : string ) {
2940
2939
const marker = this . getMarkerByName ( markerName ) ;
2941
- const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , marker . position ) ;
2940
+ const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , marker . position , ts . defaultPreferences ) ;
2942
2941
const isAvailable = applicableRefactors && applicableRefactors . length > 0 ;
2943
2942
if ( negative && isAvailable ) {
2944
2943
this . raiseError ( `verifyApplicableRefactorAvailableAtMarker failed - expected no refactor at marker ${ markerName } but found some.` ) ;
@@ -2958,7 +2957,7 @@ Actual: ${stringify(fullActual)}`);
2958
2957
public verifyRefactorAvailable ( negative : boolean , name : string , actionName ?: string ) {
2959
2958
const selection = this . getSelection ( ) ;
2960
2959
2961
- let refactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , selection ) || [ ] ;
2960
+ let refactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , selection , ts . defaultPreferences ) || [ ] ;
2962
2961
refactors = refactors . filter ( r => r . name === name && ( actionName === undefined || r . actions . some ( a => a . name === actionName ) ) ) ;
2963
2962
const isAvailable = refactors . length > 0 ;
2964
2963
@@ -2980,7 +2979,7 @@ Actual: ${stringify(fullActual)}`);
2980
2979
public verifyRefactor ( { name, actionName, refactors } : FourSlashInterface . VerifyRefactorOptions ) {
2981
2980
const selection = this . getSelection ( ) ;
2982
2981
2983
- const actualRefactors = ( this . languageService . getApplicableRefactors ( this . activeFile . fileName , selection ) || ts . emptyArray )
2982
+ const actualRefactors = ( this . languageService . getApplicableRefactors ( this . activeFile . fileName , selection , ts . defaultPreferences ) || ts . emptyArray )
2984
2983
. filter ( r => r . name === name && r . actions . some ( a => a . name === actionName ) ) ;
2985
2984
this . assertObjectsEqual ( actualRefactors , refactors ) ;
2986
2985
}
@@ -2991,7 +2990,7 @@ Actual: ${stringify(fullActual)}`);
2991
2990
throw new Error ( "Exactly one refactor range is allowed per test." ) ;
2992
2991
}
2993
2992
2994
- const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , { pos : ranges [ 0 ] . pos , end : ranges [ 0 ] . end } ) ;
2993
+ const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , ts . first ( ranges ) , ts . defaultPreferences ) ;
2995
2994
const isAvailable = applicableRefactors && applicableRefactors . length > 0 ;
2996
2995
if ( negative && isAvailable ) {
2997
2996
this . raiseError ( `verifyApplicableRefactorAvailableForRange failed - expected no refactor but found some.` ) ;
@@ -3003,7 +3002,7 @@ Actual: ${stringify(fullActual)}`);
3003
3002
3004
3003
public applyRefactor ( { refactorName, actionName, actionDescription, newContent : newContentWithRenameMarker } : FourSlashInterface . ApplyRefactorOptions ) {
3005
3004
const range = this . getSelection ( ) ;
3006
- const refactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , range ) ;
3005
+ const refactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , range , ts . defaultPreferences ) ;
3007
3006
const refactorsWithName = refactors . filter ( r => r . name === refactorName ) ;
3008
3007
if ( refactorsWithName . length === 0 ) {
3009
3008
this . raiseError ( `The expected refactor: ${ refactorName } is not available at the marker location.\nAvailable refactors: ${ refactors . map ( r => r . name ) } ` ) ;
@@ -3017,7 +3016,7 @@ Actual: ${stringify(fullActual)}`);
3017
3016
this . raiseError ( `Expected action description to be ${ JSON . stringify ( actionDescription ) } , got: ${ JSON . stringify ( action . description ) } ` ) ;
3018
3017
}
3019
3018
3020
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName ) ;
3019
+ const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName , ts . defaultPreferences ) ;
3021
3020
for ( const edit of editInfo . edits ) {
3022
3021
this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
3023
3022
}
@@ -3062,14 +3061,14 @@ Actual: ${stringify(fullActual)}`);
3062
3061
formattingOptions = formattingOptions || this . formatCodeSettings ;
3063
3062
const markerPos = this . getMarkerByName ( markerName ) . position ;
3064
3063
3065
- const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , markerPos ) ;
3064
+ const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , markerPos , ts . defaultPreferences ) ;
3066
3065
const applicableRefactorToApply = ts . find ( applicableRefactors , refactor => refactor . name === refactorNameToApply ) ;
3067
3066
3068
3067
if ( ! applicableRefactorToApply ) {
3069
3068
this . raiseError ( `The expected refactor: ${ refactorNameToApply } is not available at the marker location.` ) ;
3070
3069
}
3071
3070
3072
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply , actionName ) ;
3071
+ const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply , actionName , ts . defaultPreferences ) ;
3073
3072
3074
3073
for ( const edit of editInfo . edits ) {
3075
3074
this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
@@ -4217,8 +4216,8 @@ namespace FourSlashInterface {
4217
4216
this . state . applyCodeActionFromCompletion ( markerName , options ) ;
4218
4217
}
4219
4218
4220
- public importFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
4221
- this . state . verifyImportFixAtPosition ( expectedTextArray , errorCode ) ;
4219
+ public importFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number , preferences ?: ts . UserPreferences ) : void {
4220
+ this . state . verifyImportFixAtPosition ( expectedTextArray , errorCode , preferences ) ;
4222
4221
}
4223
4222
4224
4223
public navigationBar ( json : any , options ?: { checkSpans ?: boolean } ) {
@@ -4424,7 +4423,7 @@ namespace FourSlashInterface {
4424
4423
this . state . printCurrentSignatureHelp ( ) ;
4425
4424
}
4426
4425
4427
- public printCompletionListMembers ( options : ts . GetCompletionsAtPositionOptions | undefined ) {
4426
+ public printCompletionListMembers ( options : ts . UserPreferences | undefined ) {
4428
4427
this . state . printCompletionListMembers ( options ) ;
4429
4428
}
4430
4429
@@ -4621,11 +4620,11 @@ namespace FourSlashInterface {
4621
4620
}
4622
4621
4623
4622
export type ExpectedCompletionEntry = string | { name : string , insertText ?: string , replacementSpan ?: FourSlash . Range } ;
4624
- export interface CompletionsAtOptions extends ts . GetCompletionsAtPositionOptions {
4623
+ export interface CompletionsAtOptions extends Partial < ts . UserPreferences > {
4625
4624
isNewIdentifierLocation ?: boolean ;
4626
4625
}
4627
4626
4628
- export interface VerifyCompletionListContainsOptions extends ts . GetCompletionsAtPositionOptions {
4627
+ export interface VerifyCompletionListContainsOptions extends ts . UserPreferences {
4629
4628
sourceDisplay : string ;
4630
4629
isRecommended ?: true ;
4631
4630
insertText ?: string ;
@@ -4646,6 +4645,7 @@ namespace FourSlashInterface {
4646
4645
description : string ;
4647
4646
errorCode ?: number ;
4648
4647
index ?: number ;
4648
+ preferences ?: ts . UserPreferences ;
4649
4649
}
4650
4650
4651
4651
export interface VerifyCodeFixAvailableOptions {
@@ -4669,6 +4669,7 @@ namespace FourSlashInterface {
4669
4669
name : string ;
4670
4670
source ?: string ;
4671
4671
description : string ;
4672
+ preferences ?: ts . UserPreferences ;
4672
4673
}
4673
4674
4674
4675
export interface Diagnostic {
0 commit comments