Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (!output) {
throw new Error("Connection output stream is not set. " + commandLineMessage);
}
// Backwards compatibility
if (Is.func(input.read) && Is.func(input.on)) {
let inputStream = input;
inputStream.on('end', () => {
process.exit(shutdownReceived ? 0 : 1);
});
inputStream.on('close', () => {
process.exit(shutdownReceived ? 0 : 1);
});
}
const logger = (factories && factories.console ? new (factories.console(ConnectionLogger))() : new ConnectionLogger());
const connection = vscode_languageserver_protocol_1.createProtocolConnection(input, output, logger, strategy);
logger.rawAttach(connection);
const tracer = (factories && factories.tracer ? new (factories.tracer(TracerImpl))() : new TracerImpl());
const telemetry = (factories && factories.telemetry ? new (factories.telemetry(TelemetryImpl))() : new TelemetryImpl());
const client = (factories && factories.client ? new (factories.client(RemoteClientImpl))() : new RemoteClientImpl());
const remoteWindow = (factories && factories.window ? new (factories.window(RemoteWindowImpl))() : new RemoteWindowImpl());
const workspace = (factories && factories.workspace ? new (factories.workspace(RemoteWorkspaceImpl))() : new RemoteWorkspaceImpl());
const allRemotes = [logger, tracer, telemetry, client, remoteWindow, workspace];
function asThenable(value) {
if (Is.thenable(value)) {
return value;
}
else {
return Promise.resolve(value);
}
}
let shutdownHandler = undefined;
export const getStdioConnection = (pathToServer: string) => {
const cp = spawn('ts-node', [
'--compilerOptions',
JSON.stringify({ module: 'commonjs' }),
pathToServer,
'--stdio',
]);
const connection = createProtocolConnection(
new StreamMessageReader(cp.stdout),
new StreamMessageWriter(cp.stdin),
{
log: console.log,
info: console.info,
error: console.error,
warn: console.warn,
}
);
return { child_process: cp, connection };
};
it('performs LSP initialization via IPC', (done) => {
cp = spawn(
'ts-node',
[
'--compilerOptions',
JSON.stringify({ module: 'commonjs' }),
pathToServer,
'--node-ipc',
],
{
stdio: [null, null, null, 'ipc'],
}
);
const connection = createProtocolConnection(
new IPCMessageReader(cp),
new IPCMessageWriter(cp),
null
);
testInitHandshake(connection, done);
});
it('performs LSP initialization via socket', async (done) => {
pipeTransport.onConnected().then(([messageReader, messageWriter]) => {
const connection = createProtocolConnection(
messageReader,
messageWriter,
null
);
testInitHandshake(connection, done);
})
);
function createConnection(reader, writer, restartLanguageClient, stopLanguageClient) {
var logger = new Logger(),
actionController = new ActionController(),
connection = protocol.createProtocolConnection(reader, writer, logger),
errorHandler = _getOnErrorHandler(actionController, stopLanguageClient),
closeHandler = _getOnCloseHandler(connection, actionController, restartLanguageClient);
connection.onError(errorHandler);
connection.onClose(closeHandler);
return connection;
}