@@ -1405,29 +1405,30 @@ module ts {
14051405 }
14061406 }
14071407
1408- export function typeToDisplayParts ( typechecker : TypeChecker , type : Type , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : SymbolDisplayPart [ ] {
1408+ function mapToDisplayParts ( writeDisplayParts : ( writer : DisplayPartsSymbolWriter ) => void ) : SymbolDisplayPart [ ] {
14091409 var displayPartWriter = getDisplayPartWriter ( ) ;
1410- typechecker . writeType ( type , displayPartWriter , enclosingDeclaration , flags ) ;
1410+ writeDisplayParts ( displayPartWriter ) ;
14111411 var result = displayPartWriter . displayParts ( ) ;
14121412 releaseDisplayPartWriter ( displayPartWriter ) ;
14131413 return result ;
14141414 }
14151415
1416- export function symbolToDisplayParts ( typeChecker : TypeChecker , symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) : SymbolDisplayPart [ ] {
1417- var displayPartWriter = getDisplayPartWriter ( ) ;
1418- typeChecker . writeSymbol ( symbol , displayPartWriter , enclosingDeclaration , meaning ) ;
1419- var result = displayPartWriter . displayParts ( ) ;
1420- releaseDisplayPartWriter ( displayPartWriter ) ;
1416+ export function typeToDisplayParts ( typechecker : TypeChecker , type : Type , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : SymbolDisplayPart [ ] {
1417+ return mapToDisplayParts ( writer => {
1418+ typechecker . writeType ( type , writer , enclosingDeclaration , flags ) ;
1419+ } ) ;
1420+ }
14211421
1422- return result ;
1422+ export function symbolToDisplayParts ( typeChecker : TypeChecker , symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags , flags ?: SymbolFormatFlags ) : SymbolDisplayPart [ ] {
1423+ return mapToDisplayParts ( writer => {
1424+ typeChecker . writeSymbol ( symbol , writer , enclosingDeclaration , meaning , flags ) ;
1425+ } ) ;
14231426 }
14241427
1425- function signatureToDisplayParts ( typechecker : TypeChecker , signature : Signature , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : SymbolDisplayPart [ ] {
1426- var displayPartWriter = getDisplayPartWriter ( ) ;
1427- typechecker . writeSignature ( signature , displayPartWriter , enclosingDeclaration , flags ) ;
1428- var result = displayPartWriter . displayParts ( ) ;
1429- releaseDisplayPartWriter ( displayPartWriter ) ;
1430- return result ;
1428+ function signatureToDisplayParts ( typechecker : TypeChecker , signature : Signature , enclosingDeclaration ?: Node , flags ?: TypeFormatFlags ) : SymbolDisplayPart [ ] {
1429+ return mapToDisplayParts ( writer => {
1430+ typechecker . writeSignature ( signature , writer , enclosingDeclaration , flags ) ;
1431+ } ) ;
14311432 }
14321433
14331434 export function getDefaultCompilerOptions ( ) : CompilerOptions {
@@ -2792,13 +2793,13 @@ module ts {
27922793 if ( symbolFlags & SymbolFlags . Class && ! hasAddedSymbolInfo ) {
27932794 displayParts . push ( keywordPart ( SyntaxKind . ClassKeyword ) ) ;
27942795 displayParts . push ( spacePart ( ) ) ;
2795- displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile ) ) ;
2796+ displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOfClassOrInterface ) ) ;
27962797 }
27972798 if ( symbolFlags & SymbolFlags . Interface ) {
27982799 addNewLineIfDisplayPartsExist ( ) ;
27992800 displayParts . push ( keywordPart ( SyntaxKind . InterfaceKeyword ) ) ;
28002801 displayParts . push ( spacePart ( ) ) ;
2801- displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile ) ) ;
2802+ displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOfClassOrInterface ) ) ;
28022803 }
28032804 if ( symbolFlags & SymbolFlags . Enum ) {
28042805 addNewLineIfDisplayPartsExist ( ) ;
@@ -2819,6 +2820,25 @@ module ts {
28192820 displayParts . push ( punctuationPart ( SyntaxKind . CloseParenToken ) ) ;
28202821 displayParts . push ( spacePart ( ) ) ;
28212822 displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , enclosingDeclaration ) ) ;
2823+ displayParts . push ( spacePart ( ) ) ;
2824+ displayParts . push ( keywordPart ( SyntaxKind . InKeyword ) ) ;
2825+ displayParts . push ( spacePart ( ) ) ;
2826+ if ( symbol . parent ) {
2827+ // Class/Interface type parameter
2828+ displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol . parent , enclosingDeclaration , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOfClassOrInterface ) )
2829+ }
2830+ else {
2831+ // Method/function type parameter
2832+ var signatureDeclaration = < SignatureDeclaration > getDeclarationOfKind ( symbol , SyntaxKind . TypeParameter ) . parent ;
2833+ var signature = typeResolver . getSignatureFromDeclaration ( signatureDeclaration ) ;
2834+ if ( signatureDeclaration . kind === SyntaxKind . ConstructSignature ) {
2835+ displayParts . push ( keywordPart ( SyntaxKind . NewKeyword ) ) ;
2836+ displayParts . push ( spacePart ( ) ) ;
2837+ } else if ( signatureDeclaration . kind !== SyntaxKind . CallSignature ) {
2838+ displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , signatureDeclaration . symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOfClassOrInterface ) )
2839+ }
2840+ displayParts . push . apply ( displayParts , signatureToDisplayParts ( typeResolver , signature , sourceFile , TypeFormatFlags . NoTruncation ) ) ;
2841+ }
28222842 }
28232843 if ( symbolFlags & SymbolFlags . EnumMember ) {
28242844 addPrefixForAnyFunctionOrVar ( symbol , "enum member" ) ;
@@ -2848,7 +2868,16 @@ module ts {
28482868 symbolFlags & SymbolFlags . Variable ) {
28492869 displayParts . push ( punctuationPart ( SyntaxKind . ColonToken ) ) ;
28502870 displayParts . push ( spacePart ( ) ) ;
2851- displayParts . push . apply ( displayParts , typeToDisplayParts ( typeResolver , type , enclosingDeclaration , TypeFormatFlags . NoTruncation ) ) ;
2871+ // If the type is type parameter, format it specially
2872+ if ( type . symbol && type . symbol . flags & SymbolFlags . TypeParameter ) {
2873+ var typeParameterParts = mapToDisplayParts ( writer => {
2874+ typeResolver . writeTypeParameter ( < TypeParameter > type , writer , enclosingDeclaration , TypeFormatFlags . NoTruncation ) ;
2875+ } ) ;
2876+ displayParts . push . apply ( displayParts , typeParameterParts ) ;
2877+ }
2878+ else {
2879+ displayParts . push . apply ( displayParts , typeToDisplayParts ( typeResolver , type , enclosingDeclaration , TypeFormatFlags . NoTruncation ) ) ;
2880+ }
28522881 }
28532882 else if ( symbolFlags & SymbolFlags . Function ||
28542883 symbolFlags & SymbolFlags . Method ||
@@ -2880,9 +2909,8 @@ module ts {
28802909 displayParts . push ( textPart ( symbolKind ) ) ;
28812910 displayParts . push ( punctuationPart ( SyntaxKind . CloseParenToken ) ) ;
28822911 displayParts . push ( spacePart ( ) ) ;
2883- //if (symbol.declarations && symbol.declarations.length) {
2884- displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile ) ) ;
2885- //}
2912+ // Write type parameters of class/Interface if it is property/method of the generic class/interface
2913+ displayParts . push . apply ( displayParts , symbolToDisplayParts ( typeResolver , symbol , sourceFile , /*meaning*/ undefined , SymbolFormatFlags . WriteTypeParametersOfClassOrInterface ) ) ;
28862914 }
28872915 }
28882916
0 commit comments