| 19 | constructor(private code: Code, private editors: Editors, private quickInput: QuickInput) { } |
| 20 | |
| 21 | async openFileQuickAccessAndWait(searchValue: string, expectedFirstElementNameOrExpectedResultCount: string | number): Promise<void> { |
| 22 | |
| 23 | // make sure the file quick access is not "polluted" |
| 24 | // with entries from the editor history when opening |
| 25 | await this.runCommand('workbench.action.clearEditorHistoryWithoutConfirm'); |
| 26 | |
| 27 | const PollingStrategy = { |
| 28 | Stop: true, |
| 29 | Continue: false |
| 30 | }; |
| 31 | |
| 32 | let retries = 0; |
| 33 | let success = false; |
| 34 | |
| 35 | while (++retries < 10) { |
| 36 | let retry = false; |
| 37 | |
| 38 | try { |
| 39 | await this.openQuickAccessWithRetry(QuickAccessKind.Files, searchValue); |
| 40 | await this.quickInput.waitForQuickInputElements(elementNames => { |
| 41 | this.code.logger.log('QuickAccess: resulting elements: ', elementNames); |
| 42 | |
| 43 | // Quick access seems to be still running -> retry |
| 44 | if (elementNames.length === 0) { |
| 45 | this.code.logger.log('QuickAccess: file search returned 0 elements, will continue polling...'); |
| 46 | |
| 47 | return PollingStrategy.Continue; |
| 48 | } |
| 49 | |
| 50 | // Quick access does not seem healthy/ready -> retry |
| 51 | const firstElementName = elementNames[0]; |
| 52 | if (firstElementName === 'No matching results') { |
| 53 | this.code.logger.log(`QuickAccess: file search returned "No matching results", will retry...`); |
| 54 | |
| 55 | retry = true; |
| 56 | |
| 57 | return PollingStrategy.Stop; |
| 58 | } |
| 59 | |
| 60 | // Expected: number of results |
| 61 | if (typeof expectedFirstElementNameOrExpectedResultCount === 'number') { |
| 62 | if (elementNames.length === expectedFirstElementNameOrExpectedResultCount) { |
| 63 | success = true; |
| 64 | |
| 65 | return PollingStrategy.Stop; |
| 66 | } |
| 67 | |
| 68 | this.code.logger.log(`QuickAccess: file search returned ${elementNames.length} results but was expecting ${expectedFirstElementNameOrExpectedResultCount}, will retry...`); |
| 69 | |
| 70 | retry = true; |
| 71 | |
| 72 | return PollingStrategy.Stop; |
| 73 | } |
| 74 | |
| 75 | // Expected: string |
| 76 | else { |
| 77 | if (firstElementName === expectedFirstElementNameOrExpectedResultCount) { |
| 78 | success = true; |