Skip to content

Commit

Permalink
Finalize paste api and drop api tweaks
Browse files Browse the repository at this point in the history
Fixes #30066

This finalizes the documentPaste api. This api allows extensions to attach metadata on text copy and change how content is pasted. Some examples:

- Updating imports for pasted code
- Inserting an image as an attachment in notebooks
- Pasting files converts them to relative text paths
  • Loading branch information
mjbvz committed Jan 7, 2025
1 parent fc4e78c commit 4daea74
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 336 deletions.
3 changes: 0 additions & 3 deletions extensions/css-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"supported": true
}
},
"enabledApiProposals": [
"documentPaste"
],
"scripts": {
"compile": "npx gulp compile-extension:css-language-features-client compile-extension:css-language-features-server",
"watch": "npx gulp watch-extension:css-language-features-client watch-extension:css-language-features-server",
Expand Down
1 change: 0 additions & 1 deletion extensions/ipynb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"vscode": "^1.57.0"
},
"enabledApiProposals": [
"documentPaste",
"diffContentOptions"
],
"activationEvents": [
Expand Down
3 changes: 0 additions & 3 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"categories": [
"Programming Languages"
],
"enabledApiProposals": [
"documentPaste"
],
"activationEvents": [
"onLanguage:markdown",
"onCommand:markdown.api.render",
Expand Down
1 change: 0 additions & 1 deletion extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"mappedEditsProvider",
"codeActionAI",
"codeActionRanges",
"documentPaste",
"editorHoverVerbosityLevel"
],
"capabilities": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const enabledSettingId = 'updateImportsOnPaste.enabled';

class DocumentPasteProvider implements vscode.DocumentPasteEditProvider {

static readonly kind = vscode.DocumentDropOrPasteEditKind.Text.append('updateImports', 'jsts');
static readonly kind = vscode.DocumentDropOrPasteEditKind.TextUpdateImports.append('jsts');
static readonly metadataMimeType = 'application/vnd.code.jsts.metadata';

constructor(
Expand Down
1 change: 0 additions & 1 deletion extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"defaultChatParticipant",
"diffCommand",
"documentFiltersExclusive",
"documentPaste",
"editorInsets",
"embeddings",
"extensionRuntime",
Expand Down
3 changes: 0 additions & 3 deletions src/vs/platform/extensions/common/extensionsApiProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ const _allApiProposals = {
documentFiltersExclusive: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentFiltersExclusive.d.ts',
},
documentPaste: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentPaste.d.ts',
},
editSessionIdentityProvider: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editSessionIdentityProvider.d.ts',
},
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostLanguageFeatures.registerCodeActionProvider(extension, checkSelector(selector), provider, metadata);
},
registerDocumentPasteEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentPasteEditProvider, metadata: vscode.DocumentPasteProviderMetadata): vscode.Disposable {
checkProposedApiEnabled(extension, 'documentPaste');
return extHostLanguageFeatures.registerDocumentPasteEditProvider(extension, checkSelector(selector), provider, metadata);
},
registerCodeLensProvider(selector: vscode.DocumentSelector, provider: vscode.CodeLensProvider): vscode.Disposable {
Expand Down Expand Up @@ -669,7 +668,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostLanguages.createLanguageStatusItem(extension, id, selector);
},
registerDocumentDropEditProvider(selector: vscode.DocumentSelector, provider: vscode.DocumentDropEditProvider, metadata?: vscode.DocumentDropEditProviderMetadata): vscode.Disposable {
return extHostLanguageFeatures.registerDocumentOnDropEditProvider(extension, selector, provider, isProposedApiEnabled(extension, 'documentPaste') ? metadata : undefined);
return extHostLanguageFeatures.registerDocumentOnDropEditProvider(extension, selector, provider, metadata);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
const handle = this._nextHandle();
this._adapter.set(handle, new AdapterData(new DocumentDropEditAdapter(this._proxy, this._documents, provider, handle, extension), extension));

this._proxy.$registerDocumentOnDropEditProvider(handle, this._transformDocumentSelector(selector, extension), isProposedApiEnabled(extension, 'documentPaste') && metadata ? {
this._proxy.$registerDocumentOnDropEditProvider(handle, this._transformDocumentSelector(selector, extension), metadata ? {
supportsResolve: !!provider.resolveDocumentDropEdit,
dropMimeTypes: metadata.dropMimeTypes,
providedDropKinds: metadata.providedDropEditKinds?.map(x => x.value),
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,7 @@ export enum DocumentPasteTriggerKind {
export class DocumentDropOrPasteEditKind {
static Empty: DocumentDropOrPasteEditKind;
static Text: DocumentDropOrPasteEditKind;
static TextUpdateImports: DocumentDropOrPasteEditKind;

private static sep = '.';

Expand All @@ -2971,6 +2972,7 @@ export class DocumentDropOrPasteEditKind {
}
DocumentDropOrPasteEditKind.Empty = new DocumentDropOrPasteEditKind('');
DocumentDropOrPasteEditKind.Text = new DocumentDropOrPasteEditKind('text');
DocumentDropOrPasteEditKind.TextUpdateImports = DocumentDropOrPasteEditKind.Text.append('updateImports');

export class DocumentPasteEdit {

Expand Down
Loading

0 comments on commit 4daea74

Please sign in to comment.