forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vscode.proposed.documentPaste.d.ts
196 lines (168 loc) · 7.06 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
/*---------------------------------------------------------------------------------------------
* 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/
/**
* 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: DocumentPasteEditKind | 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 text in a file.
*
* This allows the provider to attach copy metadata to the {@link DataTransfer}
* which is then passed back to providers in {@linkcode provideDocumentPasteEdits}.
*
* Note that currently any changes to the {@linkcode DataTransfer} are isolated to the current editor session.
* This means that added metadata cannot be seen by other applications.
*
* @param document 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 document.
*
* 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 apply the paste. Return `undefined` to use standard pasting.
*/
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 {@link 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 applied on paste.
*/
class DocumentPasteEdit {
/**
* Human readable label that describes the edit.
*/
title: string;
/**
* {@link DocumentPasteEditKind Kind} of the edit.
*
* Used to identify specific types of edits.
*/
kind: DocumentPasteEditKind;
/**
* The text or snippet to insert at the pasted locations.
*/
insertText: string | SnippetString;
/**
* An optional additional edit to apply on paste.
*/
additionalEdit?: WorkspaceEdit;
/**
* Controls the ordering of paste edits provided by multiple providers.
*
* If this edit yields to another, it will be shown lower in the list of paste edit.
*/
yieldTo?: readonly DocumentPasteEditKind[];
/**
* 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 DocumentPasteEditKind Kind} of the edit.
*/
constructor(insertText: string | SnippetString, title: string, kind: DocumentPasteEditKind);
}
/**
* TODO: Share with code action kind?
*/
class DocumentPasteEditKind {
static readonly Empty: DocumentPasteEditKind;
// TODO: Add `Text` any others?
private constructor(value: string);
readonly value: string;
append(...parts: string[]): CodeActionKind;
intersects(other: CodeActionKind): boolean;
contains(other: CodeActionKind): boolean;
}
interface DocumentPasteProviderMetadata {
/**
* List of {@link DocumentPasteEditKind kinds} that the provider may return in {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits}.
*
* The provider will only be invoked when one of these kinds is being requested. For normal pasting, all providers will be invoked.
*/
readonly providedPasteEditKinds: readonly DocumentPasteEditKind[];
/**
* 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 dropping content from outside the editor, such as
* from the operating system.
*/
readonly pasteMimeTypes?: 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;
}
}