Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose QuickPick.matchOnLabel publicly #169681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
const quickPickWidget = proxy.$show(instance, {
title: options?.title,
placeHolder: options?.placeHolder,
matchOnLabel: options?.matchOnLabel,
matchOnDescription: options?.matchOnDescription,
matchOnDetail: options?.matchOnDetail,
ignoreFocusLost: options?.ignoreFocusOut,
Expand Down Expand Up @@ -525,6 +526,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
private _handlesToItems = new Map<number, T>();
private _itemsToHandles = new Map<T, number>();
private _canSelectMany = false;
private _matchOnLabel = true;
private _matchOnDescription = true;
private _matchOnDetail = true;
private _sortByLabel = true;
Expand Down Expand Up @@ -596,6 +598,15 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
this.update({ canSelectMany });
}

get matchOnLabel() {
return this._matchOnLabel;
}

set matchOnLabel(matchOnLabel: boolean) {
this._matchOnLabel = matchOnLabel;
this.update({ matchOnLabel });
}

get matchOnDescription() {
return this._matchOnDescription;
}
Expand Down
59 changes: 59 additions & 0 deletions src/vs/workbench/api/test/common/extHostQuickOpen.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import { QuickPick } from 'vscode';
import { mock } from 'vs/base/test/common/mock';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { IMainContext } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { createExtHostQuickOpen, ExtHostQuickOpen } from 'vs/workbench/api/common/extHostQuickOpen';
import { ExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';

suite('ExtHostQuickOpen', () => {

const ext = new ExtensionIdentifier(`ext`);
const protocol: IMainContext = {
getProxy: () => { return <any>proxy; },
set: () => { return undefined!; },
dispose: () => { },
assertRegistered: () => { },
drain: () => { return undefined!; },
};
const ws = new class extends mock<ExtHostWorkspace>() { };
const commands = new class extends mock<ExtHostCommands>() { };
const extension = new class extends mock<IExtensionDescription>() { override identifier = ext; };
let proxy: QuickProxy;
let host: ExtHostQuickOpen;
let pick: QuickPick<any>;

setup(() => {
proxy = new QuickProxy();
host = createExtHostQuickOpen(protocol, ws, commands);
});

teardown(() => { pick.dispose(); });

test('matchOnLabel property defaults to true', () => {
pick = host.createQuickPick(extension);
assert.strictEqual(pick.matchOnLabel, true);
});

test('matchOnLabel value is forwarded to proxy', async () => {
pick = host.createQuickPick(extension);
pick.matchOnLabel = false;
assert.strictEqual(pick.matchOnLabel, false);
pick.show();
assert.strictEqual((await proxy.update).matchOnLabel, false);
});
});

type Update = { [key: string]: any };
class QuickProxy {
private gotUpdate: any;
public update = new Promise<Update>(resolve => { this.gotUpdate = resolve; });
public $createOrUpdate(value: Update) { this.gotUpdate(value); }
public $dispose() { }
}
10 changes: 10 additions & 0 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,11 @@ declare module 'vscode' {
*/
title?: string;

/**
* An optional flag to include the label when filtering the picks.
*/
matchOnLabel?: boolean;

/**
* An optional flag to include the description when filtering the picks.
*/
Expand Down Expand Up @@ -11482,6 +11487,11 @@ declare module 'vscode' {
*/
canSelectMany: boolean;

/**
* If the filter text should be matched against the label of the items. Defaults to true.
*/
matchOnLabel: boolean;

/**
* If the filter text should also be matched against the description of the items. Defaults to false.
*/
Expand Down