From 59fdd6cdf75ea607833758ddfc062a6ff3bc9429 Mon Sep 17 00:00:00 2001 From: Remi Schnekenburger Date: Wed, 18 Oct 2023 17:42:27 +0200 Subject: [PATCH] evolution on proposed API dropMetadata with vs code 1.82 note the API can't be fully implemented until next monaco upgrade Fixes #12986 contributed on behalf of STMicroelectronics --- CHANGELOG.md | 2 ++ .../src/common/plugin-api-rpc-model.ts | 1 + .../src/main/browser/languages-main.ts | 12 ++++---- .../src/theia.proposed.dropMetadata.d.ts | 29 ++++++++++++------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0476d4bd1bdff..ec00510584bef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ## v1.43.0 - Unreleased +- [vsode] evolve proposed API for dropDocument [#13009](https://github.com/eclipse-theia/theia/pull/13009) - contributed on behalf of STMicroelectronics + [Breaking Changes:](#breaking_changes_1.43.0) - [core] removed `SETTINGS_OPEN` menupath constant - replaced by `MANAGE_GENERAL` [#12803](https://github.com/eclipse-theia/theia/pull/12803) diff --git a/packages/plugin-ext/src/common/plugin-api-rpc-model.ts b/packages/plugin-ext/src/common/plugin-api-rpc-model.ts index 6b50bd29a2734..2c3ed04df81b9 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc-model.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc-model.ts @@ -330,6 +330,7 @@ export interface DocumentDropEdit { } export interface DocumentDropEditProviderMetadata { + readonly id: string; readonly dropMimeTypes: readonly string[]; } diff --git a/packages/plugin-ext/src/main/browser/languages-main.ts b/packages/plugin-ext/src/main/browser/languages-main.ts index 0b9e9120fd9ce..9d128eda986ac 100644 --- a/packages/plugin-ext/src/main/browser/languages-main.ts +++ b/packages/plugin-ext/src/main/browser/languages-main.ts @@ -740,7 +740,8 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable { createDocumentDropEditProvider(handle: number, _metadata?: DocumentDropEditProviderMetadata): DocumentOnDropEditProvider { return { - // @monaco-uplift dropMimeTypes should be supported by the monaco drop editor provider after 1.79.0 + // @monaco-uplift id and dropMimeTypes should be supported by the monaco drop editor provider after 1.82.0 + // id?: string; // dropMimeTypes: metadata?.dropMimeTypes ?? ['*/*'], provideDocumentOnDropEdits: async (model, position, dataTransfer, token) => this.provideDocumentDropEdits(handle, model, position, dataTransfer, token) }; @@ -752,10 +753,11 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable { const edit = await this.proxy.$provideDocumentDropEdits(handle, model.uri, position, await DataTransfer.toDataTransferDTO(dataTransfer), token); if (edit) { return { - // @monaco-uplift id, priority and label should be supported by monaco after 1.79.0. The implementation relies on a copy of the plugin data - // id: edit.id ? plugin.identifier.value + '.' + edit.id : plugin.identifier.value, - // label: edit.label ?? nls.localizeByDefault("Drop using '{0}' extension", plugin.displayName || plugin.name), - // priority: edit.priority ?? 0, + // @monaco-uplift label and yieldTo should be supported by monaco after 1.82.0. The implementation relies on a copy of the plugin data + // label: label: edit.label ?? localize('defaultDropLabel', "Drop using '{0}' extension", this._extension.displayName || this._extension.name),, + // yieldTo: edit.yieldTo?.map(yTo => { + // return 'mimeType' in yTo ? yTo : { providerId: DocumentOnDropEditAdapter.toInternalProviderId(yTo.extensionId, yTo.providerId) }; + // }), insertText: edit.insertText instanceof SnippetString ? { snippet: edit.insertText.value } : edit.insertText, additionalEdit: toMonacoWorkspaceEdit(edit?.additionalEdit) }; diff --git a/packages/plugin/src/theia.proposed.dropMetadata.d.ts b/packages/plugin/src/theia.proposed.dropMetadata.d.ts index 3947e409786b1..a8f58d436f2f3 100644 --- a/packages/plugin/src/theia.proposed.dropMetadata.d.ts +++ b/packages/plugin/src/theia.proposed.dropMetadata.d.ts @@ -25,27 +25,36 @@ export module '@theia/plugin' { // https://github.com/microsoft/vscode/issues/179430 export interface DocumentDropEdit { + /** - * Identifies the type of edit. - * - * This id should be unique within the extension but does not need to be unique across extensions. + * Human readable label that describes the edit. */ - id?: string; + label?: string; /** - * The relative priority of this edit. Higher priority items are shown first in the UI. - * - * Defaults to `0`. + * The mime type from the {@link DataTransfer} that this edit applies. */ - priority?: number; + handledMimeType?: string; /** - * Human readable label that describes the edit. + * Controls the ordering or multiple paste edits. If this provider yield to edits, it will be shown lower in the list. */ - label?: string; + yieldTo?: ReadonlyArray< + | { readonly extensionId: string; readonly providerId: string } + | { readonly mimeType: string } + >; } export interface DocumentDropEditProviderMetadata { + /** + * Identifies the provider. + * + * This id is used when users configure the default provider for drop. + * + * This id should be unique within the extension but does not need to be unique across extensions. + */ + readonly id: string; + /** * List of data transfer types that the provider supports. *