From e766dbe43a8eb0748c32dc388bb3746dda8954a4 Mon Sep 17 00:00:00 2001 From: Pengcheng Xu Date: Wed, 12 Jun 2019 13:31:02 +0800 Subject: [PATCH] [Code] Use different connect direction for ctags langserver (#38659) --- .../plugins/code/server/lsp/ctags_launcher.ts | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/code/server/lsp/ctags_launcher.ts b/x-pack/plugins/code/server/lsp/ctags_launcher.ts index 773d45982b99..59c02e1ab859 100644 --- a/x-pack/plugins/code/server/lsp/ctags_launcher.ts +++ b/x-pack/plugins/code/server/lsp/ctags_launcher.ts @@ -4,43 +4,50 @@ * you may not use this file except in compliance with the Elastic License. */ +import getPort from 'get-port'; +import { spawn } from 'child_process'; import { ServerOptions } from '../server_options'; import { LoggerFactory } from '../utils/log_factory'; -import { ILanguageServerLauncher } from './language_server_launcher'; import { LanguageServerProxy } from './proxy'; +import { Logger } from '../log'; import { RequestExpander } from './request_expander'; +import { AbstractLauncher } from './abstract_launcher'; -export class CtagsLauncher implements ILanguageServerLauncher { +const CTAGS_LANG_DETACH_PORT = 2092; +export class CtagsLauncher extends AbstractLauncher { private isRunning: boolean = false; constructor( readonly targetHost: string, readonly options: ServerOptions, readonly loggerFactory: LoggerFactory - ) {} + ) { + super('ctags', targetHost, options, loggerFactory); + } public get running(): boolean { return this.isRunning; } - public async launch(builtinWorkspace: boolean, maxWorkspace: number, installationPath: string) { - const port = 2092; - - const log = this.loggerFactory.getLogger(['code', `ctags@${this.targetHost}:${port}`]); - const proxy = new LanguageServerProxy(port, this.targetHost, log, this.options.lsp); - - log.info('Detach mode, expected ctags langserver launch externally'); - proxy.onConnected(() => { - this.isRunning = true; - }); - proxy.onDisconnected(() => { - this.isRunning = false; - if (!proxy.isClosed) { - log.warn('ctags language server disconnected, reconnecting'); - setTimeout(() => proxy.connect(), 1000); - } - }); - - proxy.listen(); - await proxy.connect(); + createExpander( + proxy: LanguageServerProxy, + builtinWorkspace: boolean, + maxWorkspace: number + ): RequestExpander { return new RequestExpander(proxy, builtinWorkspace, maxWorkspace, this.options); } + + startConnect(proxy: LanguageServerProxy) { + proxy.awaitServerConnection(); + } + + async getPort(): Promise { + if (!this.options.lsp.detach) { + return await getPort(); + } + return CTAGS_LANG_DETACH_PORT; + } + + async spawnProcess(installationPath: string, port: number, log: Logger) { + // TODO(pcxu): add spawn command here for ctags langserver + return spawn(''); + } }