Skip to content

Commit

Permalink
Allow to specify title and placeholder in API for interpreter quickpi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored and eleanorjboyd committed Oct 4, 2022
1 parent 5702b85 commit e8a490d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client/common/utils/multiStepInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface IQuickPickParameters<T extends QuickPickItem, E = any> {
canGoBack?: boolean;
items: T[];
activeItem?: T | Promise<T>;
placeholder: string;
placeholder: string | undefined;
customButtonSetups?: QuickInputButtonSetup[];
matchOnDescription?: boolean;
matchOnDetail?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
input: IMultiStepInput<InterpreterStateArgs>,
state: InterpreterStateArgs,
filter?: (i: PythonEnvironment) => boolean,
params?: { placeholder?: string | null; title?: string | null },
): Promise<void | InputStep<InterpreterStateArgs>> {
// If the list is refreshing, it's crucial to maintain sorting order at all
// times so that the visible items do not change.
Expand All @@ -138,19 +139,26 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
this.configurationService.getSettings(state.workspace).pythonPath,
state.workspace ? state.workspace.fsPath : undefined,
);
const placeholder =
params?.placeholder === null
? undefined
: params?.placeholder ??
localize(
'InterpreterQuickPickList.quickPickListPlaceholder',
'Selected Interpreter: {0}',
currentInterpreterPathDisplay,
);
const title =
params?.title === null ? undefined : params?.title ?? InterpreterQuickPickList.browsePath.openButtonLabel;
const selection = await input.showQuickPick<QuickPickType, IQuickPickParameters<QuickPickType>>({
placeholder: localize(
'InterpreterQuickPickList.quickPickListPlaceholder',
'Selected Interpreter: {0}',
currentInterpreterPathDisplay,
),
placeholder,
items: suggestions,
sortByLabel: !preserveOrderWhenFiltering,
keepScrollPosition: true,
activeItem: this.getActiveItem(state.workspace, suggestions), // Use a promise here to ensure quickpick is initialized synchronously.
matchOnDetail: true,
matchOnDescription: true,
title: InterpreterQuickPickList.browsePath.openButtonLabel,
title,
customButtonSetups: [
{
button: this.refreshButton,
Expand Down Expand Up @@ -503,10 +511,11 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand implem
public async getInterpreterViaQuickPick(
workspace: Resource,
filter: ((i: PythonEnvironment) => boolean) | undefined,
params?: { placeholder?: string | null; title?: string | null },
): Promise<string | undefined> {
const interpreterState: InterpreterStateArgs = { path: undefined, workspace };
const multiStep = this.multiStepFactory.create<InterpreterStateArgs>();
await multiStep.run((input, s) => this._pickInterpreter(input, s, filter), interpreterState);
await multiStep.run((input, s) => this._pickInterpreter(input, s, filter, params), interpreterState);
return interpreterState.path;
}

Expand Down
10 changes: 10 additions & 0 deletions src/client/interpreter/configuration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,15 @@ export interface IInterpreterQuickPick {
getInterpreterViaQuickPick(
workspace: Resource,
filter?: (i: PythonEnvironment) => boolean,
params?: {
/**
* Specify `null` if a placeholder is not required.
*/
placeholder?: string | null;
/**
* Specify `null` if a title is not required.
*/
title?: string | null;
},
): Promise<string | undefined>;
}

0 comments on commit e8a490d

Please sign in to comment.