import { resolve } from 'path' ; import { ExtensionContext , LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , workspace , services } from 'coc.nvim' ; import { linters as defaultLinters , formatters as defaultFormatters } from './config' ; import * as _ from "lodash" ; export function activate ( context ) { const config = workspace . getConfiguration ( 'diagnostic-languageserver' ) ; const isEnable = config . get < boolean > ( 'enable' , true ) ; if ( ! isEnable ) { return ; } const filetypes = config . get < Record < string , string > > ( 'filetypes' , { } ) ; const formatFiletypes = config . get < Record < string , string > > ( 'formatFiletypes' , { } ) ; const documentSelector = Object . keys ( { ... filetypes , ... formatFiletypes } ) ; if ( documentSelector . length === 0 ) { return ; } const linters = config . get < Record < string , string > > ( 'linters' , { } ) ; const formatters = config . get < Record < string , string > > ( 'formatters' , { } ) ; const isEnableDebug = config . get < boolean > ( 'debug' , false ) ; const traceServer = config . get < 'off' | 'message' | 'verbose' > ( 'trace.server' , 'off' ) ; const mergeConfig = config . get < boolean > ( 'mergeConfig' , false ) ; const merge = ( a , b ) => mergeConfig ? _ . merge ( { } , a , b ) : { ... a , ... b } ; let serverModule = resolve ( context . extensionPath , 'out' , 'server' ) ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc , args : traceServer === 'verbose' ? [ '--log-level' , '4' ] : undefined } , debug : { module : serverModule , transport : TransportKind . ipc , args : traceServer === 'verbose' ? [ '--log-level' , '4' ] : undefined } } ; if ( isEnableDebug ) { serverOptions . debug . options = { execArgv : [ "--nolazy" , "--debug=6009" ] } ; } let clientOptions = { documentSelector , initializationOptions : { linters : merge ( defaultLinters , linters ) , filetypes , formatters : merge ( defaultFormatters , formatters ) , formatFiletypes } } ; let client = new LanguageClient ( 'diagnostic-languageserver' , 'diagnostic language service' , serverOptions , clientOptions ) ; context . subscriptions . push ( services . registLanguageClient ( client ) ) ; }