Skip to content

Commit

Permalink
Stub for proposed API: DocumentPaste
Browse files Browse the repository at this point in the history
The immediate goal is for vscode built-in extension
`vscode.markdown-language-features` v1.72.2 to work again (minus
the "DocumentPaste" benefits.

Fixes eclipse-theia#12430

Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
  • Loading branch information
marcdumais-work committed May 10, 2023
1 parent fa94013 commit 4867d2a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/plugin-ext/src/plugin/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,16 @@ export class LanguagesExtImpl implements LanguagesExt {
return result;
}
// #endregion

// region DocumentPaste

/** @stubbed */
registerDocumentPasteEditProvider(
extension: Plugin, selector: theia.DocumentSelector, provider: theia.DocumentPasteEditProvider, metadata: theia.DocumentPasteProviderMetadata
): theia.Disposable {
return Disposable.NULL;
}
// #endregion
}

function getPluginLabel(pluginInfo: PluginInfo): string {
Expand Down
11 changes: 9 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ import {
TerminalEditorTabInput,
TextDiffTabInput,
TextMergeTabInput,
WebviewEditorTabInput
WebviewEditorTabInput,
DocumentPasteEdit
} from './types-impl';
import { AuthenticationExtImpl } from './authentication-ext';
import { SymbolKind } from '../common/plugin-api-rpc-model';
Expand Down Expand Up @@ -927,6 +928,11 @@ export function createAPIFactory(
},
createLanguageStatusItem(id: string, selector: theia.DocumentSelector): theia.LanguageStatusItem {
return languagesExt.createLanguageStatusItem(plugin, id, selector);
},
registerDocumentPasteEditProvider(
selector: theia.DocumentSelector, provider: theia.DocumentPasteEditProvider, metadata: theia.DocumentPasteProviderMetadata
): theia.Disposable {
return languagesExt.registerDocumentPasteEditProvider(plugin, selector, provider, metadata);
}
};

Expand Down Expand Up @@ -1346,7 +1352,8 @@ export function createAPIFactory(
TabInputWebview: WebviewEditorTabInput,
TabInputTerminal: TerminalEditorTabInput,
TerminalLocation,
TerminalExitReason
TerminalExitReason,
DocumentPasteEdit
};
};
}
Expand Down
11 changes: 11 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3477,3 +3477,14 @@ export class InteractiveWindowInput {
}

// #endregion

// #region DocumentPaste
@es5ClassCompat
export class DocumentPasteEdit {
constructor(insertText: string | SnippetString) {
this.insertText = insertText;
}
insertText: string | SnippetString;
additionalEdit?: WorkspaceEdit;
}
// #endregion
69 changes: 69 additions & 0 deletions packages/plugin/src/theia-proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,75 @@ export module '@theia/plugin' {

}

// #region DocumentPaste

// https://github.com/microsoft/vscode/issues/30066/

/**
* Provider invoked when the user copies and pastes code.
*/
export interface DocumentPasteEditProvider {

/**
* Optional method invoked after the user copies text in a file.
*
* During {@link prepareDocumentPaste}, an extension can compute metadata that is attached to
* a {@link DataTransfer} and is passed back to the provider in {@link provideDocumentPasteEdits}.
*
* @param document Document where the copy took place.
* @param ranges Ranges being copied in the `document`.
* @param dataTransfer The data transfer associated with the copy. You can store additional values on this for later use in {@link provideDocumentPasteEdits}.
* @param token A cancellation token.
*/
prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable<void>;

/**
* Invoked before the user pastes into a document.
*
* In this method, extensions can return a workspace edit that replaces the standard pasting behavior.
*
* @param document Document being pasted into
* @param ranges Currently selected ranges in the document.
* @param dataTransfer The data transfer associated with the paste.
* @param token A cancellation token.
*
* @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>;
}

/**
* An operation applied on paste
*/
class DocumentPasteEdit {
/**
* The text or snippet to insert at the pasted locations.
*/
insertText: string | SnippetString;

/**
* An optional additional edit to apply on paste.
*/
additionalEdit?: WorkspaceEdit;

/**
* @param insertText The text or snippet to insert at the pasted locations.
*/
constructor(insertText: string | SnippetString);
}

interface DocumentPasteProviderMetadata {
/**
* Mime types that `provideDocumentPasteEdits` should be invoked for.
*
* Use the special `files` mimetype to indicate the provider should be invoked if any files are present in the `DataTransfer`.
*/
readonly pasteMimeTypes: readonly string[];
}

namespace languages {
export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable;
}
// #endregion

// #region SessionIdentityProvider
Expand Down

0 comments on commit 4867d2a

Please sign in to comment.