UNPKG

2.21 kBMarkdownView Raw
1# VSCode JSON RPC
2
3[![NPM Version](https://img.shields.io/npm/v/vscode-jsonrpc.svg)](https://npmjs.org/package/vscode-jsonrpc)
4[![NPM Downloads](https://img.shields.io/npm/dm/vscode-jsonrpc.svg)](https://npmjs.org/package/vscode-jsonrpc)
5[![Build Status](https://travis-ci.org/Microsoft/vscode-languageserver-node.svg?branch=master)](https://travis-ci.org/Microsoft/vscode-languageserver-node)
6
7This npm module implements the base messaging protocol spoken between a VSCode language server and a VSCode language client.
8
9The npm module can also be used standalone to establish a [JSON-RPC](http://www.jsonrpc.org/) channel between
10a client and a server. Below an example how to setup a JSON-RPC connection. First the client side.
11
12```ts
13import * as cp from 'child_process';
14import * as rpc from 'vscode-jsonrpc/node';
15
16let childProcess = cp.spawn(...);
17
18// Use stdin and stdout for communication:
19let connection = rpc.createMessageConnection(
20 new rpc.StreamMessageReader(childProcess.stdout),
21 new rpc.StreamMessageWriter(childProcess.stdin));
22
23let notification = new rpc.NotificationType<string, void>('testNotification');
24
25connection.listen();
26
27connection.sendNotification(notification, 'Hello World');
28```
29
30The server side looks very symmetrical:
31
32```ts
33import * as rpc from 'vscode-jsonrpc/node';
34
35
36let connection = rpc.createMessageConnection(
37 new rpc.StreamMessageReader(process.stdin),
38 new rpc.StreamMessageWriter(process.stdout));
39
40let notification = new rpc.NotificationType<string, void>('testNotification');
41connection.onNotification(notification, (param: string) => {
42 console.log(param); // This prints Hello World
43});
44
45connection.listen();
46```
47
48# History
49
50### 5.0.0
51
52- add progress support
53- move JS target to ES2017
54
55### 4.0.0
56
57- move JS target to ES6.
58
59### 3.0.0:
60
61- converted the NPM module to use TypeScript 2.0.3.
62- added strict null support.
63- support for passing more than one parameter to a request or notification.
64- Breaking changes:
65 - due to the use of TypeScript 2.0.3 and differences in d.ts generation users of the new version need to move to
66 TypeScript 2.0.3 as well.
67
68## License
69[MIT](https://github.com/Microsoft/vscode-languageserver-node/blob/master/License.txt)