in server/src/node/main.ts [188:261]
function _createConnection<PConsole = _, PTracer = _, PTelemetry = _, PClient = _, PWindow = _, PWorkspace = _, PLanguages = _, PNotebooks = _>(
input?: NodeJS.ReadableStream | MessageReader, output?: NodeJS.WritableStream | MessageWriter,
options?: ConnectionStrategy | ConnectionOptions,
factories?: Features<PConsole, PTracer, PTelemetry, PClient, PWindow, PWorkspace, PLanguages, PNotebooks>,
): _Connection<PConsole, PTracer, PTelemetry, PClient, PWindow, PWorkspace, PLanguages, PNotebooks> {
if (!input && !output && process.argv.length > 2) {
let port: number | undefined = void 0;
let pipeName: string | undefined = void 0;
let argv = process.argv.slice(2);
for (let i = 0; i < argv.length; i++) {
let arg = argv[i];
if (arg === '--node-ipc') {
input = new IPCMessageReader(process);
output = new IPCMessageWriter(process);
break;
} else if (arg === '--stdio') {
input = process.stdin;
output = process.stdout;
break;
} else if (arg === '--socket') {
port = parseInt(argv[i + 1]);
break;
} else if (arg === '--pipe') {
pipeName = argv[i + 1];
break;
}
else {
var args = arg.split('=');
if (args[0] === '--socket') {
port = parseInt(args[1]);
break;
} else if (args[0] === '--pipe') {
pipeName = args[1];
break;
}
}
}
if (port) {
let transport = createServerSocketTransport(port);
input = transport[0];
output = transport[1];
} else if (pipeName) {
let transport = createServerPipeTransport(pipeName);
input = transport[0];
output = transport[1];
}
}
var commandLineMessage = 'Use arguments of createConnection or set command line parameters: \'--node-ipc\', \'--stdio\' or \'--socket={number}\'';
if (!input) {
throw new Error('Connection input stream is not set. ' + commandLineMessage);
}
if (!output) {
throw new Error('Connection output stream is not set. ' + commandLineMessage);
}
// Backwards compatibility
if (Is.func((input as NodeJS.ReadableStream).read) && Is.func((input as NodeJS.ReadableStream).on)) {
let inputStream = <NodeJS.ReadableStream>input;
inputStream.on('end', () => {
endProtocolConnection();
process.exit(_shutdownReceived ? 0 : 1);
});
inputStream.on('close', () => {
endProtocolConnection();
process.exit(_shutdownReceived ? 0 : 1);
});
}
const connectionFactory = (logger: Logger): ProtocolConnection => {
const result = createProtocolConnection(input as any, output as any, logger, options);
return result;
};
return createCommonConnection(connectionFactory, watchDog, factories);
}