@@ -2788,18 +2788,37 @@ namespace ts {
27882788 return node && node . parent && node . parent . kind === SyntaxKind . PropertyAccessExpression && ( < PropertyAccessExpression > node . parent ) . name === node ;
27892789 }
27902790
2791+ function climbPastPropertyAccess ( node : Node ) {
2792+ return isRightSideOfPropertyAccess ( node ) ? node . parent : node ;
2793+ }
2794+
27912795 function isCallExpressionTarget ( node : Node ) : boolean {
2792- if ( isRightSideOfPropertyAccess ( node ) ) {
2793- node = node . parent ;
2794- }
2795- return node && node . parent && node . parent . kind === SyntaxKind . CallExpression && ( < CallExpression > node . parent ) . expression === node ;
2796+ return ! ! getCallOrNewExpressionWorker ( node , SyntaxKind . CallExpression ) ;
27962797 }
27972798
27982799 function isNewExpressionTarget ( node : Node ) : boolean {
2799- if ( isRightSideOfPropertyAccess ( node ) ) {
2800- node = node . parent ;
2800+ return ! ! getCallOrNewExpressionWorker ( node , SyntaxKind . NewExpression ) ;
2801+ }
2802+
2803+ function getCallOrNewExpressionTargetingNode ( node : Node ) : CallExpression | NewExpression | undefined {
2804+ return < CallExpression > getCallOrNewExpressionWorker ( node , SyntaxKind . CallExpression ) || < NewExpression > getCallOrNewExpressionWorker ( node , SyntaxKind . NewExpression ) ;
2805+ }
2806+
2807+ function tryGetCalledDeclaration ( typeChecker : TypeChecker , node : Node ) : SignatureDeclaration | undefined {
2808+ const callOrNewExpression = getCallOrNewExpressionTargetingNode ( node ) ;
2809+ if ( callOrNewExpression ) {
2810+ const signature = typeChecker . getResolvedSignature ( callOrNewExpression ) ;
2811+ return signature . declaration ;
28012812 }
2802- return node && node . parent && node . parent . kind === SyntaxKind . NewExpression && ( < CallExpression > node . parent ) . expression === node ;
2813+ }
2814+
2815+ function getCallOrNewExpressionWorker ( node : Node , kind : SyntaxKind ) : Node | undefined {
2816+ const target = climbPastPropertyAccess ( node ) ;
2817+ return target &&
2818+ target . parent &&
2819+ target . parent . kind === kind &&
2820+ ( < CallExpression > target . parent ) . expression === target &&
2821+ target . parent ;
28032822 }
28042823
28052824 function isNameOfModuleDeclaration ( node : Node ) {
@@ -5068,14 +5087,25 @@ namespace ts {
50685087 } ;
50695088 }
50705089
5090+ function getSymbolInfo ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) {
5091+ return {
5092+ symbolName : typeChecker . symbolToString ( symbol ) , // Do not get scoped name, just the name of the symbol
5093+ symbolKind : getSymbolKind ( symbol , node ) ,
5094+ containerName : symbol . parent ? typeChecker . symbolToString ( symbol . parent , node ) : ""
5095+ } ;
5096+ }
5097+
5098+ function getDefinitionFromSignatureDeclaration ( decl : SignatureDeclaration ) : DefinitionInfo {
5099+ const typeChecker = program . getTypeChecker ( ) ;
5100+ const { symbolName, symbolKind, containerName } = getSymbolInfo ( typeChecker , decl . symbol , decl ) ;
5101+ return createDefinitionInfo ( decl , symbolKind , symbolName , containerName ) ;
5102+ }
5103+
50715104 function getDefinitionFromSymbol ( symbol : Symbol , node : Node ) : DefinitionInfo [ ] {
50725105 const typeChecker = program . getTypeChecker ( ) ;
50735106 const result : DefinitionInfo [ ] = [ ] ;
50745107 const declarations = symbol . getDeclarations ( ) ;
5075- const symbolName = typeChecker . symbolToString ( symbol ) ; // Do not get scoped name, just the name of the symbol
5076- const symbolKind = getSymbolKind ( symbol , node ) ;
5077- const containerSymbol = symbol . parent ;
5078- const containerName = containerSymbol ? typeChecker . symbolToString ( containerSymbol , node ) : "" ;
5108+ const { symbolName, symbolKind, containerName } = getSymbolInfo ( typeChecker , symbol , node ) ;
50795109
50805110 if ( ! tryAddConstructSignature ( symbol , node , symbolKind , symbolName , containerName , result ) &&
50815111 ! tryAddCallSignature ( symbol , node , symbolKind , symbolName , containerName , result ) ) {
@@ -5201,6 +5231,12 @@ namespace ts {
52015231 }
52025232
52035233 const typeChecker = program . getTypeChecker ( ) ;
5234+
5235+ const calledDeclaration = tryGetCalledDeclaration ( typeChecker , node ) ;
5236+ if ( calledDeclaration ) {
5237+ return [ getDefinitionFromSignatureDeclaration ( calledDeclaration ) ] ;
5238+ }
5239+
52045240 let symbol = typeChecker . getSymbolAtLocation ( node ) ;
52055241
52065242 // Could not find a symbol e.g. node is string or number keyword,
0 commit comments