Skip to content

Commit cff62d1

Browse files
authored
Install extensions with delay to workaround vscode bug (#8633)
2 parents 7d01aea + 1eda99c commit cff62d1

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

test/vscodeLauncher.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,38 @@ export async function prepareVSCodeAndExecuteTests(
6969

7070
async function installExtensions(extensionIds: string[], vscodeCli: string, vscodeArgs: string[]): Promise<void> {
7171
for (const extensionId of extensionIds) {
72-
vscodeArgs.push('--install-extension', extensionId);
72+
// Workaround for https://github.com/microsoft/vscode/issues/256031 to retry installing the extension with a delay.
73+
let installError: any | undefined = undefined;
74+
let installSucceeded = false;
75+
for (let attempts = 0; attempts < 5; attempts++) {
76+
try {
77+
await installExtension(extensionId, vscodeCli, vscodeArgs);
78+
installSucceeded = true;
79+
break;
80+
} catch (error) {
81+
console.warn(`Failed to install extension ${extensionId}; retrying: ${error}`);
82+
installError = error;
83+
await new Promise((resolve) => setTimeout(resolve, 2000));
84+
}
85+
}
86+
87+
if (!installSucceeded) {
88+
throw installError;
89+
}
7390
}
7491

92+
console.log();
93+
}
94+
95+
async function installExtension(extensionId: string, vscodeCli: string, vscodeArgs: string[]): Promise<void> {
96+
const argsWithExtension = [...vscodeArgs, '--install-extension', extensionId];
97+
7598
// Since we're using shell execute, spaces in the CLI path will get interpeted as args
7699
// Therefore we wrap the CLI path in quotes as on MacOS the path can contain spaces.
77100
const cliWrapped = `"${vscodeCli}"`;
78-
console.log(`${cliWrapped} ${vscodeArgs}`);
101+
console.log(`${cliWrapped} ${argsWithExtension}`);
79102

80-
const result = cp.spawnSync(cliWrapped, vscodeArgs, {
103+
const result = cp.spawnSync(cliWrapped, argsWithExtension, {
81104
encoding: 'utf-8',
82105
stdio: 'inherit',
83106
// Workaround as described in https://github.com/nodejs/node/issues/52554
@@ -86,8 +109,6 @@ async function installExtensions(extensionIds: string[], vscodeCli: string, vsco
86109
if (result.error || result.status !== 0) {
87110
throw new Error(`Failed to install extensions: ${JSON.stringify(result)}`);
88111
}
89-
90-
console.log();
91112
}
92113

93114
function getSln(workspacePath: string): string | undefined {

0 commit comments

Comments
 (0)