import * as path from 'path' ; import { spawn } from 'child_process' ; import * as vscode from 'vscode' ; import { LanguageClient , LanguageClientOptions , ServerOptions , RevealOutputChannelOn } from 'vscode-languageclient' ; import * as url from 'url' ; import * as beautify from 'js-beautify' ; export async function activate ( context ) { let client ; const serverOptions = async ( ) => { const childProcess = spawn ( process . execPath , [ path . resolve ( __dirname , '..' , 'node_modules' , 'javascript-typescript-langserver' , 'lib' , 'language-server-stdio.js' ) ] ) ; childProcess . stderr . on ( 'data' , ( chunk ) => { client . error ( chunk + '' ) ; } ) ; return childProcess ; } ; const clientOptions = { revealOutputChannelOn : RevealOutputChannelOn . Never , documentSelector : [ 'extendscript' , 'jsx' ] , uriConverters : { code2Protocol : uri => url . format ( url . parse ( uri . toString ( true ) ) ) , protocol2Code : str => vscode . Uri . parse ( str ) } , } ; client = new LanguageClient ( 'ExtendScript Language Server' , serverOptions , clientOptions ) ; const disposable = client . start ( ) ; vscode . languages . registerDocumentFormattingEditProvider ( 'jsx' , { provideDocumentFormattingEdits ( document ) { const fullRange = document . validateRange ( new vscode . Range ( 0 , 0 , Number . MAX_VALUE , Number . MAX_VALUE ) ) ; return [ vscode . TextEdit . replace ( fullRange , beautify ( document . getText ( ) ) ) ] ; } } ) ; context . subscriptions . push ( disposable ) ; }