@theia/plugin 1.49.0 → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/plugin",
3
- "version": "1.49.0",
3
+ "version": "1.50.0",
4
4
  "description": "Theia - Plugin API",
5
5
  "types": "./src/theia.d.ts",
6
6
  "publishConfig": {
@@ -27,10 +27,10 @@
27
27
  "watch": "theiaext watch"
28
28
  },
29
29
  "devDependencies": {
30
- "@theia/ext-scripts": "1.49.0"
30
+ "@theia/ext-scripts": "1.50.0"
31
31
  },
32
32
  "nyc": {
33
33
  "extends": "../../configs/nyc.json"
34
34
  },
35
- "gitHead": "d413dadd87a70fce1c80df7eb22d9d2529cc129f"
35
+ "gitHead": "63585530b2e32af0ed4bac4edb5ff443bfc248b7"
36
36
  }
package/src/theia.d.ts CHANGED
@@ -26,10 +26,10 @@ import './theia.proposed.canonicalUriProvider';
26
26
  import './theia.proposed.customEditorMove';
27
27
  import './theia.proposed.diffCommand';
28
28
  import './theia.proposed.documentPaste';
29
- import './theia.proposed.dropMetadata';
30
29
  import './theia.proposed.editSessionIdentityProvider';
31
30
  import './theia.proposed.extensionsAny';
32
31
  import './theia.proposed.externalUriOpener';
32
+ import './theia.proposed.mappedEditsProvider';
33
33
  import './theia.proposed.notebookCellExecutionState';
34
34
  import './theia.proposed.notebookKernelSource';
35
35
  import './theia.proposed.notebookMessaging';
@@ -2740,6 +2740,12 @@ export module '@theia/plugin' {
2740
2740
  * Whether the current window is focused.
2741
2741
  */
2742
2742
  readonly focused: boolean;
2743
+
2744
+ /**
2745
+ * Whether the window has been interacted with recently. This will change
2746
+ * immediately on activity, or after a short time of user inactivity.
2747
+ */
2748
+ readonly active: boolean;
2743
2749
  }
2744
2750
 
2745
2751
  /**
@@ -7909,7 +7915,7 @@ export module '@theia/plugin' {
7909
7915
  * @param pattern A file glob pattern like `*.{ts,js}` that will be matched on file paths
7910
7916
  * relative to the base path.
7911
7917
  */
7912
- constructor(base: WorkspaceFolder | Uri | string, pattern: string)
7918
+ constructor(base: WorkspaceFolder | Uri | string, pattern: string);
7913
7919
  }
7914
7920
 
7915
7921
  /**
@@ -22,6 +22,47 @@
22
22
 
23
23
  export module '@theia/plugin' {
24
24
 
25
+ /**
26
+ * Identifies a {@linkcode DocumentDropEdit} or {@linkcode DocumentPasteEdit}
27
+ */
28
+ class DocumentDropOrPasteEditKind {
29
+ static readonly Empty: DocumentDropOrPasteEditKind;
30
+
31
+ private constructor(value: string);
32
+
33
+ /**
34
+ * The raw string value of the kind.
35
+ */
36
+ readonly value: string;
37
+
38
+ /**
39
+ * Create a new kind by appending additional scopes to the current kind.
40
+ *
41
+ * Does not modify the current kind.
42
+ */
43
+ append(...parts: string[]): DocumentDropOrPasteEditKind;
44
+
45
+ /**
46
+ * Checks if this kind intersects `other`.
47
+ *
48
+ * The kind `"text.plain"` for example intersects `text`, `"text.plain"` and `"text.plain.list"`,
49
+ * but not `"unicorn"`, or `"textUnicorn.plain"`.
50
+ *
51
+ * @param other Kind to check.
52
+ */
53
+ intersects(other: DocumentDropOrPasteEditKind): boolean;
54
+
55
+ /**
56
+ * Checks if `other` is a sub-kind of this `DocumentDropOrPasteEditKind`.
57
+ *
58
+ * The kind `"text.plain"` for example contains `"text.plain"` and `"text.plain.list"`,
59
+ * but not `"text"` or `"unicorn.text.plain"`.
60
+ *
61
+ * @param other Kind to check.
62
+ */
63
+ contains(other: DocumentDropOrPasteEditKind): boolean;
64
+ }
65
+
25
66
  /**
26
67
  * The reason why paste edits were requested.
27
68
  */
