1
1
/* @internal */
2
2
namespace ts . InlineHints {
3
3
interface HintInfo {
4
- text : string
5
- position : number
4
+ text : string ;
5
+ position : number ;
6
+ whitespaceBefore ?: boolean ;
7
+ whitespaceAfter ?: boolean ;
6
8
}
7
9
8
10
export function provideInlineHints ( context : InlineHintsContext ) : HintInfo [ ] {
@@ -41,21 +43,20 @@ namespace ts.InlineHints {
41
43
if ( isCallExpression ( node ) || isNewExpression ( node ) ) {
42
44
visitCallOrNewExpression ( node ) ;
43
45
}
46
+ else if ( isArrowFunction ( node ) || isFunctionExpression ( node ) ) {
47
+ visitFunctionExpressionLike ( node ) ;
48
+ }
44
49
return forEachChild ( node , visitor ) ;
45
50
}
46
51
47
52
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 ) {
51
54
return ;
52
55
}
53
56
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 ) {
59
60
return ;
60
61
}
61
62
@@ -67,11 +68,55 @@ namespace ts.InlineHints {
67
68
if ( ! argumentName || argumentName !== parameterName ) {
68
69
result . push ( {
69
70
text : `${ unescapeLeadingUnderscores ( parameterName ) } :` ,
70
- position : expr . arguments [ i ] . getStart ( )
71
+ position : expr . arguments [ i ] . getStart ( ) ,
72
+ whitespaceAfter : true ,
71
73
} ) ;
72
74
}
73
75
}
74
76
}
75
77
}
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
+ }
76
121
}
77
122
}
0 commit comments