import { ExtensionContext , LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , workspace , services , Buffer , events , } from 'coc.nvim' ; import { resolve } from 'path' ; export async function activate ( context ) { const config = workspace . getConfiguration ( 'vimlsp' ) ; const isEnable = config . get < boolean > ( 'enable' , true ) ; if ( ! isEnable ) { return ; } let serverModule = resolve ( context . extensionPath , 'out' , 'server' ) ; let serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc } } ; const isEnableDebug = config . get < boolean > ( 'debug' , false ) ; if ( isEnableDebug ) { serverOptions . debug . options = { execArgv : [ "--nolazy" , "--debug=6009" ] } ; } const { nvim } = workspace ; const vimruntime = await nvim . commandOutput ( 'echo $VIMRUNTIME' ) ; const runtimepath = await nvim . getOption ( 'runtimepath' ) ; const iskeyword = await nvim . getOption ( 'iskeyword' ) ; const isEnableDiagnostic = config . get < boolean > ( 'diagnostic.enable' , true ) ; const fromVimruntime = config . get < boolean > ( 'suggest.fromVimruntime' , true ) ; const fromRuntimepath = config . get < boolean > ( 'suggest.fromRuntimepath' , false ) ; const indexesRuntimepath = config . get < boolean > ( 'indexes.runtimepath' , true ) ; const indexesCount = config . get < number > ( 'indexes.count' , 1 ) ; const indexesGap = config . get < number > ( 'indexes.gap' , 100 ) ; const projectRootPatterns = config . get < string [ ] > ( 'indexes.projectRootPatterns' , [ ".git" , "autoload" , "plugin" ] ) ; let clientOptions = { documentSelector : config . get < string [ ] > ( 'vimlsp.filetypes' , [ 'vim' ] ) , initializationOptions : { isNeovim : workspace . isNvim , iskeyword , vimruntime , runtimepath , diagnostic : { enable : isEnableDiagnostic } , indexes : { runtimepath : indexesRuntimepath , count : indexesCount , gap : indexesGap , projectRootPatterns } , suggest : { fromVimruntime , fromRuntimepath } } } ; let client = new LanguageClient ( 'vimlsp' , 'vim language server' , serverOptions , clientOptions ) ; const changeIskeyword = async ( buffer ) => { const iskeyword = await buffer . getOption ( 'iskeyword' ) ; if ( client . started ) { client . sendNotification ( '$/change/iskeyword' , iskeyword ) ; } } ; client . onReady ( ) . then ( ( ) => { setTimeout ( ( ) => { let doc = workspace . documents . find ( o => o . filetype == 'vim' ) ; if ( doc ) changeIskeyword ( doc . buffer ) ; } , 100 ) ; } ) ; events . on ( 'BufEnter' , async ( bufnr ) => { const doc = await workspace . document ; if ( doc && doc . filetype == 'vim' ) await changeIskeyword ( doc . buffer ) ; } , null , context . subscriptions ) ; context . subscriptions . push ( services . registLanguageClient ( client ) ) ; }