@@ -45,7 +86,7 @@ export module '@theia/plugin' {
45
86
  /**
46
87
  * Requested kind of paste edits to return.
47
88
  */
48
- readonly only: DocumentPasteEditKind | undefined;
89
+ readonly only: DocumentDropOrPasteEditKind | undefined;
49
90
 
50
91
  /**
51
92
  * The reason why paste edits were requested.
@@ -59,18 +100,18 @@ export module '@theia/plugin' {
59
100
  interface DocumentPasteEditProvider<T extends DocumentPasteEdit = DocumentPasteEdit> {
60
101
 
61
102
  /**
62
- * Optional method invoked after the user copies text in a file.
103
+ * Optional method invoked after the user copies from a {@link TextEditor text editor}.
63
104
  *
64
- * This allows the provider to attach copy metadata to the {@link DataTransfer}
65
- * which is then passed back to providers in {@linkcode provideDocumentPasteEdits}.
105
+ * This allows the provider to attach metadata about the copied text to the {@link DataTransfer}. This data
106
+ * transfer is then passed back to providers in {@linkcode provideDocumentPasteEdits}.
66
107
  *
67
- * Note that currently any changes to the {@linkcode DataTransfer} are isolated to the current editor session.
68
- * This means that added metadata cannot be seen by other applications.
108
+ * Note that currently any changes to the {@linkcode DataTransfer} are isolated to the current editor window.
109
+ * This means that any added metadata cannot be seen by other editor windows or by other applications.
69
110
  *
70
- * @param document Document where the copy took place.
111
+ * @param document Text document where the copy took place.
71
112
  * @param ranges Ranges being copied in {@linkcode document}.
72
- * @param dataTransfer The data transfer associated with the copy. You can store additional values on this for later use in {@linkcode provideDocumentPasteEdits}.
73
- * This object is only valid for the duration of this method.
113
+ * @param dataTransfer The data transfer associated with the copy. You can store additional values on this for
114
+ * later use in {@linkcode provideDocumentPasteEdits}. This object is only valid for the duration of this method.
74
115
  * @param token A cancellation token.
75
116
  *
76
117
  * @return Optional thenable that resolves when all changes to the `dataTransfer` are complete.
@@ -78,26 +119,29 @@ export module '@theia/plugin' {
78
119
  prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable<void>;
79
120
 
80
121
  /**
81
- * Invoked before the user pastes into a document.
122
+ * Invoked before the user pastes into a {@link TextEditor text editor}.
82
123
  *
83
124
  * Returned edits can replace the standard pasting behavior.
84
125
  *
85
126
  * @param document Document being pasted into
86
127
  * @param ranges Range in the {@linkcode document} to paste into.
87
- * @param dataTransfer The {@link DataTransfer data transfer} associated with the paste. This object is only valid for the duration of the paste operation.
128
+ * @param dataTransfer The {@link DataTransfer data transfer} associated with the paste. This object is only
129
+ * valid for the duration of the paste operation.
88
130
  * @param context Additional context for the paste.
89
131
  * @param token A cancellation token.
90
132
  *
91
- * @return Set of potential {@link DocumentPasteEdit edits} that apply the paste. Return `undefined` to use standard pasting.
133
+ * @return Set of potential {@link DocumentPasteEdit edits} that can apply the paste. Only a single returned
134
+ * {@linkcode DocumentPasteEdit} is applied at a time. If multiple edits are returned from all providers, then
135
+ * the first is automatically applied and a widget is shown that lets the user switch to the other edits.
92
136
  */
93
- provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext,
94
- token: CancellationToken): ProviderResult<T[]>;
137
+ provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext, token: CancellationToken):
138
+ ProviderResult<T[]>;
95
139
 
96
140
  /**
97
141
  * Optional method which fills in the {@linkcode DocumentPasteEdit.additionalEdit} before the edit is applied.
98
142
  *
99
143
  * This is called once per edit and should be used if generating the complete edit may take a long time.
100
- * Resolve can only be used to change {@link DocumentPasteEdit.additionalEdit}.
144
+ * Resolve can only be used to change {@linkcode DocumentPasteEdit.additionalEdit}.
101
145
  *
102
146
  * @param pasteEdit The {@linkcode DocumentPasteEdit} to resolve.
103
147
  * @param token A cancellation token.
@@ -109,7 +153,7 @@ export module '@theia/plugin' {
109
153
  }
110
154
 
111
155
  /**
112
- * An edit applied on paste.
156
+ * An edit the applies a paste operation.
113
157
  */
114
158
  class DocumentPasteEdit {
115
159
 
@@ -119,14 +163,14 @@ export module '@theia/plugin' {
119
163
  title: string;
120
164
 
121
165
  /**
122
- * {@link DocumentPasteEditKind Kind} of the edit.
123
- *
124
- * Used to identify specific types of edits.
166
+ * {@link DocumentDropOrPasteEditKind Kind} of the edit.
125
167
  */
126
- kind: DocumentPasteEditKind;
168
+ kind: DocumentDropOrPasteEditKind;
127
169
 
128
170
  /**
129
171
  * The text or snippet to insert at the pasted locations.
172
+ *
173
+ * If your edit requires more advanced insertion logic, set this to an empty string and provide an {@link DocumentPasteEdit.additionalEdit additional edit} instead.
130
174
  */
131
175
  insertText: string | SnippetString;
132
176
 
@@ -136,46 +180,33 @@ export module '@theia/plugin' {
136
180
  additionalEdit?: WorkspaceEdit;
137
181
 
138
182
  /**
139
- * Controls the ordering of paste edits provided by multiple providers.
183
+ * Controls ordering when multiple paste edits can potentially be applied.
140
184
  *
141
- * If this edit yields to another, it will be shown lower in the list of paste edit.
185
+ * If this edit yields to another, it will be shown lower in the list of possible paste edits shown to the user.
142
186
  */
143
- yieldTo?: readonly DocumentPasteEditKind[];
187
+ yieldTo?: readonly DocumentDropOrPasteEditKind[];
144
188
 
145
189
  /**
146
190
  * Create a new paste edit.
147
191
  *
148
192
  * @param insertText The text or snippet to insert at the pasted locations.
149
193
  * @param title Human readable label that describes the edit.
150
- * @param kind {@link DocumentPasteEditKind Kind} of the edit.
194
+ * @param kind {@link DocumentDropOrPasteEditKind Kind} of the edit.
151
195
  */
152
- constructor(insertText: string | SnippetString, title: string, kind: DocumentPasteEditKind);
196
+ constructor(insertText: string | SnippetString, title: string, kind: DocumentDropOrPasteEditKind);
153
197
  }
154
198
 
155
199
  /**
156
- * TODO: Share with code action kind?
200
+ * Provides additional metadata about how a {@linkcode DocumentPasteEditProvider} works.
157
201
  */
158
- class DocumentPasteEditKind {
159
- static readonly Empty: DocumentPasteEditKind;
160
-
161
- // TODO: Add `Text` any others?
162
-
163
- private constructor(value: string);
164
-
165
- readonly value: string;
166
-
167
- append(...parts: string[]): CodeActionKind;
168
- intersects(other: CodeActionKind): boolean;
169
- contains(other: CodeActionKind): boolean;
170
- }
171
-
172
202
  interface DocumentPasteProviderMetadata {
173
203
  /**
174
- * List of {@link DocumentPasteEditKind kinds} that the provider may return in {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits}.
204
+ * List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in
205
+ * {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits}.
175
206
  *
176
- * The provider will only be invoked when one of these kinds is being requested. For normal pasting, all providers will be invoked.
207
+ * This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested.
177
208
  */
178
- readonly providedPasteEditKinds: readonly DocumentPasteEditKind[];
209
+ readonly providedPasteEditKinds: readonly DocumentDropOrPasteEditKind[];
179
210
 
180
211
  /**
181
212
  * Mime types that {@linkcode DocumentPasteEditProvider.prepareDocumentPaste prepareDocumentPaste} may add on copy.
@@ -190,12 +221,80 @@ export module '@theia/plugin' {
190
221
  * Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench.
191
222
  *
192
223
  * Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@linkcode DataTransfer}.
193
- * Note that {@linkcode DataTransferFile} entries are only created when dropping content from outside the editor, such as
224
+ * Note that {@linkcode DataTransferFile} entries are only created when pasting content from outside the editor, such as
194
225
  * from the operating system.
195
226
  */
196
227
  readonly pasteMimeTypes?: readonly string[];
197
228
  }
198
229
 
230
+ /**
231
+ * TODO on finalization:
232
+ * - Add ctor(insertText: string | SnippetString, title?: string, kind?: DocumentDropOrPasteEditKind); Can't be done as this is an extension to an existing class
233
+ */
234
+
235
+ export interface DocumentDropEdit {
236
+ /**
237
+ * Human readable label that describes the edit.
238
+ */
239
+ title?: string;
240
+
241
+ /**
242
+ * {@link DocumentDropOrPasteEditKind Kind} of the edit.
243
+ */
244
+ kind: DocumentDropOrPasteEditKind;
245
+
246
+ /**
247
+ * Controls the ordering or multiple edits. If this provider yield to edits, it will be shown lower in the list.
248
+ */
249
+ yieldTo?: readonly DocumentDropOrPasteEditKind[];
250
+ }
251
+
252
+ export interface DocumentDropEditProvider<T extends DocumentDropEdit = DocumentDropEdit> {
253
+ // Overload that allows returning multiple edits
254
+ // Will be merged in on finalization
255
+ provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken):
256
+ ProviderResult<DocumentDropEdit | DocumentDropEdit[]>;
257
+
258
+ /**
259
+ * Optional method which fills in the {@linkcode DocumentDropEdit.additionalEdit} before the edit is applied.
260
+ *
261
+ * This is called once per edit and should be used if generating the complete edit may take a long time.
262
+ * Resolve can only be used to change {@link DocumentDropEdit.additionalEdit}.
263
+ *
264
+ * @param pasteEdit The {@linkcode DocumentDropEdit} to resolve.
265
+ * @param token A cancellation token.
266
+ *
267
+ * @returns The resolved edit or a thenable that resolves to such. It is OK to return the given
268
+ * `edit`. If no result is returned, the given `edit` is used.
269
+ */
270
+ resolveDocumentDropEdit?(edit: T, token: CancellationToken): ProviderResult<T>;
271
+ }
272
+
273
+ /**
274
+ * Provides additional metadata about how a {@linkcode DocumentDropEditProvider} works.
275
+ */
276
+ export interface DocumentDropEditProviderMetadata {
277
+ /**
278
+ * List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in {@linkcode DocumentDropEditProvider.provideDocumentDropEdits provideDocumentDropEdits}.
279
+ *
280
+ * This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested.
281
+ */
282
+ readonly providedDropEditKinds?: readonly DocumentDropOrPasteEditKind[];
283
+
284
+ /**
285
+ * List of {@link DataTransfer} mime types that the provider can handle.
286
+ *
287
+ * This can either be an exact mime type such as `image/png`, or a wildcard pattern such as `image/*`.
288
+ *
289
+ * Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench.
290
+ *
291
+ * Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@link DataTransfer}.
292
+ * Note that {@link DataTransferFile} entries are only created when dropping content from outside the editor, such as
293
+ * from the operating system.
294
+ */
295
+ readonly dropMimeTypes: readonly string[];
296
+ }
297
+
199
298
  namespace languages {
200
299
  /**
201
300
  * Registers a new {@linkcode DocumentPasteEditProvider}.
@@ -208,5 +307,10 @@ export module '@theia/plugin' {
208
307
  * @stubbed
209
308
  */
210
309
  export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable;
310
+
311
+ /**
312
+ * Overload which adds extra metadata. Will be removed on finalization.
313
+ */
314
+ export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider, metadata?: DocumentDropEditProviderMetadata): Disposable;
211
315
  }
