Skip to content

Commit bf757ca

Browse files
authored
Windows: piping from another process fails to update editor contents (fix microsoft#148952) (microsoft#151401)
1 parent 361692e commit bf757ca

File tree

1 file changed

+13
-10
lines changed
  • src/vs/platform/environment/node

1 file changed

+13
-10
lines changed

src/vs/platform/environment/node/stdin.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { createWriteStream } from 'fs';
76
import { tmpdir } from 'os';
7+
import { Queue } from 'vs/base/common/async';
88
import { randomPath } from 'vs/base/common/extpath';
9+
import { Promises } from 'vs/base/node/pfs';
910
import { resolveTerminalEncoding } from 'vs/base/node/terminalEncoding';
1011

1112
export function hasStdinWithoutTty() {
@@ -38,10 +39,6 @@ export function getStdinFilePath(): string {
3839
}
3940

4041
export async function readFromStdin(targetPath: string, verbose: boolean): Promise<void> {
41-
42-
// open tmp file for writing
43-
const stdinFileStream = createWriteStream(targetPath);
44-
4542
let encoding = await resolveTerminalEncoding(verbose);
4643

4744
const iconv = await import('@vscode/iconv-lite-umd');
@@ -51,15 +48,21 @@ export async function readFromStdin(targetPath: string, verbose: boolean): Promi
5148
}
5249

5350
// Pipe into tmp file using terminals encoding
51+
// Use a `Queue` to be able to use `appendFile`
52+
// which helps file watchers to be aware of the
53+
// changes because each append closes the underlying
54+
// file descriptor.
55+
// (https://github.com/microsoft/vscode/issues/148952)
5456
const decoder = iconv.getDecoder(encoding);
55-
process.stdin.on('data', chunk => stdinFileStream.write(decoder.write(chunk)));
57+
const appendFileQueue = new Queue();
58+
process.stdin.on('data', chunk => {
59+
const chunkStr = decoder.write(chunk);
60+
appendFileQueue.queue(() => Promises.appendFile(targetPath, chunkStr));
61+
});
5662
process.stdin.on('end', () => {
5763
const end = decoder.end();
5864
if (typeof end === 'string') {
59-
stdinFileStream.write(end);
65+
appendFileQueue.queue(() => Promises.appendFile(targetPath, end));
6066
}
61-
stdinFileStream.end();
6267
});
63-
process.stdin.on('error', error => stdinFileStream.destroy(error));
64-
process.stdin.on('close', () => stdinFileStream.close());
6568
}

0 commit comments

Comments
 (0)