[Code] fix a problem when using server connection in lsp proxy (#38750)

This commit is contained in:
Yulong 2019-06-12 16:08:53 +08:00 committed by GitHub
parent dfe30a9bdf
commit d6cf22f9ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,8 +60,6 @@ export class LanguageServerProxy implements ILanguageServerHandler {
private readonly logger: Logger;
private readonly lspOptions: LspOptions;
private eventEmitter = new EventEmitter();
private passiveConnection: boolean = false;
private connectingPromise: Cancelable<MessageConnection> | null = null;
constructor(targetPort: number, targetHost: string, logger: Logger, lspOptions: LspOptions) {
@ -112,7 +110,7 @@ export class LanguageServerProxy implements ILanguageServerHandler {
if (this.error) {
throw this.error;
}
const clientConn = await this.tryConnect();
const clientConn = await this.connect();
const rootUri = workspaceFolders[0].uri;
const params = {
processId: null,
@ -145,7 +143,7 @@ export class LanguageServerProxy implements ILanguageServerHandler {
this.logger.debug('received request method: ' + method);
}
return this.tryConnect().then(clientConn => {
return this.connect().then(clientConn => {
if (this.lspOptions.verbose) {
this.logger.info(`proxy method:${method} to Language Server `);
} else {
@ -159,7 +157,7 @@ export class LanguageServerProxy implements ILanguageServerHandler {
}
public async shutdown() {
const clientConn = await this.tryConnect();
const clientConn = await this.connect();
this.logger.info(`sending shutdown request`);
return await clientConn.sendRequest('shutdown');
}
@ -185,7 +183,6 @@ export class LanguageServerProxy implements ILanguageServerHandler {
public awaitServerConnection() {
// prevent calling this method multiple times which may cause 'port already in use' error
if (!this.connectingPromise) {
this.passiveConnection = true;
this.connectingPromise = new Cancelable((res, rej, onCancel) => {
const server = net.createServer(socket => {
this.initialized = false;
@ -311,12 +308,6 @@ export class LanguageServerProxy implements ILanguageServerHandler {
});
}
private tryConnect() {
return this.passiveConnection
? ((this.connectingPromise as unknown) as Promise<MessageConnection>)
: this.connect();
}
public changePort(port: number) {
if (port !== this.targetPort) {
this.targetPort = port;