@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.
@@ -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.set(method, handler);
80
+ const handlers = this.notificationHandlers.get(method) ?? [];
81
+ handlers.push(handler);
82
+ this.notificationHandlers.set(method, handlers);
81
83
  return {
82
- dispose: () => this.notificationHandlers.delete(method),
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 handler = this.notificationHandlers.get(notification.method);
143
- if (!handler)
151
+ const handlers = this.notificationHandlers.get(notification.method);
152
+ if (!handlers?.length)
144
153
  return;
145
- try {
146
- handler(notification.params);
147
- }
148
- catch (error) {
149
- console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@typerighter/rpc-client",
4
- "version": "0.26.0",
4
+ "version": "0.27.0",
5
5
  "description": "JSON-RPC client for Typedown over TCP/stdio.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -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.set(method, handler);
124
+ const handlers = this.notificationHandlers.get(method) ?? [];
125
+ handlers.push(handler);
126
+ this.notificationHandlers.set(method, handlers);
125
127
  return {
126
- dispose: () => this.notificationHandlers.delete(method),
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 handler = this.notificationHandlers.get(notification.method);
204
+ const handlers = this.notificationHandlers.get(notification.method);
197
205
 
198
- if (!handler) return;
206
+ if (!handlers?.length) return;
199
207
 
200
- try {
201
- handler(notification.params);
202
- } catch (error) {
203
- console.error(`[jsonrpc] Notification handler for '${notification.method}' threw:`, error);
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