How to use vscode-jsonrpc - 10 common examples

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 gfrancischini / vscode-unit-test / src / mochaTestLanguageServer / testRunner / client.ts View on Github external
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;
    }
github eclipse-theia / theia / packages / core / src / node / messaging / ipc-bootstrap.ts View on Github external
* 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-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-bootstrap.ts View on Github external
* Licenses when the conditions for such availability set forth in the Eclipse
 * 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 yitzchak / dicy / packages / server / spec / Server_spec.ts View on Github external
'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()
  })
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 facebookarchive / flow-language-server / packages / flow-language-server / src / pkg / nuclide-flow-rpc / lib / FlowIDEConnection.js View on Github external
constructor(process: child_process$ChildProcess, fileCache: FileCache) {
    this._disposables = new UniversalDisposable();
    this._fileCache = fileCache;
    this._ideProcess = process;
    this._ideProcess.stderr.pipe(
      through(msg => {
        getLogger('nuclide-flow-rpc').info(
          'Flow IDE process stderr: ',
          msg.toString(),
        );
      }),
    );
    this._connection = rpc.createMessageConnection(
      new SafeStreamMessageReader(this._ideProcess.stdout),
      new rpc.StreamMessageWriter(this._ideProcess.stdin),
    );
    this._connection.listen();

    this._ideProcess.on('exit', () => this.dispose());
    this._ideProcess.on('close', () => this.dispose());

    const diagnostics = Observable.fromEventPattern(
      handler => {
        this._connection.onNotification(
          NOTIFICATION_METHOD_NAME,
          (errors: FlowStatusOutput) => {
            handler(errors);
          },
        );
      },
      // no-op: vscode-jsonrpc offers no way to unsubscribe
github onivim / oni / browser / src / Plugins / Api / LanguageClient / LanguageClient.ts View on Github external
this._process.on("close", (code: number, signal: string) => {
            Log.warn(`[LANGUAGE CLIENT]: Process closed with exit code ${code} and signal ${signal}`)
        })

        const logFunc = (msg: any) => {
            Log.debug(`[LANGUAGE CLIENT - DEBUG] ${msg}`)
        }
        const errFunc = (msg: any) => {
            Log.error(`[LANGUAGE CLIENT - ERROR]: ${msg}`)
            this._statusBar.setStatus(LanguageClientState.Error)
        }
        this._process.stderr.on("data", (this._startOptions.stderrAsLog) ? logFunc : errFunc)

        this._connection = rpc.createMessageConnection(
            (new rpc.StreamMessageReader(this._process.stdout)) as any,
            (new rpc.StreamMessageWriter(this._process.stdin)) as any,
            new LanguageClientLogger())

        this._currentOpenDocumentPath = null
        this._serverCapabilities = null

        this._connection.onNotification(Helpers.ProtocolConstants.Window.LogMessage, (args) => {
            Log.info(JSON.stringify(args))
        })

        this._connection.onNotification(Helpers.ProtocolConstants.Telemetry.Event, (args) => {
            Log.info(JSON.stringify(args))
        })

        this._connection.onNotification(Helpers.ProtocolConstants.Window.ShowMessage, (args) => {
            // TODO: Need alternate paradigm for showing a message
            alert(args)
github onivim / oni / browser / src / Services / Language / LanguageClientProcess.ts View on Github external
throw new Error("Unable to start language server process")
        }

        Log.info(`[LanguageClientProcess]: Started process ${this._process.pid}`)

        this._process.stderr.on("data", msg => {
            Log.info(`[LANGUAGE CLIENT - STDERR]: ${msg}`)
            // this._statusBar.setStatus(LanguageClientState.Error)
        })

        this._lastWorkingDirectory = workingDirectory
        this._lastRootPath = rootPath

        this._connection = rpc.createMessageConnection(
            new rpc.StreamMessageReader(this._process.stdout) as any,
            new rpc.StreamMessageWriter(this._process.stdin) as any,
            new LanguageClientLogger(),
        )

        this._onConnectionChangedEvent.dispatch(this._connection)

        this._connection.listen()

        const NoDynamicRegistration = {
            dynamicRegistration: false,
        }

        const SupportedMarkup = ["plaintext"]

        const oniLanguageClientParams = {
            clientName: "oni",
            rootPath,
github ballerina-platform / ballerina-lang / composer / lang-service / src / server.ts View on Github external
function createLSConnection(ballerinaHome: string) : LangServerProcessConnection {
    const childProcess = createServer(ballerinaHome);
    childProcess.on('error', (err) => {
        // log('Error while starting LS', err);
    });
    const reader = new StreamMessageReader(childProcess.stdout);
    const writer = new StreamMessageWriter(childProcess.stdin);
    const messageConntection = createMessageConnection(reader, writer);
    const errorHandler: ConnectionErrorHandler = (err, msg, count) => {
       // log('Error while starting LS', err);
    };
    const closeHandler: ConnectionCloseHandler = () => {
       // log('LS Connection closed');
    };
    const lsConnection = createConnection(messageConntection, errorHandler, closeHandler);
    return {
        childProcess,
        lsConnection
    }
}