import * as vscode from 'vscode' ; export const activate = async ( ) : Promise < void > => { const ext = vscode . extensions . getExtension ( 'stoplight.spectral' ) ; if ( ext === undefined ) { throw new Error ( 'Unable to activate the extension' ) ; } await ext . activate ( ) ; console . info ( `Extension '${ ext . id }' v${ ext . packageJSON . version } has been successfully activated.` ) ; } ; async function sleep ( ms ) { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; } const isOutputPanel = ( uri ) => { return uri . toString ( ) . startsWith ( 'output:extension-output-' ) ; } ; export const retrieveOutputChannelId = async ( ) : Promise < vscode . Uri > => { await vscode . commands . executeCommand ( 'spectral.showOutputChannel' ) ; await sleep ( 2000 ) ; const outputs = vscode . workspace . textDocuments . filter ( ( d ) => isOutputPanel ( d . uri ) ) ; if ( outputs . length !== 1 ) { throw new Error ( 'Unable to retrieve the Spectral output channel' ) ; } return outputs [ 0 ] . uri ; } ; export const readFromOutputChannelId = async ( outputChannelId ) : Promise < string > => { await sleep ( 2000 ) ; const x = await vscode . workspace . openTextDocument ( outputChannelId ) ; return x . getText ( ) ; } ; export const openFile = async ( docUri ) : Promise < void > => { const doc = await vscode . workspace . openTextDocument ( docUri ) ; await vscode . window . showTextDocument ( doc ) ; await sleep ( 2000 ) ; } ;