[Code] Use different connect direction for ctags langserver (#38659)
This commit is contained in:
parent
a8b5220bac
commit
e766dbe43a
|
@ -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<number> {
|
||||
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('');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue