當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。