const vsc = { postMessage : ( message ) => { } , } ; function uuid ( ) { return ( '_' + Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ) ; } function createPromiseFromMessageEvent ( requestId ) { return new Promise < any > ( ( resolve , reject ) => { const handleEvent = ( e ) => { if ( requestId === e . data . requestId ) { window . removeEventListener ( 'message' , handleEvent ) ; if ( e . data . error ) { reject ( e . data . error ) ; } else { resolve ( e . data . payload ) ; } } } ; window . addEventListener ( 'message' , handleEvent ) ; } ) ; } export function post < T > ( cmd , payload ) { const requestId = uuid ( ) ; vsc . postMessage ( { requestId , cmd , payload , } ) ; return createPromiseFromMessageEvent ( requestId ) ; } export function initialize ( vscodeApi ) { vsc . postMessage = vscodeApi . postMessage . bind ( ) ; }