Add toggle support for QuickInput/QuickPick, resourceUri support for QuickPickItem (#271598)

* Add quickPickItemResource API proposal

* Transfer resourceUri from extension host to main thread.

* Make proposed API checks consistent.

* Process resourceUri

* Fix up resourceUri mapping logic

* API proposal

* Transfer toggles from extension host to main thread

* Support Folder icon, refactor label/description derivation.

* Update

* Update API proposal per API review

* Update transfer logic per API changes

* Move toggles to the base input interface

* Handle toggle button type

* Fix up

* Updates

* Propagate checked state, dispose removed toggles.

* Nit

* Expand icons

* Feedback/updates

* Added comments, PR feedback

* Updates

* Revert some change, add typings and unit-tests to converters.

* Add a quick pick test for resourceUri

* Test updates
This commit is contained in:
Dmitriy Vasyura
2025-10-18 15:57:07 -07:00
committed by GitHub
parent 8e72c61e03
commit bfba6b040c
14 changed files with 558 additions and 151 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { commands, Disposable, QuickPick, QuickPickItem, window } from 'vscode';
import { commands, Disposable, QuickPick, QuickPickItem, window, workspace } from 'vscode';
import { assertNoRpc, closeAllEditors } from '../utils';
interface QuickPickExpected {
@@ -248,6 +248,71 @@ suite('vscode API - quick input', function () {
quickPick.hide();
await waitForHide(quickPick);
});
test('createQuickPick, match item by label derived from resourceUri', function (_done) {
let done = (err?: any) => {
done = () => { };
_done(err);
};
const quickPick = createQuickPick({
events: ['active', 'selection', 'accept', 'hide'],
activeItems: [['']],
selectionItems: [['']],
acceptedItems: {
active: [['']],
selection: [['']],
dispose: [true]
},
}, (err?: any) => done(err));
const baseUri = workspace!.workspaceFolders![0].uri;
quickPick.items = [
{ label: 'a1', resourceUri: baseUri.with({ path: baseUri.path + '/test1.txt' }) },
{ label: '', resourceUri: baseUri.with({ path: baseUri.path + '/test2.txt' }) },
{ label: 'a3', resourceUri: baseUri.with({ path: baseUri.path + '/test3.txt' }) }
];
quickPick.value = 'test2.txt';
quickPick.show();
(async () => {
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
})()
.catch(err => done(err));
});
test('createQuickPick, match item by description derived from resourceUri', function (_done) {
let done = (err?: any) => {
done = () => { };
_done(err);
};
const quickPick = createQuickPick({
events: ['active', 'selection', 'accept', 'hide'],
activeItems: [['a2']],
selectionItems: [['a2']],
acceptedItems: {
active: [['a2']],
selection: [['a2']],
dispose: [true]
},
}, (err?: any) => done(err));
const baseUri = workspace!.workspaceFolders![0].uri;
quickPick.items = [
{ label: 'a1', resourceUri: baseUri.with({ path: baseUri.path + '/test1.txt' }) },
{ label: 'a2', resourceUri: baseUri.with({ path: baseUri.path + '/test2.txt' }) },
{ label: 'a3', resourceUri: baseUri.with({ path: baseUri.path + '/test3.txt' }) }
];
quickPick.matchOnDescription = true;
quickPick.value = 'test2.txt';
quickPick.show();
(async () => {
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
})()
.catch(err => done(err));
});
});
function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void, record = false) {