MCPcopy Index your code
hub / github.com/microsoft/vscode-languageserver-node / IPCMessageWriter

Class IPCMessageWriter

jsonrpc/src/messageWriter.ts:108–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108export class IPCMessageWriter extends AbstractMessageWriter implements MessageWriter {
109
110 private process: NodeJS.Process | ChildProcess;
111 private queue: Message[];
112 private sending: boolean;
113 private errorCount: number;
114
115 public constructor(process: NodeJS.Process | ChildProcess) {
116 super();
117 this.process = process;
118 this.errorCount = 0;
119 this.queue = [];
120 this.sending = false;
121 let eventEmitter: NodeJS.EventEmitter = this.process;
122 eventEmitter.on('error', (error: any) => this.fireError(error));
123 eventEmitter.on('close', () => this.fireClose);
124 }
125
126 public write(msg: Message): void {
127 if (!this.sending && this.queue.length === 0) {
128 // See https://github.com/nodejs/node/issues/7657
129 this.doWriteMessage(msg);
130 } else {
131 this.queue.push(msg);
132 }
133 }
134
135 public doWriteMessage(msg: Message): void {
136 try {
137 if (this.process.send) {
138 this.sending = true;
139 (this.process.send as Function)(msg, undefined, undefined, (error: any) => {
140 this.sending = false;
141 if (error) {
142 this.errorCount++;
143 this.fireError(error, msg, this.errorCount);
144 } else {
145 this.errorCount = 0;
146 }
147 if (this.queue.length > 0) {
148 this.doWriteMessage(this.queue.shift()!);
149 }
150 });
151 }
152 } catch (error) {
153 this.errorCount++;
154 this.fireError(error, msg, this.errorCount);
155 }
156
157 }
158 }
159
160 export class SocketMessageWriter extends AbstractMessageWriter implements MessageWriter {
161

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected