'use strict' ; import { SignatureHelpProvider , SignatureHelp , SignatureInformation , ParameterInformation , TextDocument , Position , CancellationToken } from 'vscode' ; import * as Previewer from './previewer' ; import * as Proto from '../protocol' ; import { ITypescriptServiceClient } from '../typescriptService' ; export default class TypeScriptSignatureHelpProvider implements SignatureHelpProvider { private client : ITypescriptServiceClient ; public constructor ( client ) { this . client = client ; } public provideSignatureHelp ( document , position , token ) { let args = { file : this . client . asAbsolutePath ( document . uri ) , line : position . line + 1 , offset : position . character + 1 } ; if ( ! args . file ) { return Promise . resolve < SignatureHelp > ( null ) ; } return this . client . execute ( 'signatureHelp' , args , token ) . then ( ( response ) => { let info = response . body ; if ( ! info ) { return null ; } let result = new SignatureHelp ( ) ; result . activeSignature = info . selectedItemIndex ; result . activeParameter = info . argumentIndex ; if ( info . items [ info . selectedItemIndex ] . isVariadic ) { } info . items . forEach ( ( item , i ) => { if ( i === info . selectedItemIndex && item . isVariadic ) { result . activeParameter = Math . min ( info . argumentIndex , item . parameters . length - 1 ) ; } let signature = new SignatureInformation ( '' ) ; signature . label += Previewer . plain ( item . prefixDisplayParts ) ; item . parameters . forEach ( ( p , i , a ) => { let parameter = new ParameterInformation ( Previewer . plain ( p . displayParts ) , Previewer . plain ( p . documentation ) ) ; signature . label += parameter . label ; signature . parameters . push ( parameter ) ; if ( i < a . length - 1 ) { signature . label += Previewer . plain ( item . separatorDisplayParts ) ; } } ) ; signature . label += Previewer . plain ( item . suffixDisplayParts ) ; signature . documentation = Previewer . plain ( item . documentation ) ; result . signatures . push ( signature ) ; } ) ; return result ; } , ( err ) => { this . client . error ( `'signatureHelp' request failed with error.` , err ) ; return null ; } ) ; } }