Skip to content

Commit b9226f2

Browse files
authored
In WSL --wait is still enforced for stdin (fix microsoft#209925) (microsoft#210016)
1 parent 3117776 commit b9226f2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/vs/server/node/server.cli.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
1515
import { createWaitMarkerFileSync } from 'vs/platform/environment/node/wait';
1616
import { PipeCommand } from 'vs/workbench/api/node/extHostCLIServer';
1717
import { hasStdinWithoutTty, getStdinFilePath, readFromStdin } from 'vs/platform/environment/node/stdin';
18+
import { DeferredPromise } from 'vs/base/common/async';
1819

1920
/*
2021
* Implements a standalone CLI app that opens VS Code from a remote terminal.
@@ -181,26 +182,33 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
181182

182183
parsedArgs['_'] = [];
183184

185+
let readFromStdinPromise: Promise<void> | undefined;
186+
184187
if (hasReadStdinArg && hasStdinWithoutTty()) {
185188
try {
186189
let stdinFilePath = cliStdInFilePath;
187190
if (!stdinFilePath) {
188191
stdinFilePath = getStdinFilePath();
189-
await readFromStdin(stdinFilePath, verbose); // throws error if file can not be written
192+
const readFromStdinDone = new DeferredPromise<void>();
193+
await readFromStdin(stdinFilePath, verbose, () => readFromStdinDone.complete()); // throws error if file can not be written
194+
if (!parsedArgs.wait) {
195+
// if `--wait` is not provided, we keep this process alive
196+
// for at least as long as the stdin stream is open to
197+
// ensure that we read all the data.
198+
readFromStdinPromise = readFromStdinDone.p;
199+
}
190200
}
191201

192202
// Make sure to open tmp file
193203
translatePath(stdinFilePath, mapFileUri, folderURIs, fileURIs);
194204

195-
// Enable --wait to get all data and ignore adding this to history
196-
parsedArgs.wait = true;
205+
// Ignore adding this to history
197206
parsedArgs['skip-add-to-recently-opened'] = true;
198207

199208
console.log(`Reading from stdin via: ${stdinFilePath}`);
200209
} catch (e) {
201210
console.log(`Failed to create file to read via stdin: ${e.toString()}`);
202211
}
203-
204212
}
205213

206214
if (parsedArgs.extensionDevelopmentPath) {
@@ -339,6 +347,10 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
339347
if (waitMarkerFilePath) {
340348
waitForFileDeleted(waitMarkerFilePath);
341349
}
350+
351+
if (readFromStdinPromise) {
352+
await readFromStdinPromise;
353+
}
342354
}
343355
}
344356

0 commit comments

Comments
 (0)