Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createConnection(reader : MessageReader, writer : MessageWriter): IConnection {
// Use stdin and stdout for communication:
let msgConnection = createMessageConnection(reader, writer);
let result: IConnection = {
listen: (): void => msgConnection.listen(),
initialize: (params: RunParams) => msgConnection.sendRequest(RunRequest.type, params),
onTestSuiteUpdated: (handler) => msgConnection.onNotification(TestSuiteUpdateNotification.type, handler),
//onDataOutput: (handler) => msgConnection.onNotification(DataOutputNotification.type, handler),
onClose: (handler) => msgConnection.onClose(handler),
onError: (handler) => msgConnection.onError(handler),
}
return result;
}
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import 'reflect-metadata';
import { ConsoleLogger } from 'vscode-ws-jsonrpc/lib/logger';
import { createMessageConnection, IPCMessageReader, IPCMessageWriter, Trace } from 'vscode-jsonrpc';
import { checkParentAlive, ipcEntryPoint, IPCEntryPoint } from './ipc-protocol';
checkParentAlive();
const reader = new IPCMessageReader(process);
const writer = new IPCMessageWriter(process);
const logger = new ConsoleLogger();
const connection = createMessageConnection(reader, writer, logger);
connection.trace(Trace.Off, {
// tslint:disable-next-line:no-any
log: (message: any, data?: string) => console.log(message, data)
});
const entryPoint = require(ipcEntryPoint!).default as IPCEntryPoint;
entryPoint(connection);
'setUserOptions'
])
// @ts-ignore
cache.on.and.callFake((name: string, handler: (file: Uri, messages: Message[]) => void) => {
log = handler
return cache
})
// @ts-ignore
cache.run.and.returnValue(true)
// @ts-ignore
cache.getTargets.and.returnValue(['file://foo/bar.pdf'])
client = rpc.createMessageConnection(clientTransport[0], clientTransport[1])
client.listen()
server = new Server(serverTransport, cache)
server.start()
})
protected createConnection(childProcess: cp.ChildProcess, options: ResolvedIPCConnectionOptions): MessageConnection {
const reader = new IPCMessageReader(childProcess);
const writer = new IPCMessageWriter(childProcess);
const connection = createMessageConnection(reader, writer, {
error: (message: string) => this.logger.error(`[${options.serverName}: ${childProcess.pid}] ${message}`),
warn: (message: string) => this.logger.warn(`[${options.serverName}: ${childProcess.pid}] ${message}`),
info: (message: string) => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${message}`),
log: (message: string) => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${message}`)
});
connection.trace(Trace.Off, {
// tslint:disable-next-line:no-any
log: (message: any, data?: string) => this.logger.info(`[${options.serverName}: ${childProcess.pid}] ${message}` + (typeof data === 'string' ? ' ' + data : ''))
});
return connection;
}
private createConnection(reader, writer) {
let msgConnection = createMessageConnection(reader, writer);
let result: IConnection = {
listen: (): void => msgConnection.listen(),
onRun: (handler) => msgConnection.onRequest(RunRequest.type, handler),
testSuiteUpdate: (params: TestSuiteUpdateParams) => msgConnection.sendNotification(TestSuiteUpdateNotification.type, params),
//dataOutput: (params: DataOutputParams) => msgConnection.sendNotification(DataOutputNotification.type, params)
}
return result;
}
const server = net.createServer(socket => {
this.initialized = false;
server.close();
this.currentServer = null;
socket.on('close', () => this.onSocketClosed());
this.eventEmitter.off('changePort', server.close);
this.logger.info('langserver connection established on port ' + this.targetPort);
const reader = new SocketMessageReader(socket);
const writer = new SocketMessageWriter(socket);
this.clientConnection = createMessageConnection(reader, writer, this.logger);
this.registerOnNotificationHandler(this.clientConnection);
this.clientConnection.listen();
this.eventEmitter.emit('connect');
});
server.on('error', this.setError);
const server = net.createServer(socket => {
this.initialized = false;
server.close();
this.eventEmitter.emit('connect');
socket.on('close', () => this.onSocketClosed());
this.logger.info('langserver connection established on port ' + this.targetPort);
const reader = new SocketMessageReader(socket);
const writer = new SocketMessageWriter(socket);
this.clientConnection = createMessageConnection(reader, writer, this.logger);
this.registerOnNotificationHandler(this.clientConnection);
this.clientConnection.listen();
res(this.clientConnection);
});
server.on('error', rej);
export function createSocketConnection(socket: Socket, logger: Logger): MessageConnection {
const messageReader = new SocketMessageReader(socket);
const messageWriter = new SocketMessageWriter(socket);
const connection = createMessageConnection(messageReader, messageWriter, logger);
connection.trace(Trace.Off, logger);
connection.onClose(() => connection.dispose());
return connection;
}