/**
 * LSP client for vscode-ruby
 */ import path from 'path' ; import { commands , ExtensionContext , window , workspace , WorkspaceFolder } from 'vscode' ; import { ConfigurationParams , CancellationToken , LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , WorkspaceMiddleware , } from 'vscode-languageclient/node' ; let client ; export function activate ( context ) { const serverModule = context . asAbsolutePath ( path . join ( 'dist' , 'server' , 'index.js' ) ) ; const debugOptions = { execArgv : [ '--nolazy' , '--inspect=6009' ] } ; const serverOptions = { run : { module : serverModule , transport : TransportKind . ipc } , debug : { module : serverModule , transport : TransportKind . ipc , options : debugOptions } , } ; const rubyDocumentSelector = [ { scheme : 'file' , language : 'ruby' } , { scheme : 'untitled' , language : 'ruby' } , ] ; const clientOptions = { documentSelector : rubyDocumentSelector , synchronize : { fileEvents : workspace . createFileSystemWatcher ( '**/{.ruby-version,.rvmrc,.tool-versions}' ) , } , outputChannel : window . createOutputChannel ( 'Ruby Language Server' ) , middleware : { workspace : { configuration : ( params , token , next ) : any [ ] => { if ( ! params . items ) { return [ ] ; } let result = next ( params , token , next ) ; let settings = result [ 0 ] ; let scopeUri = '' ; for ( let item of params . items ) { if ( ! item . scopeUri ) { continue ; } else { scopeUri = item . scopeUri ; } } let resource = client . protocol2CodeConverter . asUri ( scopeUri ) ; let workspaceFolder = workspace . getWorkspaceFolder ( resource ) ; if ( ! workspaceFolder && workspace . workspaceFolders ) { workspaceFolder = workspace . workspaceFolders [ 0 ] ; } if ( workspaceFolder ) { const protocolUri = client . code2ProtocolConverter . asUri ( workspaceFolder . uri ) ; settings . workspaceFolderUri = protocolUri ; } return result ; } , } as WorkspaceMiddleware , } , } ; client = new LanguageClient ( 'ruby' , 'Ruby' , serverOptions , clientOptions ) ; client . registerProposedFeatures ( ) ; context . subscriptions . push ( client . start ( ) , commands . registerCommand ( 'ruby.showLanguageServerOutputChannel' , ( ) => { client . outputChannel . show ( ) ; } ) ) ; } export function deactivate ( ) { return client ? client . stop ( ) : undefined ; }