How to use the vscode-jsonrpc.IPCMessageWriter function in vscode-jsonrpc

To help you get started, we’ve selected a few vscode-jsonrpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / core / src / node / messaging / ipc-bootstrap.ts View on Github external
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * 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);
github eclipse-theia / theia / packages / core / src / node / messaging / ipc-connection-provider.ts View on Github external
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;
    }
github angular / vscode-ng-language-service / integration / lsp / smoke_spec.ts View on Github external
async function send(request: RequestMessage|NotificationMessage) {
    const writer = new IPCMessageWriter(server);
    writer.write(request);
    if (isNotificationMessage(request)) {
      return Promise.resolve(null);  // No response for notification message
    }
    return new Promise((resolve, reject) => {
      responseEmitter.once('response', (response: ResponseMessage) => {
        if (response.error) {
          reject(new Error(response.error.message));
        } else {
          resolve(response);
        }
      });
    });
  }
github sourcegraph / sourcegraph-typescript / src / server / language-server.ts View on Github external
}
    logger.log('Spawning language server')
    const serverProcess = fork(TYPESCRIPT_LANGSERVER_JS_BIN, args, {
        env: {
            ...process.env,
            XDG_CACHE_HOME: tsserverCacheDir,
        },
        stdio: ['ipc', 'inherit'],
        execArgv: [],
    })
    disposables.add({ dispose: () => serverProcess.kill() })
    // Log language server STDERR output
    const languageServerLogger = new PrefixedLogger(logger, 'langserver')
    serverProcess.stderr!.on('data', chunk => languageServerLogger.log(chunk + ''))
    const languageServerReader = new IPCMessageReader(serverProcess)
    const languageServerWriter = new IPCMessageWriter(serverProcess)
    disposables.add(languageServerWriter)
    const connection = createMessageConnection(languageServerReader, languageServerWriter, logger)
    disposables.add(connection)
    connection.listen()

    // Forward log messages from the language server to the browser
    const dispatcher = createDispatcher(
        {
            reader: languageServerReader,
            writer: languageServerWriter,
        },
        {
            tracer,
            logger,
            tags: {
                connectionId,
github atom / atom-languageclient / lib / auto-languageclient.ts View on Github external
private createRpcConnection(process: LanguageServerProcess): rpc.MessageConnection {
    let reader: rpc.MessageReader;
    let writer: rpc.MessageWriter;
    const connectionType = this.getConnectionType();
    switch (connectionType) {
      case 'ipc':
        reader = new rpc.IPCMessageReader(process as cp.ChildProcess);
        writer = new rpc.IPCMessageWriter(process as cp.ChildProcess);
        break;
      case 'socket':
        reader = new rpc.SocketMessageReader(this.socket);
        writer = new rpc.SocketMessageWriter(this.socket);
        break;
      case 'stdio':
        reader = new rpc.StreamMessageReader(process.stdout);
        writer = new rpc.StreamMessageWriter(process.stdin);
        break;
      default:
        return Utils.assertUnreachable(connectionType);
    }

    return rpc.createMessageConnection(reader, writer, {
      log: (..._args: any[]) => { },
      warn: (..._args: any[]) => { },
github yitzchak / dicy / packages / server / src / main.ts View on Github external
})
  .option('stdio', {
    conflicts: ['socket', 'nodeIpc', 'pipe'],
    describe: 'use stdio',
    default: undefined,
    type: 'boolean'
  })
  .help()
  .argv

let transport: [rpc.MessageReader, rpc.MessageWriter] | undefined

if (argv.stdio) {
  transport = [new rpc.StreamMessageReader(process.stdin), new rpc.StreamMessageWriter(process.stdout)]
} else if (argv.nodeIpc) {
  transport = [new rpc.IPCMessageReader(process), new rpc.IPCMessageWriter(process)]
} else if (argv.port) {
  transport = rpc.createServerSocketTransport(argv.port as number)
} else if (argv.pipe) {
  transport = rpc.createServerPipeTransport(argv.pipe)
} else {
  yargs.showHelp()
}

if (transport) {
  const server: Server = new Server(transport, new DiCy())
  server.start()
}