Skip to content

Commit

Permalink
Fix potential JSON RPC error in the quick-open plugin API (#10230)
Browse files Browse the repository at this point in the history
Remap items to a new known objects to exclude non JSON RPC compatible objects when passing them through the quick-open plugin API.
  • Loading branch information
vinokurig authored and azatsarynnyy committed Oct 18, 2021
1 parent a73a746 commit cd50236
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Expand Up @@ -555,7 +555,7 @@ export interface TransferQuickInputButton extends theia.QuickInputButton {
handle?: number;
}

export type TransferQuickInput<T extends theia.QuickPickItem> = TransferQuickPick<T> | TransferInputBox;
export type TransferQuickInput = TransferQuickPick | TransferInputBox;

export interface BaseTransferQuickInput {
[key: string]: any;
Expand All @@ -566,14 +566,14 @@ export interface BaseTransferQuickInput {
visible?: boolean;
}

export interface TransferQuickPick<T extends theia.QuickPickItem> extends BaseTransferQuickInput {
export interface TransferQuickPick extends BaseTransferQuickInput {
type?: 'quickPick';
value?: string;
placeholder?: string;
buttons?: TransferQuickInputButton[];
items?: TransferQuickPickItems[];
activeItems?: ReadonlyArray<T>;
selectedItems?: ReadonlyArray<T>;
activeItems?: ReadonlyArray<theia.QuickPickItem>;
selectedItems?: ReadonlyArray<theia.QuickPickItem>;
canSelectMany?: boolean;
ignoreFocusOut?: boolean;
matchOnDescription?: boolean;
Expand Down Expand Up @@ -605,7 +605,7 @@ export interface QuickOpenMain {
$setItems(instance: number, items: TransferQuickPickItems[]): Promise<any>;
$setError(instance: number, error: Error): Promise<void>;
$input(options: theia.InputBoxOptions, validateInput: boolean, token: CancellationToken): Promise<string | undefined>;
$createOrUpdate<T extends theia.QuickPickItem>(params: TransferQuickInput<T>): Promise<void>;
$createOrUpdate<T extends theia.QuickPickItem>(params: TransferQuickInput): Promise<void>;
$dispose(id: number): Promise<void>;

$hide(): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/browser/quick-open-main.ts
Expand Up @@ -194,7 +194,7 @@ export class QuickOpenMainImpl implements QuickOpenMain, Disposable {

private sessions = new Map<number, QuickInputSession>();

$createOrUpdate<T extends theia.QuickPickItem>(params: TransferQuickInput<T>): Promise<void> {
$createOrUpdate<T extends theia.QuickPickItem>(params: TransferQuickInput): Promise<void> {
const sessionId = params.id;
let session = this.sessions.get(sessionId);
if (!session) {
Expand Down
13 changes: 10 additions & 3 deletions packages/plugin-ext/src/plugin/quick-open.ts
Expand Up @@ -259,7 +259,7 @@ export class QuickInputExt implements QuickInput {
private onDidHideEmitter: Emitter<void>;
private onDidTriggerButtonEmitter: Emitter<theia.QuickInputButton>;
private _updateTimeout: any;
private _pendingUpdate: TransferQuickInput<any> = { id: this._id };
private _pendingUpdate: TransferQuickInput = { id: this._id };

constructor(readonly quickOpen: QuickOpenExtImpl, readonly quickOpenMain: QuickOpenMain, readonly plugin: Plugin, private _onDidDispose: () => void) {
this.title = undefined;
Expand Down Expand Up @@ -613,9 +613,16 @@ export class QuickPickExt<T extends theia.QuickPickItem> extends QuickInputExt i
this._handlesToItems.set(i, item);
this._itemsToHandles.set(item, i);
});
items.forEach((item, i) => Object.assign(item, { handle: i }));
this.update({
items
items: items.map((item, i) => ({
type: item.type,
label: item.label,
description: item.description,
handle: i,
detail: item.detail,
picked: item.picked,
alwaysShow: item.alwaysShow
}))
});
}

Expand Down

0 comments on commit cd50236

Please sign in to comment.