@typerighter/rpc-client 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/client.js +20 -9
- package/package.json +1 -1
- package/src/core/client.ts +19 -9
package/dist/core/client.js
CHANGED
|
@@ -77,9 +77,18 @@ export class JsonRpcClient {
|
|
|
77
77
|
}
|
|
78
78
|
// https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L557
|
|
79
79
|
onNotification(method, handler) {
|
|
80
|
-
this.notificationHandlers.
|
|
80
|
+
const handlers = this.notificationHandlers.get(method) ?? [];
|
|
81
|
+
handlers.push(handler);
|
|
82
|
+
this.notificationHandlers.set(method, handlers);
|
|
81
83
|
return {
|
|
82
|
-
dispose: () =>
|
|
84
|
+
dispose: () => {
|
|
85
|
+
const list = this.notificationHandlers.get(method);
|
|
86
|
+
if (list) {
|
|
87
|
+
const idx = list.indexOf(handler);
|
|
88
|
+
if (idx !== -1)
|
|
89
|
+
list.splice(idx, 1);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
83
92
|
};
|
|
84
93
|
}
|
|
85
94
|
// Accumulate chunk and parse as many complete messages as possible
|
|
@@ -139,14 +148,16 @@ export class JsonRpcClient {
|
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
handleNotification(notification) {
|
|
142
|
-
const
|
|
143
|
-
if (!
|
|
151
|
+
const handlers = this.notificationHandlers.get(notification.method);
|
|
152
|
+
if (!handlers?.length)
|
|
144
153
|
return;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
154
|
+
for (const handler of handlers) {
|
|
155
|
+
try {
|
|
156
|
+
handler(notification.params);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
|
|
160
|
+
}
|
|
150
161
|
}
|
|
151
162
|
}
|
|
152
163
|
// Cleanup
|
package/package.json
CHANGED
package/src/core/client.ts
CHANGED
|
@@ -47,7 +47,7 @@ export class JsonRpcClient implements MessageConnection {
|
|
|
47
47
|
// Request/response matching
|
|
48
48
|
private sequenceNumber = 1;
|
|
49
49
|
private responsePromises = new Map<number, PendingRequest>();
|
|
50
|
-
private notificationHandlers = new Map<string, (params: unknown) => void
|
|
50
|
+
private notificationHandlers = new Map<string, Array<(params: unknown) => void>>();
|
|
51
51
|
|
|
52
52
|
// Inbound buffer, raw chunks to avoid corrupting multi-byte UTF-8
|
|
53
53
|
private chunks: Buffer[] = [];
|
|
@@ -121,9 +121,17 @@ export class JsonRpcClient implements MessageConnection {
|
|
|
121
121
|
|
|
122
122
|
// https://github.com/microsoft/vscode-languageserver-node/blob/5010cdf9822e1038a30ee7eb6ee5d7aaa79acc4a/jsonrpc/src/common/connection.ts#L557
|
|
123
123
|
onNotification (method: string, handler: (params: any) => void): Disposable {
|
|
124
|
-
this.notificationHandlers.
|
|
124
|
+
const handlers = this.notificationHandlers.get(method) ?? [];
|
|
125
|
+
handlers.push(handler);
|
|
126
|
+
this.notificationHandlers.set(method, handlers);
|
|
125
127
|
return {
|
|
126
|
-
dispose: () =>
|
|
128
|
+
dispose: () => {
|
|
129
|
+
const list = this.notificationHandlers.get(method);
|
|
130
|
+
if (list) {
|
|
131
|
+
const idx = list.indexOf(handler);
|
|
132
|
+
if (idx !== -1) list.splice(idx, 1);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
127
135
|
};
|
|
128
136
|
}
|
|
129
137
|
|
|
@@ -193,14 +201,16 @@ export class JsonRpcClient implements MessageConnection {
|
|
|
193
201
|
}
|
|
194
202
|
|
|
195
203
|
private handleNotification (notification: NotificationMessage): void {
|
|
196
|
-
const
|
|
204
|
+
const handlers = this.notificationHandlers.get(notification.method);
|
|
197
205
|
|
|
198
|
-
if (!
|
|
206
|
+
if (!handlers?.length) return;
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
208
|
+
for (const handler of handlers) {
|
|
209
|
+
try {
|
|
210
|
+
handler(notification.params);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
|
|
213
|
+
}
|
|
204
214
|
}
|
|
205
215
|
}
|
|
206
216
|
|