@@ -202,11 +202,57 @@ module ts.SignatureHelp {
202202 cancellationToken . throwIfCancellationRequested ( ) ;
203203
204204 if ( ! candidates . length ) {
205+ // We didn't have any sig help items produced by the TS compiler. If this is a JS
206+ // file, then see if we can figure out anything better.
207+ if ( isJavaScript ( sourceFile . fileName ) ) {
208+ return createJavaScriptSignatureHelpItems ( argumentInfo ) ;
209+ }
210+
205211 return undefined ;
206212 }
207213
208214 return createSignatureHelpItems ( candidates , resolvedSignature , argumentInfo ) ;
209215
216+ function createJavaScriptSignatureHelpItems ( argumentInfo : ArgumentListInfo ) : SignatureHelpItems {
217+ if ( argumentInfo . invocation . kind !== SyntaxKind . CallExpression ) {
218+ return undefined ;
219+ }
220+
221+ // See if we can find some symbol with the call expression name that has call signatures.
222+ let callExpression = < CallExpression > argumentInfo . invocation ;
223+ let expression = callExpression . expression ;
224+ let name = expression . kind === SyntaxKind . Identifier
225+ ? < Identifier > expression
226+ : expression . kind === SyntaxKind . PropertyAccessExpression
227+ ? ( < PropertyAccessExpression > expression ) . name
228+ : undefined ;
229+
230+ if ( ! name || ! name . text ) {
231+ return undefined ;
232+ }
233+
234+ let typeChecker = program . getTypeChecker ( ) ;
235+ for ( let sourceFile of program . getSourceFiles ( ) ) {
236+ let nameToDeclarations = sourceFile . getNamedDeclarations ( ) ;
237+ let declarations = getProperty ( nameToDeclarations , name . text ) ;
238+
239+ if ( declarations ) {
240+ for ( let declaration of declarations ) {
241+ let symbol = declaration . symbol ;
242+ if ( symbol ) {
243+ let type = typeChecker . getTypeOfSymbolAtLocation ( symbol , declaration ) ;
244+ if ( type ) {
245+ let callSignatures = type . getCallSignatures ( ) ;
246+ if ( callSignatures && callSignatures . length ) {
247+ return createSignatureHelpItems ( callSignatures , callSignatures [ 0 ] , argumentInfo ) ;
248+ }
249+ }
250+ }
251+ }
252+ }
253+ }
254+ }
255+
210256 /**
211257 * Returns relevant information for the argument list and the current argument if we are
212258 * in the argument of an invocation; returns undefined otherwise.
0 commit comments