Skip to content

Commit

Permalink
Fix quick pick separators from plugins (#13740)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored May 29, 2024
1 parent ffdb635 commit c1e941e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/plugin-ext/src/main/browser/quick-open-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
QuickInputButtonHandle,
QuickInputService,
QuickPickItem,
QuickPickItemOrSeparator,
codiconArray
} from '@theia/core/lib/browser';
import { DisposableCollection, Disposable } from '@theia/core/lib/common/disposable';
Expand All @@ -46,10 +47,11 @@ import { UriComponents } from '../../common/uri-components';
import { URI } from '@theia/core/shared/vscode-uri';
import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/base/common/themables';
import { isUriComponents } from '@theia/monaco-editor-core/esm/vs/base/common/uri';
import { QuickPickSeparator } from '@theia/core';

export interface QuickInputSession {
input: QuickInput;
handlesToItems: Map<number, QuickPickItem>;
handlesToItems: Map<number, QuickPickItemOrSeparator>;
}

interface IconPath {
Expand All @@ -63,7 +65,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
private proxy: QuickOpenExt;
private delegate: MonacoQuickInputService;
private readonly items: Record<number, {
resolve(items: QuickPickItem[]): void;
resolve(items: QuickPickItemOrSeparator[]): void;
reject(error: Error): void;
}> = {};

Expand All @@ -80,7 +82,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
}

async $show(instance: number, options: TransferQuickPickOptions<TransferQuickPickItem>, token: CancellationToken): Promise<number | number[] | undefined> {
const contents = new Promise<QuickPickItem[]>((resolve, reject) => {
const contents = new Promise<QuickPickItemOrSeparator[]>((resolve, reject) => {
this.items[instance] = { resolve, reject };
});

Expand All @@ -92,7 +94,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
this.proxy.$onItemSelected(Number.parseInt((<QuickPickItem>el).id!));
}
},
activeItem: activeItem ? this.toQuickPickItem(activeItem) : undefined
activeItem: this.isItem(activeItem) ? this.toQuickPickItem(activeItem) : undefined
};

const result = await this.delegate.pick(contents, transformedOptions, token);
Expand All @@ -105,6 +107,10 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
return undefined;
}

private isItem(item?: TransferQuickPickItem): item is TransferQuickPickItem & { kind: 'item' } {
return item?.kind === 'item';
}

private normalizeIconPath(path: UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon | undefined): {
iconPath?: IconPath
iconClasses?: string[]
Expand All @@ -127,10 +133,17 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
}

private toQuickPickItem(item: undefined): undefined;
private toQuickPickItem(item: TransferQuickPickItem): QuickPickItem;
private toQuickPickItem(item: TransferQuickPickItem | undefined): QuickPickItem | undefined {
private toQuickPickItem(item: TransferQuickPickItem & { kind: 'item' }): QuickPickItem;
private toQuickPickItem(item: TransferQuickPickItem & { kind: 'separator' }): QuickPickSeparator;
private toQuickPickItem(item: TransferQuickPickItem): QuickPickItemOrSeparator;
private toQuickPickItem(item: TransferQuickPickItem | undefined): QuickPickItemOrSeparator | undefined {
if (!item) {
return undefined;
} else if (item.kind === 'separator') {
return {
type: 'separator',
label: item.label
};
}
return {
...this.normalizeIconPath(item.iconPath),
Expand Down Expand Up @@ -309,7 +322,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {
}
} else if (param === 'items') {
handlesToItems.clear();
const items: QuickPickItem[] = [];
const items: QuickPickItemOrSeparator[] = [];
params[param].forEach((transferItem: TransferQuickPickItem) => {
const item = this.toQuickPickItem(transferItem);
items.push(item);
Expand Down

0 comments on commit c1e941e

Please sign in to comment.