当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vscode-jsonrpc.createMessageConnection函数代码示例

本文整理汇总了TypeScript中vscode-jsonrpc.createMessageConnection函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createMessageConnection函数的具体用法?TypeScript createMessageConnection怎么用?TypeScript createMessageConnection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createMessageConnection函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: connect

async function connect() {
  let childProcess = cp.spawn("dotnet", [`${__dirname}/../../../core/AutoRest/bin/netcoreapp1.0/AutoRest.dll`, "--server"]);

  // Use stdin and stdout for communication:
  let connection = rpc.createMessageConnection(
    new rpc.StreamMessageReader(childProcess.stdout),
    new rpc.StreamMessageWriter(childProcess.stdin), console);

  // host interface
  connection.onNotification(new rpc.NotificationType4<string, string, string, any, void>('WriteFile'), (sessionId: string, filename: string, content: string, sourcemap: any) => {
    console.log(`Saving File ${sessionId}, ${filename}`);
  });

  connection.onNotification(new rpc.NotificationType3<string, any, any, void>('Message'), (sessionId: string, details: any, sourcemap: any) => {
    console.log(`You have posted message ${sessionId}, ${details}`);
  });

  connection.onRequest(new rpc.RequestType2<string, string, string, void, void>('ReadFile'), (sessionId: string, filename: string) => {
    return `You asked for the file ${filename} in the session ${sessionId}`;
  });

  connection.onRequest(new rpc.RequestType2<string, string, string, void, void>('GetValue'), (sessionId: string, key: string) => {
    return `You asked for the value ${key} in the session ${sessionId}`;
  });

  connection.onRequest(new rpc.RequestType2<string,string|undefined, Array<string>, void, void>('ListInputs'), (sessionId: string) => {
    return ["a.txt", "b.txt"];
  });

  // extension interface
  let EnumeratePlugins = new rpc.RequestType0<Array<string>, void, void>('GetPluginNames');
  let Process = (plugin: string, session: string) => connection.sendRequest(new rpc.RequestType2<string, string, boolean, void, void>('Process'), plugin, session);
  let Shutdown = () => connection.sendNotification(new rpc.NotificationType0<void>('Shutdown'));

  childProcess.stderr.pipe(process.stdout);
  connection.listen();

  console.log('before enumerate')
  let values = await connection.sendRequest(EnumeratePlugins);
  for (let each of values) {
    console.log(each);
  }
  console.log('after enumerate')

  console.log('calling process')
  let result = await Process("Modeler", "session1");
  console.log(`done process: ${result} `)

  Shutdown();

  // wait for shutdown!
  await new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, 200);
  });

}
开发者ID:anuchandy,项目名称:autorest,代码行数:58,代码来源:test-rpc.ts

示例2: waitForServer

  return waitForServer().then(socket => {
    let connection = rpc.createMessageConnection(
      new rpc.StreamMessageReader(socket),
      new rpc.StreamMessageWriter(socket))

    connection.listen()

    connection.onNotification("window/logMessage", (params) => {
      log.appendLine(`<<< [${messageTypeToString(params.type)}] ${params.message}`)
    })

    return connection
  })
开发者ID:xeno-by,项目名称:dotty,代码行数:13,代码来源:sbt-server.ts

示例3:

export const start = (opts?: cp.SpawnOptions) => {
  opts = opts || {
    env: { ...process.env, MERLIN_LOG: "-" }
  };
  let childProcess = cp.spawn(serverPath, [], opts);

  let connection = rpc.createMessageConnection(
    new rpc.StreamMessageReader(childProcess.stdout),
    new rpc.StreamMessageWriter(childProcess.stdin)
  );

  if (process.env.MERLIN_LSP_TEST_DEBUG) {
    childProcess.stderr.on("data", d => {
      console.log("Received data: " + d);
    });
  }

  connection.listen();

  return connection as LanguageServer;
};
开发者ID:the-lambda-church,项目名称:merlin,代码行数:21,代码来源:LanguageServer.ts

示例4:

  process.exit(1)
}

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<P, RO>(
  type: lsp.NotificationType<P, RO>,
  handler: lsp.NotificationHandler<P>
): void {
  return connection.onNotification(type, handler)
}

OnNotification(lsp.ShowMessageNotification.type, params => {
  if (debug_connection) {
    console.group('notification', params.type)
    console.log(params.message)
开发者ID:Franciman,项目名称:kakoune-languageclient,代码行数:32,代码来源:main.ts


注:本文中的vscode-jsonrpc.createMessageConnection函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。