11/* @internal */
22namespace ts . InlineHints {
33 interface HintInfo {
4- text : string
5- position : number
4+ text : string ;
5+ position : number ;
6+ whitespaceBefore ?: boolean ;
7+ whitespaceAfter ?: boolean ;
68 }
79
810 export function provideInlineHints ( context : InlineHintsContext ) : HintInfo [ ] {
@@ -41,21 +43,20 @@ namespace ts.InlineHints {
4143 if ( isCallExpression ( node ) || isNewExpression ( node ) ) {
4244 visitCallOrNewExpression ( node ) ;
4345 }
46+ else if ( isArrowFunction ( node ) || isFunctionExpression ( node ) ) {
47+ visitFunctionExpressionLike ( node ) ;
48+ }
4449 return forEachChild ( node , visitor ) ;
4550 }
4651
4752 function visitCallOrNewExpression ( expr : CallExpression | NewExpression ) {
48- const candidates : Signature [ ] = [ ] ;
49- const signature = checker . getResolvedSignatureForSignatureHelp ( expr , candidates ) ;
50- if ( ! signature || ! candidates . length ) {
53+ if ( ! expr . arguments || ! expr . arguments . length ) {
5154 return ;
5255 }
5356
54- getCallArgumentsHints ( expr , signature ) ;
55- }
56-
57- function getCallArgumentsHints ( expr : CallExpression | NewExpression , signature : Signature ) {
58- if ( ! expr . arguments || ! expr . arguments . length ) {
57+ const candidates : Signature [ ] = [ ] ;
58+ const signature = checker . getResolvedSignatureForSignatureHelp ( expr , candidates ) ;
59+ if ( ! signature || ! candidates . length ) {
5960 return ;
6061 }
6162
@@ -67,11 +68,55 @@ namespace ts.InlineHints {
6768 if ( ! argumentName || argumentName !== parameterName ) {
6869 result . push ( {
6970 text : `${ unescapeLeadingUnderscores ( parameterName ) } :` ,
70- position : expr . arguments [ i ] . getStart ( )
71+ position : expr . arguments [ i ] . getStart ( ) ,
72+ whitespaceAfter : true ,
7173 } ) ;
7274 }
7375 }
7476 }
7577 }
78+
79+ function visitFunctionExpressionLike ( expr : ArrowFunction | FunctionExpression ) {
80+ if ( ! expr . parameters . length || expr . parameters . every ( param => param . type ) ) {
81+ return ;
82+ }
83+
84+ const contextualType = checker . getContextualType ( expr ) ;
85+ if ( ! contextualType ) {
86+ return ;
87+ }
88+
89+ const signatures = checker . getSignaturesOfType ( contextualType , SignatureKind . Call ) ;
90+ const signature = firstOrUndefined ( signatures ) ;
91+ if ( ! signature ) {
92+ return ;
93+ }
94+
95+ for ( let i = 0 ; i < expr . parameters . length && i < signature . parameters . length ; ++ i ) {
96+ const param = expr . parameters [ i ] ;
97+ if ( param . type ) {
98+ continue ;
99+ }
100+
101+ const signatureParam = signature . parameters [ i ] ;
102+ const signatureParamType = checker . getTypeOfSymbolAtLocation ( signatureParam , signatureParam . valueDeclaration ) ;
103+
104+ const valueDeclaration = signatureParam . valueDeclaration ;
105+ if ( ! valueDeclaration || ! isParameter ( valueDeclaration ) || ! valueDeclaration . type ) {
106+ continue ;
107+ }
108+
109+ const typeDisplayString = displayPartsToString ( typeToDisplayParts ( checker , signatureParamType ) ) ;
110+ if ( ! typeDisplayString ) {
111+ continue ;
112+ }
113+
114+ result . push ( {
115+ text : `:${ typeDisplayString } ` ,
116+ position : param . end ,
117+ whitespaceBefore : true ,
118+ } ) ;
119+ }
120+ }
76121 }
77122}
0 commit comments