'use strict' ; import { MapYcmFixItToVSCodeEdit } from './utils' ; import * as path from 'path' ; import { workspace , Disposable , ExtensionContext , window , commands } from 'vscode' ; import { LanguageClient , LanguageClientOptions , SettingMonitor , ServerOptions , TransportKind } from 'vscode-languageclient' ; let client ; let disposable ; export function activate ( context ) { let serverModule = context . asAbsolutePath ( path . join ( 'server' , 'server.js' ) ) ; let debugOptions = { execArgv : [ '--nolazy' , '--inspect=6004' ] } ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } } ; const languages = workspace . getConfiguration ( 'ycmd' ) . get ( 'enabled_languages' ) as string [ ] ; let clientOptions = { documentSelector : languages , synchronize : { configurationSection : 'ycmd' , } } ; client = new LanguageClient ( 'ycm-language-server' , serverOptions , clientOptions ) ; client . onReady ( ) . then ( ( ) => { client . onNotification ( 'error' , ( params ) => { window . showErrorMessage ( `[ycm] ${ params }` ) ; } ) ; } ) ; disposable = client . start ( ) ; commands . registerCommand ( 'ycm.lint' , ( args ) => { client . sendNotification ( 'lint' , window . activeTextEditor . document . uri . toString ( ) ) ; } ) ; commands . registerCommand ( 'ycm.FixIt' , async ( args ) => { const fixit = args as YcmFixIt ; const edits = MapYcmFixItToVSCodeEdit ( fixit ) ; const success = await workspace . applyEdit ( edits ) ; client . sendNotification ( 'lint' , window . activeTextEditor . document . uri . toString ( ) ) ; } ) ; context . subscriptions . push ( disposable ) ; workspace . onDidSaveTextDocument ( ( event ) => { let whenToLint = workspace . getConfiguration ( 'ycmd' ) . get ( 'lint_run' ) as string ; if ( whenToLint === 'onSave' ) { client . sendNotification ( 'lint' , window . activeTextEditor . document . uri . toString ( ) ) ; } } ) ; }