@@ -783,13 +783,13 @@ namespace FourSlash {
783
783
} ) ;
784
784
}
785
785
786
- public verifyCompletionListContains ( symbol : string , text ?: string , documentation ?: string , kind ?: string , spanIndex ?: number , hasAction ?: boolean ) {
786
+ public verifyCompletionListContains ( entryId : ts . Completions . CompletionEntryIdentifier , text ?: string , documentation ?: string , kind ?: string , spanIndex ?: number , hasAction ?: boolean ) {
787
787
const completions = this . getCompletionListAtCaret ( ) ;
788
788
if ( completions ) {
789
- this . assertItemInCompletionList ( completions . entries , symbol , text , documentation , kind , spanIndex , hasAction ) ;
789
+ this . assertItemInCompletionList ( completions . entries , entryId , text , documentation , kind , spanIndex , hasAction ) ;
790
790
}
791
791
else {
792
- this . raiseError ( `No completions at position '${ this . currentCaretPosition } ' when looking for '${ symbol } '.` ) ;
792
+ this . raiseError ( `No completions at position '${ this . currentCaretPosition } ' when looking for '${ JSON . stringify ( entryId ) } '.` ) ;
793
793
}
794
794
}
795
795
@@ -804,7 +804,7 @@ namespace FourSlash {
804
804
* @param expectedKind the kind of symbol (see ScriptElementKind)
805
805
* @param spanIndex the index of the range that the completion item's replacement text span should match
806
806
*/
807
- public verifyCompletionListDoesNotContain ( symbol : string , expectedText ?: string , expectedDocumentation ?: string , expectedKind ?: string , spanIndex ?: number ) {
807
+ public verifyCompletionListDoesNotContain ( entryId : ts . Completions . CompletionEntryIdentifier , expectedText ?: string , expectedDocumentation ?: string , expectedKind ?: string , spanIndex ?: number ) {
808
808
const that = this ;
809
809
let replacementSpan : ts . TextSpan ;
810
810
if ( spanIndex !== undefined ) {
@@ -833,14 +833,14 @@ namespace FourSlash {
833
833
834
834
const completions = this . getCompletionListAtCaret ( ) ;
835
835
if ( completions ) {
836
- let filterCompletions = completions . entries . filter ( e => e . name === symbol ) ;
836
+ let filterCompletions = completions . entries . filter ( e => e . name === entryId . name && e . source === entryId . source ) ;
837
837
filterCompletions = expectedKind ? filterCompletions . filter ( e => e . kind === expectedKind ) : filterCompletions ;
838
838
filterCompletions = filterCompletions . filter ( filterByTextOrDocumentation ) ;
839
839
if ( filterCompletions . length !== 0 ) {
840
840
// After filtered using all present criterion, if there are still symbol left in the list
841
841
// then these symbols must meet the criterion for Not supposed to be in the list. So we
842
842
// raise an error
843
- let error = " Completion list did contain \'" + symbol + " \'." ;
843
+ let error = ` Completion list did contain ' ${ JSON . stringify ( entryId ) } \'.` ;
844
844
const details = this . getCompletionEntryDetails ( filterCompletions [ 0 ] . name ) ;
845
845
if ( expectedText ) {
846
846
error += "Expected text: " + expectedText + " to equal: " + ts . displayPartsToString ( details . displayParts ) + "." ;
@@ -1130,8 +1130,8 @@ Actual: ${stringify(fullActual)}`);
1130
1130
return this . languageService . getCompletionsAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1131
1131
}
1132
1132
1133
- private getCompletionEntryDetails ( entryName : string ) {
1134
- return this . languageService . getCompletionEntryDetails ( this . activeFile . fileName , this . currentCaretPosition , entryName , this . formatCodeSettings ) ;
1133
+ private getCompletionEntryDetails ( entryName : string , source ?: string ) {
1134
+ return this . languageService . getCompletionEntryDetails ( this . activeFile . fileName , this . currentCaretPosition , entryName , this . formatCodeSettings , source ) ;
1135
1135
}
1136
1136
1137
1137
private getReferencesAtCaret ( ) {
@@ -1640,7 +1640,7 @@ Actual: ${stringify(fullActual)}`);
1640
1640
const longestNameLength = max ( entries , m => m . name . length ) ;
1641
1641
const longestKindLength = max ( entries , m => m . kind . length ) ;
1642
1642
entries . sort ( ( m , n ) => m . sortText > n . sortText ? 1 : m . sortText < n . sortText ? - 1 : m . name > n . name ? 1 : m . name < n . name ? - 1 : 0 ) ;
1643
- const membersString = entries . map ( m => `${ pad ( m . name , longestNameLength ) } ${ pad ( m . kind , longestKindLength ) } ${ m . kindModifiers } ` ) . join ( "\n" ) ;
1643
+ const membersString = entries . map ( m => `${ pad ( m . name , longestNameLength ) } ${ pad ( m . kind , longestKindLength ) } ${ m . kindModifiers } ${ m . source === undefined ? "" : m . source } ` ) . join ( "\n" ) ;
1644
1644
Harness . IO . log ( membersString ) ;
1645
1645
}
1646
1646
@@ -2296,13 +2296,13 @@ Actual: ${stringify(fullActual)}`);
2296
2296
public applyCodeActionFromCompletion ( markerName : string , options : FourSlashInterface . VerifyCompletionActionOptions ) {
2297
2297
this . goToMarker ( markerName ) ;
2298
2298
2299
- const actualCompletion = this . getCompletionListAtCaret ( ) . entries . find ( e => e . name === options . name ) ;
2299
+ const actualCompletion = this . getCompletionListAtCaret ( ) . entries . find ( e => e . name === options . name && e . source === options . source ) ;
2300
2300
2301
2301
if ( ! actualCompletion . hasAction ) {
2302
2302
this . raiseError ( `Completion for ${ options . name } does not have an associated action.` ) ;
2303
2303
}
2304
2304
2305
- const details = this . getCompletionEntryDetails ( options . name ) ;
2305
+ const details = this . getCompletionEntryDetails ( options . name , actualCompletion . source ) ;
2306
2306
if ( details . codeActions . length !== 1 ) {
2307
2307
this . raiseError ( `Expected one code action, got ${ details . codeActions . length } ` ) ;
2308
2308
}
@@ -2984,33 +2984,35 @@ Actual: ${stringify(fullActual)}`);
2984
2984
2985
2985
private assertItemInCompletionList (
2986
2986
items : ts . CompletionEntry [ ] ,
2987
- name : string ,
2987
+ entryId : ts . Completions . CompletionEntryIdentifier ,
2988
2988
text : string | undefined ,
2989
2989
documentation : string | undefined ,
2990
2990
kind : string | undefined ,
2991
2991
spanIndex : number | undefined ,
2992
2992
hasAction : boolean | undefined ,
2993
2993
) {
2994
2994
for ( const item of items ) {
2995
- if ( item . name === name ) {
2996
- if ( documentation !== undefined || text !== undefined ) {
2997
- const details = this . getCompletionEntryDetails ( item . name ) ;
2995
+ if ( item . name === entryId . name && item . source === entryId . source ) {
2996
+ if ( documentation !== undefined || text !== undefined || entryId . source !== undefined ) {
2997
+ const details = this . getCompletionEntryDetails ( item . name , item . source ) ;
2998
2998
2999
2999
if ( documentation !== undefined ) {
3000
- assert . equal ( ts . displayPartsToString ( details . documentation ) , documentation , this . assertionMessageAtLastKnownMarker ( "completion item documentation for " + name ) ) ;
3000
+ assert . equal ( ts . displayPartsToString ( details . documentation ) , documentation , this . assertionMessageAtLastKnownMarker ( "completion item documentation for " + entryId ) ) ;
3001
3001
}
3002
3002
if ( text !== undefined ) {
3003
- assert . equal ( ts . displayPartsToString ( details . displayParts ) , text , this . assertionMessageAtLastKnownMarker ( "completion item detail text for " + name ) ) ;
3003
+ assert . equal ( ts . displayPartsToString ( details . displayParts ) , text , this . assertionMessageAtLastKnownMarker ( "completion item detail text for " + entryId ) ) ;
3004
3004
}
3005
+
3006
+ assert . deepEqual ( details . source , entryId . source === undefined ? undefined : [ ts . textPart ( entryId . source ) ] ) ;
3005
3007
}
3006
3008
3007
3009
if ( kind !== undefined ) {
3008
- assert . equal ( item . kind , kind , this . assertionMessageAtLastKnownMarker ( "completion item kind for " + name ) ) ;
3010
+ assert . equal ( item . kind , kind , this . assertionMessageAtLastKnownMarker ( "completion item kind for " + entryId ) ) ;
3009
3011
}
3010
3012
3011
3013
if ( spanIndex !== undefined ) {
3012
3014
const span = this . getTextSpanForRangeAtIndex ( spanIndex ) ;
3013
- assert . isTrue ( TestState . textSpansEqual ( span , item . replacementSpan ) , this . assertionMessageAtLastKnownMarker ( stringify ( span ) + " does not equal " + stringify ( item . replacementSpan ) + " replacement span for " + name ) ) ;
3015
+ assert . isTrue ( TestState . textSpansEqual ( span , item . replacementSpan ) , this . assertionMessageAtLastKnownMarker ( stringify ( span ) + " does not equal " + stringify ( item . replacementSpan ) + " replacement span for " + entryId ) ) ;
3014
3016
}
3015
3017
3016
3018
assert . equal ( item . hasAction , hasAction ) ;
@@ -3021,7 +3023,7 @@ Actual: ${stringify(fullActual)}`);
3021
3023
3022
3024
const itemsString = items . map ( item => stringify ( { name : item . name , kind : item . kind } ) ) . join ( ",\n" ) ;
3023
3025
3024
- this . raiseError ( `Expected "${ stringify ( { name , text, documentation, kind } ) } " to be in list [${ itemsString } ]` ) ;
3026
+ this . raiseError ( `Expected "${ stringify ( { entryId , text, documentation, kind } ) } " to be in list [${ itemsString } ]` ) ;
3025
3027
}
3026
3028
3027
3029
private findFile ( indexOrName : any ) {
@@ -3732,12 +3734,15 @@ namespace FourSlashInterface {
3732
3734
3733
3735
// Verifies the completion list contains the specified symbol. The
3734
3736
// completion list is brought up if necessary
3735
- public completionListContains ( symbol : string , text ?: string , documentation ?: string , kind ?: string , spanIndex ?: number , hasAction ?: boolean ) {
3737
+ public completionListContains ( entryId : string | ts . Completions . CompletionEntryIdentifier , text ?: string , documentation ?: string , kind ?: string , spanIndex ?: number , hasAction ?: boolean ) {
3738
+ if ( typeof entryId === "string" ) {
3739
+ entryId = { name : entryId , source : undefined } ;
3740
+ }
3736
3741
if ( this . negative ) {
3737
- this . state . verifyCompletionListDoesNotContain ( symbol , text , documentation , kind , spanIndex ) ;
3742
+ this . state . verifyCompletionListDoesNotContain ( entryId , text , documentation , kind , spanIndex ) ;
3738
3743
}
3739
3744
else {
3740
- this . state . verifyCompletionListContains ( symbol , text , documentation , kind , spanIndex , hasAction ) ;
3745
+ this . state . verifyCompletionListContains ( entryId , text , documentation , kind , spanIndex , hasAction ) ;
3741
3746
}
3742
3747
}
3743
3748
@@ -4492,6 +4497,7 @@ namespace FourSlashInterface {
4492
4497
4493
4498
export interface VerifyCompletionActionOptions extends NewContentOptions {
4494
4499
name : string ;
4500
+ source ?: string ;
4495
4501
description : string ;
4496
4502
}
4497
4503
}
0 commit comments