Skip to content

Commit

Permalink
[vscode] Add proposed documentPaste API (eclipse-theia#12737)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jul 25, 2023
1 parent 34e0d13 commit 4093531
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
7 changes: 6 additions & 1 deletion packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3506,11 +3506,16 @@ export class InteractiveWindowInput {
// #region DocumentPaste
@es5ClassCompat
export class DocumentPasteEdit {
constructor(insertText: string | SnippetString) {
constructor(insertText: string | SnippetString, id: string, label: string) {
this.insertText = insertText;
this.id = id;
this.label = label;
}
insertText: string | SnippetString;
additionalEdit?: WorkspaceEdit;
id: string;
label: string;
priority?: number;
}
// #endregion

Expand Down
44 changes: 38 additions & 6 deletions packages/plugin/src/theia.proposed.documentPaste.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// code copied and modified from https://github.com/microsoft/vscode/blob/1.77.0/src/vscode-dts/vscode.proposed.documentPaste.d.ts
// code copied and modified from https://github.com/microsoft/vscode/blob/1.79.0/src/vscode-dts/vscode.proposed.documentPaste.d.ts

export module '@theia/plugin' {

Expand Down Expand Up @@ -52,13 +52,32 @@ export module '@theia/plugin' {
*
* @return Optional workspace edit that applies the paste. Return undefined to use standard pasting.
*/
provideDocumentPasteEdits(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentPasteEdit>;
provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentPasteEdit>;
}

/**
* An operation applied on paste
*/
class DocumentPasteEdit {
/**
* Identifies the type of edit.
*
* This id should be unique within the extension but does not need to be unique across extensions.
*/
id: string;

/**
* Human readable label that describes the edit.
*/
label: string;

/**
* The relative priority of this edit. Higher priority items are shown first in the UI.
*
* Defaults to `0`.
*/
priority?: number;

/**
* The text or snippet to insert at the pasted locations.
*/
Expand All @@ -71,17 +90,30 @@ export module '@theia/plugin' {

/**
* @param insertText The text or snippet to insert at the pasted locations.
*
* TODO: Reverse args, but this will break existing consumers :(
*/
constructor(insertText: string | SnippetString);
constructor(insertText: string | SnippetString, id: string, label: string);
}

interface DocumentPasteProviderMetadata {
/**
* Mime types that `provideDocumentPasteEdits` should be invoked for.
* Mime types that {@link DocumentPasteEditProvider.prepareDocumentPaste provideDocumentPasteEdits} may add on copy.
*/
readonly copyMimeTypes?: readonly string[];

/**
* Mime types that {@link DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits} should be invoked for.
*
* This can either be an exact mime type such as `image/png`, or a wildcard pattern such as `image/*`.
*
* Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench.
*
* Use the special `files` mimetype to indicate the provider should be invoked if any files are present in the `DataTransfer`.
* Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@link DataTransfer}.
* Note that {@link DataTransferFile} entries are only created when dropping content from outside the editor, such as
* from the operating system.
*/
readonly pasteMimeTypes: readonly string[];
readonly pasteMimeTypes?: readonly string[];
}

namespace languages {
Expand Down

0 comments on commit 4093531

Please sign in to comment.