@@ -1426,18 +1426,22 @@ Actual: ${stringify(fullActual)}`);
1426
1426
}
1427
1427
}
1428
1428
1429
- public verifyNoSignatureHelp ( markers : ReadonlyArray < string > ) {
1429
+ public verifySignatureHelpPresence ( expectPresent : boolean , triggerReason : ts . SignatureHelpTriggerReason | undefined , markers : ReadonlyArray < string > ) {
1430
1430
if ( markers . length ) {
1431
1431
for ( const marker of markers ) {
1432
1432
this . goToMarker ( marker ) ;
1433
- this . verifyNoSignatureHelp ( ts . emptyArray ) ;
1433
+ this . verifySignatureHelpPresence ( expectPresent , triggerReason , ts . emptyArray ) ;
1434
1434
}
1435
1435
return ;
1436
1436
}
1437
-
1438
- const actual = this . getSignatureHelp ( ) ;
1439
- if ( actual ) {
1440
- this . raiseError ( `Expected no signature help, but got "${ stringify ( actual ) } "` ) ;
1437
+ const actual = this . getSignatureHelp ( { triggerReason } ) ;
1438
+ if ( expectPresent !== ! ! actual ) {
1439
+ if ( actual ) {
1440
+ this . raiseError ( `Expected no signature help, but got "${ stringify ( actual ) } "` ) ;
1441
+ }
1442
+ else {
1443
+ this . raiseError ( "Expected signature help, but none was returned." ) ;
1444
+ }
1441
1445
}
1442
1446
}
1443
1447
@@ -1456,7 +1460,7 @@ Actual: ${stringify(fullActual)}`);
1456
1460
}
1457
1461
1458
1462
private verifySignatureHelpWorker ( options : FourSlashInterface . VerifySignatureHelpOptions ) {
1459
- const help = this . getSignatureHelp ( ) ! ;
1463
+ const help = this . getSignatureHelp ( { triggerReason : options . triggerReason } ) ! ;
1460
1464
const selectedItem = help . items [ help . selectedItemIndex ] ;
1461
1465
// Argument index may exceed number of parameters
1462
1466
const currentParameter = selectedItem . parameters [ help . argumentIndex ] as ts . SignatureHelpParameter | undefined ;
@@ -1498,6 +1502,7 @@ Actual: ${stringify(fullActual)}`);
1498
1502
1499
1503
const allKeys : ReadonlyArray < keyof FourSlashInterface . VerifySignatureHelpOptions > = [
1500
1504
"marker" ,
1505
+ "triggerReason" ,
1501
1506
"overloadsCount" ,
1502
1507
"docComment" ,
1503
1508
"text" ,
@@ -1724,7 +1729,7 @@ Actual: ${stringify(fullActual)}`);
1724
1729
}
1725
1730
1726
1731
public printCurrentParameterHelp ( ) {
1727
- const help = this . languageService . getSignatureHelpItems ( this . activeFile . fileName , this . currentCaretPosition ) ;
1732
+ const help = this . languageService . getSignatureHelpItems ( this . activeFile . fileName , this . currentCaretPosition , /*options*/ undefined ) ;
1728
1733
Harness . IO . log ( stringify ( help ) ) ;
1729
1734
}
1730
1735
@@ -1765,12 +1770,14 @@ Actual: ${stringify(fullActual)}`);
1765
1770
}
1766
1771
1767
1772
public printCurrentSignatureHelp ( ) {
1768
- const help = this . getSignatureHelp ( ) ! ;
1773
+ const help = this . getSignatureHelp ( ts . emptyOptions ) ! ;
1769
1774
Harness . IO . log ( stringify ( help . items [ help . selectedItemIndex ] ) ) ;
1770
1775
}
1771
1776
1772
- private getSignatureHelp ( ) : ts . SignatureHelpItems | undefined {
1773
- return this . languageService . getSignatureHelpItems ( this . activeFile . fileName , this . currentCaretPosition ) ;
1777
+ private getSignatureHelp ( { triggerReason } : FourSlashInterface . VerifySignatureHelpOptions ) : ts . SignatureHelpItems | undefined {
1778
+ return this . languageService . getSignatureHelpItems ( this . activeFile . fileName , this . currentCaretPosition , {
1779
+ triggerReason
1780
+ } ) ;
1774
1781
}
1775
1782
1776
1783
public printCompletionListMembers ( preferences : ts . UserPreferences | undefined ) {
@@ -1866,13 +1873,18 @@ Actual: ${stringify(fullActual)}`);
1866
1873
offset ++ ;
1867
1874
1868
1875
if ( highFidelity ) {
1869
- if ( ch === "(" || ch === "," ) {
1876
+ if ( ch === "(" || ch === "," || ch === "<" ) {
1870
1877
/* Signature help*/
1871
- this . languageService . getSignatureHelpItems ( this . activeFile . fileName , offset ) ;
1878
+ this . languageService . getSignatureHelpItems ( this . activeFile . fileName , offset , {
1879
+ triggerReason : {
1880
+ kind : "characterTyped" ,
1881
+ triggerCharacter : ch
1882
+ }
1883
+ } ) ;
1872
1884
}
1873
1885
else if ( prevChar === " " && / A - Z a - z _ / . test ( ch ) ) {
1874
1886
/* Completions */
1875
- this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset , ts . defaultPreferences ) ;
1887
+ this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , offset , ts . emptyOptions ) ;
1876
1888
}
1877
1889
1878
1890
if ( i % checkCadence === 0 ) {
@@ -2505,7 +2517,7 @@ Actual: ${stringify(fullActual)}`);
2505
2517
`Expected '${ fixId } '. Available action ids: ${ ts . mapDefined ( this . getCodeFixes ( this . activeFile . fileName ) , a => a . fixId ) } ` ) ;
2506
2518
ts . Debug . assertEqual ( fixWithId ! . fixAllDescription , fixAllDescription ) ;
2507
2519
2508
- const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings , ts . defaultPreferences ) ;
2520
+ const { changes, commands } = this . languageService . getCombinedCodeFix ( { type : "file" , fileName : this . activeFile . fileName } , fixId , this . formatCodeSettings , ts . emptyOptions ) ;
2509
2521
assert . deepEqual < ReadonlyArray < { } > | undefined > ( commands , expectedCommands ) ;
2510
2522
assert ( changes . every ( c => c . fileName === this . activeFile . fileName ) , "TODO: support testing codefixes that touch multiple files" ) ;
2511
2523
this . applyChanges ( changes ) ;
@@ -2585,7 +2597,7 @@ Actual: ${stringify(fullActual)}`);
2585
2597
* Rerieves a codefix satisfying the parameters, or undefined if no such codefix is found.
2586
2598
* @param fileName Path to file where error should be retrieved from.
2587
2599
*/
2588
- private getCodeFixes ( fileName : string , errorCode ?: number , preferences : ts . UserPreferences = ts . defaultPreferences ) : ts . CodeFixAction [ ] {
2600
+ private getCodeFixes ( fileName : string , errorCode ?: number , preferences : ts . UserPreferences = ts . emptyOptions ) : ts . CodeFixAction [ ] {
2589
2601
const diagnosticsForCodeFix = this . getDiagnostics ( fileName , /*includeSuggestions*/ true ) . map ( diagnostic => ( {
2590
2602
start : diagnostic . start ,
2591
2603
length : diagnostic . length ,
@@ -3030,7 +3042,7 @@ Actual: ${stringify(fullActual)}`);
3030
3042
this . raiseError ( `Expected action description to be ${ JSON . stringify ( actionDescription ) } , got: ${ JSON . stringify ( action . description ) } ` ) ;
3031
3043
}
3032
3044
3033
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName , ts . defaultPreferences ) ! ;
3045
+ const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactorName , actionName , ts . emptyOptions ) ! ;
3034
3046
for ( const edit of editInfo . edits ) {
3035
3047
this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
3036
3048
}
@@ -3094,7 +3106,7 @@ Actual: ${stringify(fullActual)}`);
3094
3106
const action = ts . first ( refactor . actions ) ;
3095
3107
assert ( action . name === "Move to a new file" && action . description === "Move to a new file" ) ;
3096
3108
3097
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactor . name , action . name , options . preferences || ts . defaultPreferences ) ! ;
3109
+ const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , this . formatCodeSettings , range , refactor . name , action . name , options . preferences || ts . emptyOptions ) ! ;
3098
3110
this . testNewFileContents ( editInfo . edits , options . newFileContents , "move to new file" ) ;
3099
3111
}
3100
3112
@@ -3136,14 +3148,14 @@ Actual: ${stringify(fullActual)}`);
3136
3148
formattingOptions = formattingOptions || this . formatCodeSettings ;
3137
3149
const markerPos = this . getMarkerByName ( markerName ) . position ;
3138
3150
3139
- const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , markerPos , ts . defaultPreferences ) ;
3151
+ const applicableRefactors = this . languageService . getApplicableRefactors ( this . activeFile . fileName , markerPos , ts . emptyOptions ) ;
3140
3152
const applicableRefactorToApply = ts . find ( applicableRefactors , refactor => refactor . name === refactorNameToApply ) ;
3141
3153
3142
3154
if ( ! applicableRefactorToApply ) {
3143
3155
this . raiseError ( `The expected refactor: ${ refactorNameToApply } is not available at the marker location.` ) ;
3144
3156
}
3145
3157
3146
- const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply , actionName , ts . defaultPreferences ) ! ;
3158
+ const editInfo = this . languageService . getEditsForRefactor ( this . activeFile . fileName , formattingOptions , markerPos , refactorNameToApply , actionName , ts . emptyOptions ) ! ;
3147
3159
3148
3160
for ( const edit of editInfo . edits ) {
3149
3161
this . applyEdits ( edit . fileName , edit . textChanges , /*isFormattingEdit*/ false ) ;
@@ -3340,7 +3352,7 @@ Actual: ${stringify(fullActual)}`);
3340
3352
3341
3353
public getEditsForFileRename ( { oldPath, newPath, newFileContents } : FourSlashInterface . GetEditsForFileRenameOptions ) : void {
3342
3354
const test = ( fileContents : { readonly [ fileName : string ] : string } , description : string ) : void => {
3343
- const changes = this . languageService . getEditsForFileRename ( oldPath , newPath , this . formatCodeSettings , ts . defaultPreferences ) ;
3355
+ const changes = this . languageService . getEditsForFileRename ( oldPath , newPath , this . formatCodeSettings , ts . emptyOptions ) ;
3344
3356
this . testNewFileContents ( changes , fileContents , description ) ;
3345
3357
} ;
3346
3358
@@ -3354,7 +3366,7 @@ Actual: ${stringify(fullActual)}`);
3354
3366
test ( renameKeys ( newFileContents , key => pathUpdater ( key ) || key ) , "with file moved" ) ;
3355
3367
}
3356
3368
3357
- private getApplicableRefactors ( positionOrRange : number | ts . TextRange , preferences = ts . defaultPreferences ) : ReadonlyArray < ts . ApplicableRefactorInfo > {
3369
+ private getApplicableRefactors ( positionOrRange : number | ts . TextRange , preferences = ts . emptyOptions ) : ReadonlyArray < ts . ApplicableRefactorInfo > {
3358
3370
return this . languageService . getApplicableRefactors ( this . activeFile . fileName , positionOrRange , preferences ) || ts . emptyArray ;
3359
3371
}
3360
3372
}
@@ -4042,7 +4054,15 @@ namespace FourSlashInterface {
4042
4054
}
4043
4055
4044
4056
public noSignatureHelp ( ...markers : string [ ] ) : void {
4045
- this . state . verifyNoSignatureHelp ( markers ) ;
4057
+ this . state . verifySignatureHelpPresence ( /*expectPresent*/ false , /*triggerReason*/ undefined , markers ) ;
4058
+ }
4059
+
4060
+ public noSignatureHelpForTriggerReason ( reason : ts . SignatureHelpTriggerReason , ...markers : string [ ] ) : void {
4061
+ this . state . verifySignatureHelpPresence ( /*expectPresent*/ false , reason , markers ) ;
4062
+ }
4063
+
4064
+ public signatureHelpPresentForTriggerReason ( reason : ts . SignatureHelpTriggerReason , ...markers : string [ ] ) : void {
4065
+ this . state . verifySignatureHelpPresence ( /*expectPresent*/ true , reason , markers ) ;
4046
4066
}
4047
4067
4048
4068
public signatureHelp ( ...options : VerifySignatureHelpOptions [ ] ) : void {
@@ -4757,6 +4777,7 @@ namespace FourSlashInterface {
4757
4777
readonly isVariadic ?: boolean ;
4758
4778
/** @default ts.emptyArray */
4759
4779
readonly tags ?: ReadonlyArray < ts . JSDocTagInfo > ;
4780
+ readonly triggerReason ?: ts . SignatureHelpTriggerReason ;
4760
4781
}
4761
4782
4762
4783
export interface VerifyNavigateToOptions {
0 commit comments