Skip to content

Commit

Permalink
Stub for DocumentPaste proposed API.
Browse files Browse the repository at this point in the history
The immediate goal was for for the vscode built-in extension
`markdown-language-features` v1.72.2 (and a few prevgious I think),
to work again (minus the real "DocumentPaste" benefits.

Fixes eclipse-theia#12430

Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
  • Loading branch information
marcdumais-work committed May 9, 2023
1 parent b6de884 commit 890e4df
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
7 changes: 7 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,13 @@ export class LanguagesExtImpl implements LanguagesExt {
return result;
}
// #endregion

// Stub implementation
registerDocumentPasteEditProvider(
extension: Plugin, selector: theia.DocumentSelector, provider: theia.DocumentPasteEditProvider, metadata: theia.DocumentPasteProviderMetadata
): theia.Disposable {
return Disposable.NULL;
}
}

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 @@ -191,7 +191,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 @@ -918,6 +919,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 @@ -1336,7 +1342,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 @@ -3429,3 +3429,14 @@ export class InteractiveWindowInput {
}

// #endregion

// #region DocumentPaste
@es5ClassCompat
export class DocumentPasteEdit {
constructor(insertText: string | SnippetString) {
this.insertText = insertText;
}
insertText: string | SnippetString;
additionalEdit?: WorkspaceEdit;
}
// #endregion
72 changes: 72 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,78 @@ export module '@theia/plugin' {

}

// 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;
}

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

// #endregion
}

Expand Down

0 comments on commit 890e4df

Please sign in to comment.