212
316
  }
@@ -0,0 +1,59 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2024 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /*---------------------------------------------------------------------------------------------
18
+ * Copyright (c) Microsoft Corporation. All rights reserved.
19
+ * Licensed under the MIT License. See License.txt in the project root for license information.
20
+ *--------------------------------------------------------------------------------------------*/
21
+
22
+ export module '@theia/plugin' {
23
+
24
+ export interface DocumentContextItem {
25
+ readonly uri: Uri;
26
+ readonly version: number;
27
+ readonly ranges: Range[];
28
+ }
29
+
30
+ export interface MappedEditsContext {
31
+ documents: DocumentContextItem[][];
32
+ }
33
+
34
+ /**
35
+ * Interface for providing mapped edits for a given document.
36
+ */
37
+ export interface MappedEditsProvider {
38
+ /**
39
+ * Provide mapped edits for a given document.
40
+ * @param document The document to provide mapped edits for.
41
+ * @param codeBlocks Code blocks that come from an LLM's reply.
42
+ * "Insert at cursor" in the panel chat only sends one edit that the user clicks on, but inline chat can send multiple blocks
43
+ * and let the lang server decide what to do with them.
44
+ * @param context The context for providing mapped edits.
45
+ * @param token A cancellation token.
46
+ * @returns A provider result of text edits.
47
+ */
48
+ provideMappedEdits(
49
+ document: TextDocument,
50
+ codeBlocks: string[],
51
+ context: MappedEditsContext,
52
+ token: CancellationToken
53
+ ): ProviderResult<WorkspaceEdit | null>;
54
+ }
55
+
56
+ export namespace chat {
57
+ export function registerMappedEditsProvider(documentSelector: DocumentSelector, provider: MappedEditsProvider): Disposable;
58
+ }
59
+ }
@@ -1,74 +0,0 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- /*---------------------------------------------------------------------------------------------
18
- * Copyright (c) Microsoft Corporation. All rights reserved.
19
- * Licensed under the MIT License. See License.txt in the project root for license information.
20
- *--------------------------------------------------------------------------------------------*/
21
- // code copied and modified from https://github.com/microsoft/vscode/blob/1.79.0/src/vscode-dts/vscode.proposed.dropMetadata.d.ts
22
-
23
- export module '@theia/plugin' {
24
-
25
- // https://github.com/microsoft/vscode/issues/179430
26
-
27
- export interface DocumentDropEdit {
28
-
29
- /**
30
- * Human readable label that describes the edit.
31
- */
32
- title?: string;
33
-
34
- /**
35
- * {@link DocumentPasteEditKind Kind} of the edit.
36
- *
37
- * Used to identify specific types of edits.
38
- *
39
- * TODO: use own type?
40
- */
41
- kind: DocumentPasteEditKind;
42
-
43
- /**
44
- * The mime type from the {@link DataTransfer} that this edit applies.
45
- */
46
- handledMimeType?: string;
47
-
48
- /**
49
- * Controls the ordering or multiple paste edits. If this provider yield to edits, it will be shown lower in the list.
50
- */
51
- yieldTo?: ReadonlyArray<DocumentPasteEditKind>;
52
- }
53
-
54
- export interface DocumentDropEditProviderMetadata {
55
- readonly providedDropEditKinds?: readonly DocumentPasteEditKind[];
56
-
57
- /**
58
- * List of data transfer types that the provider supports.
59
- *
60
- * This can either be an exact mime type such as `image/png`, or a wildcard pattern such as `image/*`.
61
- *
62
- * Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench.
63
- *
64
- * Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@link DataTransfer}.
65
- * Note that {@link DataTransferFile} entries are only created when dropping content from outside the editor, such as
66
- * from the operating system.
67
- */
68
- readonly dropMimeTypes: readonly string[];
69
- }
70
-
71
- export namespace languages {
72
- export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider, metadata?: DocumentDropEditProviderMetadata): Disposable;
73
- }
74
- }