Skip to content

Commit

Permalink
In WSL --wait is still enforced for stdin (fix microsoft#209925) (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Apr 10, 2024
1 parent 3117776 commit b9226f2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/vs/server/node/server.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { createWaitMarkerFileSync } from 'vs/platform/environment/node/wait';
import { PipeCommand } from 'vs/workbench/api/node/extHostCLIServer';
import { hasStdinWithoutTty, getStdinFilePath, readFromStdin } from 'vs/platform/environment/node/stdin';
import { DeferredPromise } from 'vs/base/common/async';

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

parsedArgs['_'] = [];

let readFromStdinPromise: Promise<void> | undefined;

if (hasReadStdinArg && hasStdinWithoutTty()) {
try {
let stdinFilePath = cliStdInFilePath;
if (!stdinFilePath) {
stdinFilePath = getStdinFilePath();
await readFromStdin(stdinFilePath, verbose); // throws error if file can not be written
const readFromStdinDone = new DeferredPromise<void>();
await readFromStdin(stdinFilePath, verbose, () => readFromStdinDone.complete()); // throws error if file can not be written
if (!parsedArgs.wait) {
// if `--wait` is not provided, we keep this process alive
// for at least as long as the stdin stream is open to
// ensure that we read all the data.
readFromStdinPromise = readFromStdinDone.p;
}
}

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

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

console.log(`Reading from stdin via: ${stdinFilePath}`);
} catch (e) {
console.log(`Failed to create file to read via stdin: ${e.toString()}`);
}

}

if (parsedArgs.extensionDevelopmentPath) {
Expand Down Expand Up @@ -339,6 +347,10 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
if (waitMarkerFilePath) {
waitForFileDeleted(waitMarkerFilePath);
}

if (readFromStdinPromise) {
await readFromStdinPromise;
}
}
}

Expand Down

0 comments on commit b9226f2

Please sign in to comment.