本文整理匯總了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);
});
}
示例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
})
示例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;
};
示例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)