MCPcopy
hub / github.com/microsoft/vscode / wrapStream

Function wrapStream

src/bootstrap-fork.ts:118–137  ·  view source on GitHub ↗

* Wraps process.stderr/stdout.write() so that it is transmitted to the * renderer or CLI. It both calls through to the original method as well * as to console.log with complete lines so that they're made available * to the debugger/CLI.

(streamName: 'stdout' | 'stderr', severity: 'log' | 'warn' | 'error')

Source from the content-addressed store, hash-verified

116 * to the debugger/CLI.
117 */
118 function wrapStream(streamName: 'stdout' | 'stderr', severity: 'log' | 'warn' | 'error'): void {
119 const stream = process[streamName];
120 const original = stream.write;
121
122 let buf = '';
123
124 Object.defineProperty(stream, 'write', {
125 set: () => { },
126 get: () => (chunk: string | Buffer | Uint8Array, encoding: BufferEncoding | undefined, callback: ((err?: Error | null) => void) | undefined) => {
127 buf += chunk.toString(encoding);
128 const eol = buf.length > MAX_STREAM_BUFFER_LENGTH ? buf.length : buf.lastIndexOf('\n');
129 if (eol !== -1) {
130 console[severity](buf.slice(0, eol));
131 buf = buf.slice(eol + 1);
132 }
133
134 original.call(stream, chunk, encoding, callback);
135 },
136 });
137 }
138
139 // Pass console logging to the outside so that we have it in the main side if told so
140 if (process.env['VSCODE_VERBOSE_LOGGING'] === 'true') {

Callers 1

pipeLoggingToParentFunction · 0.85

Calls 3

toStringMethod · 0.65
sliceMethod · 0.65
callMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…