retry after waiting for workbench restore (#195300)

This commit is contained in:
Sandeep Somavarapu 2023-10-11 01:05:45 +02:00 committed by GitHub
parent 33e39e8c16
commit 9a611bbe20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -174,7 +174,7 @@ export class QuickAccess {
const keepOpen = options?.keepOpen;
const exactLabelMatch = options?.exactLabelMatch;
const openCommandPalletteAndTypeCommand = async (): Promise<string> => {
const openCommandPalletteAndTypeCommand = async (): Promise<boolean> => {
// open commands picker
await this.openQuickAccessWithRetry(QuickAccessKind.Commands, `>${commandId}`);
@ -182,25 +182,43 @@ export class QuickAccess {
await this.quickInput.waitForQuickInputElementFocused();
// Retry for as long as the command not found
return await this.quickInput.waitForQuickInputElementText();
const text = await this.quickInput.waitForQuickInputElementText();
if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
return false;
}
return true;
};
let text = await openCommandPalletteAndTypeCommand();
let hasCommandFound = await openCommandPalletteAndTypeCommand();
if (!hasCommandFound) {
if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
this.code.logger.log(`QuickAccess: No matching commands, will retry...`);
await this.quickInput.closeQuickInput();
// Wait for workbench to be restored
await this.code.whenWorkbenchRestored();
// Retry after workbench is restored
text = await openCommandPalletteAndTypeCommand();
if (text === 'No matching commands' || (exactLabelMatch && text !== commandId)) {
throw new Error(`Command: ${commandId} Not found`);
let retries = 0;
while (++retries < 5) {
hasCommandFound = await openCommandPalletteAndTypeCommand();
if (hasCommandFound) {
break;
} else {
this.code.logger.log(`QuickAccess: No matching commands, will retry...`);
await this.quickInput.closeQuickInput();
await this.code.wait(1000);
}
}
if (!hasCommandFound) {
throw new Error(`QuickAccess.runCommand(commandId: ${commandId}) failed to find command.`);
}
}
// wait and click on best choice
await this.quickInput.selectQuickInputElement(0, keepOpen);
}