if ( process . env . PRODUCT !== 'ext' ) { throw 'Cant use context module outside of VSCode context' ; } import { ExtensionContext } from 'vscode' ; import { InvalidActionError } from '@sqltools/util/exception' ; let currentContext = { } as any ; const queue = [ ] ; const onRegister = ( cb ) => queue . push ( cb ) ; export const setCurrentContext = ( ctx ) => { currentContext = ctx as ( typeof currentContext ) ; queue . forEach ( cb => cb ( ) ) ; } ; const handler = { get ( _ , prop ) { if ( prop === 'set' ) return setCurrentContext ; if ( prop === 'onRegister' ) return onRegister ; return currentContext [ prop ] ; } , set ( ) { throw new InvalidActionError ( 'Cannot set values to extension context directly!' ) ; } , } ; const Context = new Proxy < typeof currentContext > ( currentContext , handler ) ; export default Context ;