import * as os from 'os' ; import { callWithTelemetryAndErrorHandlingSync , IActionContext , parseError } from 'vscode-azureextensionui' ; import { Message } from 'vscode-jsonrpc' ; import { CloseAction , ErrorAction , ErrorHandler } from 'vscode-languageclient' ; import { languageServerName } from '../../common' ; const languageServerErrorTelemId = 'Language Server Error' ; /**
 * Wraps the default error handler for the language server client to send telemetry for the error
 * events.
 *
 * (The default error handler causes the server to shut down after 3 errors or 5 crashes.)
 */ export class WrappedErrorHandler implements ErrorHandler { private _serverStartTime : number ; constructor ( private _handler ) { this . _serverStartTime = Date . now ( ) ; } param error param message param count public error ( error , message , count ) { callWithTelemetryAndErrorHandlingSync ( languageServerErrorTelemId , ( context ) => { context . telemetry . properties . jsonrpcMessage = message ? message . jsonrpc : "" ; context . telemetry . measurements . secondsSinceStart = ( Date . now ( ) - this . _serverStartTime ) / 1000 ; throw new Error ( `An error occurred in the ${ languageServerName }.${ os . EOL }${ os . EOL }${ parseError ( error ) . message }` ) ; } ) ; return this . _handler . error ( error , message , count ) ; } /**
     * The connection to the server got closed.
     */ public closed ( ) { callWithTelemetryAndErrorHandlingSync ( languageServerErrorTelemId , ( context ) => { context . telemetry . measurements . secondsSinceStart = ( Date . now ( ) - this . _serverStartTime ) / 1000 ; throw new Error ( `The connection to the ${ languageServerName } got closed.` ) ; } ) ; return this . _handler . closed ( ) ; } }