import { getNodeFileFS } from './nodeFs' ; import { Disposable , ExtensionContext } from 'vscode' ; import { startClient , LanguageClientConstructor } from '../htmlClient' ; import { ServerOptions , TransportKind , LanguageClientOptions , LanguageClient } from 'vscode-languageclient/node' ; import { TextDecoder } from 'util' ; import * as fs from 'fs' ; import TelemetryReporter from 'vscode-extension-telemetry' ; let telemetry ; export function activate ( context ) { let clientPackageJSON = getPackageInfo ( context ) ; telemetry = new TelemetryReporter ( clientPackageJSON . name , clientPackageJSON . version , clientPackageJSON . aiKey ) ; const serverMain = `./server/${ clientPackageJSON . main . indexOf ( '/dist/' ) !== - 1 ? 'dist' : 'out' }/node/htmlServerMain` ; const serverModule = context . asAbsolutePath ( serverMain ) ; const debugOptions = { execArgv : [ '--nolazy' , '--inspect=' + ( 8000 + Math . round ( Math . random ( ) * 999 ) ) ] } ; const serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; const newLanguageClient = ( id , name , clientOptions ) => { return new LanguageClient ( id , name , serverOptions , clientOptions ) ; } ; const timer = { setTimeout ( callback , ms , ... args ) { const handle = setTimeout ( callback , ms , ... args ) ; return { dispose : ( ) => clearTimeout ( handle ) } ; } } ; startClient ( context , newLanguageClient , { fileFs : getNodeFileFS ( ) , TextDecoder , telemetry , timer } ) ; } interface IPackageInfo { name : string ; version : string ; aiKey : string ; main : string ; } function getPackageInfo ( context ) { const location = context . asAbsolutePath ( './package.json' ) ; try { return JSON . parse ( fs . readFileSync ( location ) . toString ( ) ) ; } catch ( e ) { console . log ( `Problems reading ${ location }: ${ e }` ) ; return { name : '' , version : '' , aiKey : '' , main : '' } ; } }