diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts index 5138a762aba..ba7ce21e32f 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { commands, window } from 'vscode'; +import { commands, Disposable, QuickPick, QuickPickItem, window } from 'vscode'; import { assertNoRpc, closeAllEditors } from '../utils'; interface QuickPickExpected { @@ -204,6 +204,50 @@ suite('vscode API - quick input', function () { quickPick.hide(); quickPick.dispose(); }); + + test('createQuickPick, hide and hide', function (_done) { + let done = (err?: any) => { + done = () => { }; + _done(err); + }; + + let hidden = false; + const quickPick = window.createQuickPick(); + quickPick.onDidHide(() => { + if (hidden) { + done(new Error('Already hidden')); + } else { + hidden = true; + setTimeout(done, 0); + } + }); + quickPick.show(); + quickPick.hide(); + quickPick.hide(); + }); + + test('createQuickPick, hide show hide', async function () { + async function waitForHide(quickPick: QuickPick) { + let disposable: Disposable | undefined; + try { + await Promise.race([ + new Promise(resolve => disposable = quickPick.onDidHide(() => resolve(true))), + new Promise((_, reject) => setTimeout(() => reject(), 4000)) + ]); + } finally { + disposable?.dispose(); + } + } + + const quickPick = window.createQuickPick(); + quickPick.show(); + const promise = waitForHide(quickPick); + quickPick.hide(); + quickPick.show(); + await promise; + quickPick.hide(); + await waitForHide(quickPick); + }); }); function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void, record = false) { diff --git a/src/vs/workbench/api/common/extHostQuickOpen.ts b/src/vs/workbench/api/common/extHostQuickOpen.ts index 5e735c8c1ec..8f935e1eb1e 100644 --- a/src/vs/workbench/api/common/extHostQuickOpen.ts +++ b/src/vs/workbench/api/common/extHostQuickOpen.ts @@ -420,7 +420,15 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx _fireDidHide() { if (this._expectingHide) { - this._expectingHide = false; + // if this._visible is true, it means that .show() was called between + // .hide() and .onDidHide. To ensure the correct number of onDidHide events + // are emitted, we set this._expectingOnDidHide to this value so that + // the next time .hide() is called, we can emit the event again. + // Example: + // .show() -> .hide() -> .show() -> .hide() should emit 2 onDidHide events. + // .show() -> .hide() -> .hide() should emit 1 onDidHide event. + // Fixes #135747 + this._expectingHide = this._visible; this._onDidHideEmitter.fire(); } }