How to use the vscode-jsonrpc.StreamMessageWriter 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 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
    }
}
github danr / kakoune-languageclient / src / main.ts View on Github external
}

const kak = Kak.Init(Splice, {
  session,
  debug,
})

console.log('spawning')
const child = cp.spawn(server, args, {
  detached: true,
  stdio: 'pipe',
})

const connection = rpc.createMessageConnection(
  new rpc.StreamMessageReader(child.stdout),
  new rpc.StreamMessageWriter(child.stdin)
)

console.log('running')

function OnNotification(
  type: lsp.NotificationType,
  handler: lsp.NotificationHandler<p>
): void {
  return connection.onNotification(type, handler)
}

OnNotification(lsp.ShowMessageNotification.type, params =&gt; {
  if (debug_connection) {
    console.group('notification', params.type)
    console.log(params.message)
    console.groupEnd()</p>
github yitzchak / dicy / packages / server / spec / Server_spec.ts View on Github external
beforeEach(() => {
    const input: PassThrough = new PassThrough()
    const output: PassThrough = new PassThrough()
    const clientTransport: [rpc.MessageReader, rpc.MessageWriter] =
      [new rpc.StreamMessageReader(output), new rpc.StreamMessageWriter(input)]
    const serverTransport: [rpc.MessageReader, rpc.MessageWriter] =
      [new rpc.StreamMessageReader(input), new rpc.StreamMessageWriter(output)]

    cache = jasmine.createSpyObj('MockCache', [
      'clear',
      'clearAll',
      'destroy',
      'getTargets',
      'kill',
      'killAll',
      'on',
      'run',
      'setDirectoryOptions',
      'setInstanceOptions',
      'setProjectOptions',
      'setUserOptions'
    ])
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[]) => { },
      info: (..._args: any[]) => { },
      error: (...args: any[]) => {
        this.logger.error(args);
      },
    });
  }
github DonJayamanne / pythonVSCode / src / client / common / process / pythonDaemonPool.ts View on Github external
protected createConnection(proc: ChildProcess) {
        return createMessageConnection(new StreamMessageReader(proc.stdout), new StreamMessageWriter(proc.stdin));
    }
    @traceDecorators.error('Failed to create daemon')
github TypeFox / vscode-ws-jsonrpc / src / server / launch.ts View on Github external
export function createStreamConnection(outStream: stream.Readable, inStream: stream.Writable, onDispose: () => void): IConnection {
    const reader = new StreamMessageReader(outStream);
    const writer = new StreamMessageWriter(inStream);
    return createConnection(reader, writer, onDispose);
}