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 |
|
7 | This npm module implements the base messaging protocol spoken between a VSCode language server and a VSCode language client.
|
8 |
|
9 | The npm module can also be used standalone to establish a [JSON-RPC](http://www.jsonrpc.org/) channel between
|
10 | a client and a server. Below an example how to setup a JSON-RPC connection. First the client side.
|
11 |
|
12 | ```ts
|
13 | import * as cp from 'child_process';
|
14 | import * as rpc from 'vscode-jsonrpc/node';
|
15 |
|
16 | let childProcess = cp.spawn(...);
|
17 |
|
18 | // Use stdin and stdout for communication:
|
19 | let connection = rpc.createMessageConnection(
|
20 | new rpc.StreamMessageReader(childProcess.stdout),
|
21 | new rpc.StreamMessageWriter(childProcess.stdin));
|
22 |
|
23 | let notification = new rpc.NotificationType<string, void>('testNotification');
|
24 |
|
25 | connection.listen();
|
26 |
|
27 | connection.sendNotification(notification, 'Hello World');
|
28 | ```
|
29 |
|
30 | The server side looks very symmetrical:
|
31 |
|
32 | ```ts
|
33 | import * as rpc from 'vscode-jsonrpc/node';
|
34 |
|
35 |
|
36 | let connection = rpc.createMessageConnection(
|
37 | new rpc.StreamMessageReader(process.stdin),
|
38 | new rpc.StreamMessageWriter(process.stdout));
|
39 |
|
40 | let notification = new rpc.NotificationType<string, void>('testNotification');
|
41 | connection.onNotification(notification, (param: string) => {
|
42 | console.log(param); // This prints Hello World
|
43 | });
|
44 |
|
45 | connection.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)
|