import { AutoWire , Logger } from "@vmware/vrdt-common" ; import { Disposable , InitializedParams , InitializeParams , ServerCapabilities } from "vscode-languageserver" ; import capabilities from "./Capabilities" ; import { ConnectionLocator } from "./ConnectionLocator" ; export type InitListener = ( event : InitializeParams ) => void ; export type InitdListener = ( event : InitializedParams ) => void ; @ AutoWire export class Initializer { private initListeners : InitListener [ ] = [ ] ; private initdListeners : InitdListener [ ] = [ ] ; private readonly logger = Logger . get ( "Initializer" ) ; constructor ( connectionLocator ) { connectionLocator . connection . onInitialize ( e => this . initialize ( e ) ) ; connectionLocator . connection . onInitialized ( e => this . initialized ( e ) ) ; } onInitialize ( l ) { this . initListeners . push ( l ) ; return { dispose : ( ) => this . initListeners . splice ( this . initListeners . indexOf ( l ) , 1 ) } ; } onInitialized ( l ) { this . initdListeners . push ( l ) ; return { dispose : ( ) => this . initdListeners . splice ( this . initdListeners . indexOf ( l ) , 1 ) } ; } private initialize ( event ) { this . logger . info ( "Initializing all registered components... capabilities = " , { client : event . capabilities , server : capabilities } ) ; this . initListeners . forEach ( l => { l ( event ) ; } ) ; return { capabilities } ; } private initialized ( event ) { this . initdListeners . forEach ( l => { l ( event ) ; } ) ; } }