import { Registration , ServerCapabilities , Unregistration } from 'vscode-languageserver-protocol' ; interface IFlexibleServerCapabilities extends ServerCapabilities { [ key ] : any ; } function registerServerCapability ( serverCapabilities , registration ) { const serverCapabilitiesCopy = JSON . parse ( JSON . stringify ( serverCapabilities ) ) as IFlexibleServerCapabilities ; const { method , registerOptions } = registration ; const providerName = method . substring ( 13 ) + 'Provider' ; if ( providerName ) { if ( ! registerOptions ) { serverCapabilitiesCopy [ providerName ] = true ; } else { serverCapabilitiesCopy [ providerName ] = JSON . parse ( JSON . stringify ( registerOptions ) ) ; } } else { throw new Error ( 'Could not register server capability.' ) ; } return serverCapabilitiesCopy ; } function unregisterServerCapability ( serverCapabilities , unregistration ) { const serverCapabilitiesCopy = JSON . parse ( JSON . stringify ( serverCapabilities ) ) as IFlexibleServerCapabilities ; const { method } = unregistration ; const providerName = method . substring ( 13 ) + 'Provider' ; delete serverCapabilitiesCopy [ providerName ] ; return serverCapabilitiesCopy ; } export { registerServerCapability , unregisterServerCapability } ;