-
Notifications
You must be signed in to change notification settings - Fork 29.5k
/
vscode.proposed.documentPaste.d.ts
297 lines (260 loc) · 11.4 KB
/
vscode.proposed.documentPaste.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
// https://github.com/microsoft/vscode/issues/30066/
/**
* Identifies a {@linkcode DocumentDropEdit} or {@linkcode DocumentPasteEdit}
*/
class DocumentDropOrPasteEditKind {
static readonly Empty: DocumentDropOrPasteEditKind;
private constructor(value: string);
/**
* The raw string value of the kind.
*/
readonly value: string;
/**
* Create a new kind by appending additional scopes to the current kind.
*
* Does not modify the current kind.
*/
append(...parts: string[]): DocumentDropOrPasteEditKind;
/**
* Checks if this kind intersects `other`.
*
* The kind `"text.plain"` for example intersects `text`, `"text.plain"` and `"text.plain.list"`,
* but not `"unicorn"`, or `"textUnicorn.plain"`.
*
* @param other Kind to check.
*/
intersects(other: DocumentDropOrPasteEditKind): boolean;
/**
* Checks if `other` is a sub-kind of this `DocumentDropOrPasteEditKind`.
*
* The kind `"text.plain"` for example contains `"text.plain"` and `"text.plain.list"`,
* but not `"text"` or `"unicorn.text.plain"`.
*
* @param other Kind to check.
*/
contains(other: DocumentDropOrPasteEditKind): boolean;
}
/**
* The reason why paste edits were requested.
*/
export enum DocumentPasteTriggerKind {
/**
* Pasting was requested as part of a normal paste operation.
*/
Automatic = 0,
/**
* Pasting was requested by the user with the `paste as` command.
*/
PasteAs = 1,
}
/**
* Additional information about the paste operation.
*/
export interface DocumentPasteEditContext {
/**
* Requested kind of paste edits to return.
*/
readonly only: DocumentDropOrPasteEditKind | undefined;
/**
* The reason why paste edits were requested.
*/
readonly triggerKind: DocumentPasteTriggerKind;
}
/**
* Provider invoked when the user copies or pastes in a {@linkcode TextDocument}.
*/
interface DocumentPasteEditProvider<T extends DocumentPasteEdit = DocumentPasteEdit> {
/**
* Optional method invoked after the user copies from a {@link TextEditor text editor}.
*
* This allows the provider to attach metadata about the copied text to the {@link DataTransfer}. This data
* transfer is then passed back to providers in {@linkcode provideDocumentPasteEdits}.
*
* Note that currently any changes to the {@linkcode DataTransfer} are isolated to the current editor window.
* This means that any added metadata cannot be seen by other editor windows or by other applications.
*
* @param document Text document where the copy took place.
* @param ranges Ranges being copied in {@linkcode document}.
* @param dataTransfer The data transfer associated with the copy. You can store additional values on this for
* later use in {@linkcode provideDocumentPasteEdits}. This object is only valid for the duration of this method.
* @param token A cancellation token.
*
* @return Optional thenable that resolves when all changes to the `dataTransfer` are complete.
*/
prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable<void>;
/**
* Invoked before the user pastes into a {@link TextEditor text editor}.
*
* Returned edits can replace the standard pasting behavior.
*
* @param document Document being pasted into
* @param ranges Range in the {@linkcode document} to paste into.
* @param dataTransfer The {@link DataTransfer data transfer} associated with the paste. This object is only
* valid for the duration of the paste operation.
* @param context Additional context for the paste.
* @param token A cancellation token.
*
* @return Set of potential {@link DocumentPasteEdit edits} that can apply the paste. Only a single returned
* {@linkcode DocumentPasteEdit} is applied at a time. If multiple edits are returned from all providers, then
* the first is automatically applied and a widget is shown that lets the user switch to the other edits.
*/
provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext, token: CancellationToken): ProviderResult<T[]>;
/**
* Optional method which fills in the {@linkcode DocumentPasteEdit.additionalEdit} before the edit is applied.
*
* This is called once per edit and should be used if generating the complete edit may take a long time.
* Resolve can only be used to change {@linkcode DocumentPasteEdit.additionalEdit}.
*
* @param pasteEdit The {@linkcode DocumentPasteEdit} to resolve.
* @param token A cancellation token.
*
* @returns The resolved paste edit or a thenable that resolves to such. It is OK to return the given
* `pasteEdit`. If no result is returned, the given `pasteEdit` is used.
*/
resolveDocumentPasteEdit?(pasteEdit: T, token: CancellationToken): ProviderResult<T>;
}
/**
* An edit the applies a paste operation.
*/
class DocumentPasteEdit {
/**
* Human readable label that describes the edit.
*/
title: string;
/**
* {@link DocumentDropOrPasteEditKind Kind} of the edit.
*/
kind: DocumentDropOrPasteEditKind;
/**
* The text or snippet to insert at the pasted locations.
*
* If your edit requires more advanced insertion logic, set this to an empty string and provide an {@link DocumentPasteEdit.additionalEdit additional edit} instead.
*/
insertText: string | SnippetString;
/**
* An optional additional edit to apply on paste.
*/
additionalEdit?: WorkspaceEdit;
/**
* Controls ordering when multiple paste edits can potentially be applied.
*
* If this edit yields to another, it will be shown lower in the list of possible paste edits shown to the user.
*/
yieldTo?: readonly DocumentDropOrPasteEditKind[];
/**
* Create a new paste edit.
*
* @param insertText The text or snippet to insert at the pasted locations.
* @param title Human readable label that describes the edit.
* @param kind {@link DocumentDropOrPasteEditKind Kind} of the edit.
*/
constructor(insertText: string | SnippetString, title: string, kind: DocumentDropOrPasteEditKind);
}
/**
* Provides additional metadata about how a {@linkcode DocumentPasteEditProvider} works.
*/
interface DocumentPasteProviderMetadata {
/**
* List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits}.
*
* This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested.
*/
readonly providedPasteEditKinds: readonly DocumentDropOrPasteEditKind[];
/**
* Mime types that {@linkcode DocumentPasteEditProvider.prepareDocumentPaste prepareDocumentPaste} may add on copy.
*/
readonly copyMimeTypes?: readonly string[];
/**
* Mime types that {@linkcode 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 `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@linkcode DataTransfer}.
* Note that {@linkcode DataTransferFile} entries are only created when pasting content from outside the editor, such as
* from the operating system.
*/
readonly pasteMimeTypes?: readonly string[];
}
/**
* TODO on finalization:
* - Add ctor(insertText: string | SnippetString, title?: string, kind?: DocumentDropOrPasteEditKind); Can't be done as this is an extension to an existing class
*/
export interface DocumentDropEdit {
/**
* Human readable label that describes the edit.
*/
title?: string;
/**
* {@link DocumentDropOrPasteEditKind Kind} of the edit.
*/
kind: DocumentDropOrPasteEditKind;
/**
* Controls the ordering or multiple edits. If this provider yield to edits, it will be shown lower in the list.
*/
yieldTo?: readonly DocumentDropOrPasteEditKind[];
}
export interface DocumentDropEditProvider<T extends DocumentDropEdit = DocumentDropEdit> {
// Overload that allows returning multiple edits
// Will be merged in on finalization
provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<DocumentDropEdit | DocumentDropEdit[]>;
/**
* Optional method which fills in the {@linkcode DocumentDropEdit.additionalEdit} before the edit is applied.
*
* This is called once per edit and should be used if generating the complete edit may take a long time.
* Resolve can only be used to change {@link DocumentDropEdit.additionalEdit}.
*
* @param pasteEdit The {@linkcode DocumentDropEdit} to resolve.
* @param token A cancellation token.
*
* @returns The resolved edit or a thenable that resolves to such. It is OK to return the given
* `edit`. If no result is returned, the given `edit` is used.
*/
resolveDocumentDropEdit?(edit: T, token: CancellationToken): ProviderResult<T>;
}
/**
* Provides additional metadata about how a {@linkcode DocumentDropEditProvider} works.
*/
export interface DocumentDropEditProviderMetadata {
/**
* List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in {@linkcode DocumentDropEditProvider.provideDocumentDropEdits provideDocumentDropEdits}.
*
* This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested.
*/
readonly providedDropEditKinds?: readonly DocumentDropOrPasteEditKind[];
/**
* List of {@link DataTransfer} mime types that the provider can handle.
*
* 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 `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 dropMimeTypes: readonly string[];
}
namespace languages {
/**
* Registers a new {@linkcode DocumentPasteEditProvider}.
*
* @param selector A selector that defines the documents this provider applies to.
* @param provider A paste editor provider.
* @param metadata Additional metadata about the provider.
*
* @returns A {@link Disposable} that unregisters this provider when disposed of.
*/
export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable;
/**
* Overload which adds extra metadata. Will be removed on finalization.
*/
export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider, metadata?: DocumentDropEditProviderMetadata): Disposable;
}
}