| 99 | } |
| 100 | |
| 101 | private async handleLine(line: string) { |
| 102 | let msg: { messageType: string; messageId: string; data?: any }; |
| 103 | try { |
| 104 | msg = JSON.parse(line); |
| 105 | } catch { |
| 106 | return; // not JSON, ignore |
| 107 | } |
| 108 | |
| 109 | const handler = this.handlers[msg.messageType]; |
| 110 | if (!handler) return; // not an IDE message, let CoreBinaryMessenger handle it |
| 111 | |
| 112 | try { |
| 113 | const result = await handler(msg.data); |
| 114 | this.respond(msg.messageType, result, msg.messageId); |
| 115 | } catch (e) { |
| 116 | this.respond(msg.messageType, undefined, msg.messageId); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | private respond(messageType: string, data: any, messageId: string) { |
| 121 | const response = JSON.stringify({ messageType, data, messageId }); |