@codingame/monaco-vscode-api 1.83.15-next.0 → 1.83.15

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.
@@ -1,15 +1,34 @@
1
1
  import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
2
  import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
3
+ import { combinedDisposable, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
5
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
3
6
  import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
7
+ import { IExtensionManagementService, IExtensionGalleryService } from '../../../../platform/extensionManagement/common/extensionManagement.js';
8
+ import { IWorkbenchExtensionEnablementService } from '../../extensionManagement/common/extensionManagement.js';
9
+ import { areSameExtensions } from '../../../../platform/extensionManagement/common/extensionManagementUtil.js';
4
10
  import { createDecorator } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
11
+ import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
5
12
  import { IStorageService } from 'monaco-editor/esm/vs/platform/storage/common/storage.js';
6
13
  import { IURLService } from '../../../../platform/url/common/url.js';
14
+ import { IHostService } from '../../host/browser/host.js';
15
+ import { toExtensionDescription, IExtensionService } from '../common/extensions.js';
16
+ import { ExtensionIdentifier } from 'monaco-editor/esm/vs/platform/extensions/common/extensions.js';
7
17
  import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
8
18
  import { Extensions } from '../../../common/contributions.js';
9
19
  import { registerAction2, Action2, MenuId } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
10
20
  import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput.js';
21
+ import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
11
22
  import { IsWebContext } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkeys.js';
23
+ import { CancellationToken } from 'monaco-editor/esm/vs/base/common/cancellation.js';
24
+ import { ITelemetryService } from 'monaco-editor/esm/vs/platform/telemetry/common/telemetry.js';
25
+ import { IProductService } from 'monaco-editor/esm/vs/platform/product/common/productService.js';
26
+ import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
12
27
  var ExtensionUrlBootstrapHandler_1;
28
+ const FIVE_MINUTES = 5 * 60 * 1000;
29
+ const THIRTY_SECONDS = 30 * 1000;
30
+ const URL_TO_HANDLE = 'extensionUrlHandler.urlToHandle';
31
+ const USER_TRUSTED_EXTENSIONS_CONFIGURATION_KEY = 'extensions.confirmedUriHandlerExtensionIds';
13
32
  const USER_TRUSTED_EXTENSIONS_STORAGE_KEY = 'extensionUrlHandler.confirmedExtensions';
14
33
  function isExtensionId(value) {
15
34
  return /^[a-z0-9][a-z0-9\-]*\.[a-z0-9][a-z0-9\-]*$/i.test(value);
@@ -38,6 +57,293 @@ class UserTrustedExtensionIdStorage {
38
57
  }
39
58
  }
40
59
  const IExtensionUrlHandler = ( createDecorator('extensionUrlHandler'));
60
+ let ExtensionUrlHandler = class ExtensionUrlHandler {
61
+ constructor(urlService, extensionService, dialogService, notificationService, extensionManagementService, extensionEnablementService, hostService, galleryService, storageService, configurationService, progressService, telemetryService, productService) {
62
+ this.extensionService = extensionService;
63
+ this.dialogService = dialogService;
64
+ this.notificationService = notificationService;
65
+ this.extensionManagementService = extensionManagementService;
66
+ this.extensionEnablementService = extensionEnablementService;
67
+ this.hostService = hostService;
68
+ this.galleryService = galleryService;
69
+ this.storageService = storageService;
70
+ this.configurationService = configurationService;
71
+ this.progressService = progressService;
72
+ this.telemetryService = telemetryService;
73
+ this.productService = productService;
74
+ this.extensionHandlers = ( new Map());
75
+ this.uriBuffer = ( new Map());
76
+ this.userTrustedExtensionsStorage = ( new UserTrustedExtensionIdStorage(storageService));
77
+ const interval = setInterval(() => this.garbageCollect(), THIRTY_SECONDS);
78
+ const urlToHandleValue = this.storageService.get(URL_TO_HANDLE, 1 );
79
+ if (urlToHandleValue) {
80
+ this.storageService.remove(URL_TO_HANDLE, 1 );
81
+ this.handleURL(URI.revive(JSON.parse(urlToHandleValue)), { trusted: true });
82
+ }
83
+ this.disposable = combinedDisposable(urlService.registerHandler(this), toDisposable(() => clearInterval(interval)));
84
+ const cache = ExtensionUrlBootstrapHandler.cache;
85
+ setTimeout(() => cache.forEach(([uri, option]) => this.handleURL(uri, option)));
86
+ }
87
+ async handleURL(uri, options) {
88
+ if (!isExtensionId(uri.authority)) {
89
+ return false;
90
+ }
91
+ const extensionId = uri.authority;
92
+ this.telemetryService.publicLog2('uri_invoked/start', { extensionId });
93
+ const initialHandler = this.extensionHandlers.get(ExtensionIdentifier.toKey(extensionId));
94
+ let extensionDisplayName;
95
+ if (!initialHandler) {
96
+ const extension = await this.extensionService.getExtension(extensionId);
97
+ if (!extension) {
98
+ await this.handleUnhandledURL(uri, { id: extensionId }, options);
99
+ return true;
100
+ }
101
+ else {
102
+ extensionDisplayName = extension.displayName ?? '';
103
+ }
104
+ }
105
+ else {
106
+ extensionDisplayName = initialHandler.extensionDisplayName;
107
+ }
108
+ const trusted = options?.trusted
109
+ || this.productService.trustedExtensionProtocolHandlers?.includes(extensionId)
110
+ || this.didUserTrustExtension(ExtensionIdentifier.toKey(extensionId));
111
+ if (!trusted) {
112
+ let uriString = ( uri.toString(false));
113
+ if (uriString.length > 40) {
114
+ uriString = `${uriString.substring(0, 30)}...${uriString.substring(uriString.length - 5)}`;
115
+ }
116
+ const result = await this.dialogService.confirm({
117
+ message: ( localizeWithPath(
118
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
119
+ 'confirmUrl',
120
+ "Allow '{0}' extension to open this URI?",
121
+ extensionDisplayName
122
+ )),
123
+ checkbox: {
124
+ label: ( localizeWithPath(
125
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
126
+ 'rememberConfirmUrl',
127
+ "Don't ask again for this extension."
128
+ )),
129
+ },
130
+ detail: uriString,
131
+ primaryButton: ( localizeWithPath(
132
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
133
+ { key: 'open', comment: ['&& denotes a mnemonic'] },
134
+ "&&Open"
135
+ ))
136
+ });
137
+ if (!result.confirmed) {
138
+ this.telemetryService.publicLog2('uri_invoked/cancel', { extensionId });
139
+ return true;
140
+ }
141
+ if (result.checkboxChecked) {
142
+ this.userTrustedExtensionsStorage.add(ExtensionIdentifier.toKey(extensionId));
143
+ }
144
+ }
145
+ const handler = this.extensionHandlers.get(ExtensionIdentifier.toKey(extensionId));
146
+ if (handler) {
147
+ if (!initialHandler) {
148
+ return await this.handleURLByExtension(extensionId, handler, uri, options);
149
+ }
150
+ return false;
151
+ }
152
+ const timestamp = ( new Date()).getTime();
153
+ let uris = this.uriBuffer.get(ExtensionIdentifier.toKey(extensionId));
154
+ if (!uris) {
155
+ uris = [];
156
+ this.uriBuffer.set(ExtensionIdentifier.toKey(extensionId), uris);
157
+ }
158
+ uris.push({ timestamp, uri });
159
+ await this.extensionService.activateByEvent(`onUri:${ExtensionIdentifier.toKey(extensionId)}`, 1 );
160
+ return true;
161
+ }
162
+ registerExtensionHandler(extensionId, handler) {
163
+ this.extensionHandlers.set(ExtensionIdentifier.toKey(extensionId), handler);
164
+ const uris = this.uriBuffer.get(ExtensionIdentifier.toKey(extensionId)) || [];
165
+ for (const { uri } of uris) {
166
+ this.handleURLByExtension(extensionId, handler, uri);
167
+ }
168
+ this.uriBuffer.delete(ExtensionIdentifier.toKey(extensionId));
169
+ }
170
+ unregisterExtensionHandler(extensionId) {
171
+ this.extensionHandlers.delete(ExtensionIdentifier.toKey(extensionId));
172
+ }
173
+ async handleURLByExtension(extensionId, handler, uri, options) {
174
+ this.telemetryService.publicLog2('uri_invoked/end', { extensionId: ExtensionIdentifier.toKey(extensionId) });
175
+ return await handler.handleURL(uri, options);
176
+ }
177
+ async handleUnhandledURL(uri, extensionIdentifier, options) {
178
+ const installedExtensions = await this.extensionManagementService.getInstalled();
179
+ let extension = installedExtensions.find(e => areSameExtensions(e.identifier, extensionIdentifier));
180
+ if (!extension) {
181
+ let galleryExtension;
182
+ try {
183
+ galleryExtension = (await this.galleryService.getExtensions([extensionIdentifier], CancellationToken.None))[0] ?? undefined;
184
+ }
185
+ catch (err) {
186
+ return;
187
+ }
188
+ if (!galleryExtension) {
189
+ return;
190
+ }
191
+ this.telemetryService.publicLog2('uri_invoked/install_extension/start', { extensionId: extensionIdentifier.id });
192
+ const result = await this.dialogService.confirm({
193
+ message: ( localizeWithPath(
194
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
195
+ 'installAndHandle',
196
+ "Would you like to install '{0}' extension from '{1}' to open this URI?",
197
+ galleryExtension.displayName,
198
+ galleryExtension.publisherDisplayName
199
+ )),
200
+ detail: `${( localizeWithPath(
201
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
202
+ 'installDetail',
203
+ "'{0}' extension wants to open a URI:",
204
+ galleryExtension.displayName
205
+ ))}\n\n${( uri.toString())}`,
206
+ primaryButton: ( localizeWithPath(
207
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
208
+ { key: 'install and open', comment: ['&& denotes a mnemonic'] },
209
+ "&&Install and Open"
210
+ ))
211
+ });
212
+ if (!result.confirmed) {
213
+ this.telemetryService.publicLog2('uri_invoked/install_extension/cancel', { extensionId: extensionIdentifier.id });
214
+ return;
215
+ }
216
+ this.telemetryService.publicLog2('uri_invoked/install_extension/accept', { extensionId: extensionIdentifier.id });
217
+ try {
218
+ extension = await this.progressService.withProgress({
219
+ location: 15 ,
220
+ title: ( localizeWithPath(
221
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
222
+ 'Installing',
223
+ "Installing Extension '{0}'...",
224
+ galleryExtension.displayName || galleryExtension.name
225
+ ))
226
+ }, () => this.extensionManagementService.installFromGallery(galleryExtension));
227
+ }
228
+ catch (error) {
229
+ this.notificationService.error(error);
230
+ return;
231
+ }
232
+ }
233
+ if (!this.extensionEnablementService.isEnabled(extension)) {
234
+ this.telemetryService.publicLog2('uri_invoked/enable_extension/start', { extensionId: extensionIdentifier.id });
235
+ const result = await this.dialogService.confirm({
236
+ message: ( localizeWithPath(
237
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
238
+ 'enableAndHandle',
239
+ "Extension '{0}' is disabled. Would you like to enable the extension and open the URL?",
240
+ extension.manifest.displayName || extension.manifest.name
241
+ )),
242
+ detail: `${extension.manifest.displayName || extension.manifest.name} (${extensionIdentifier.id}) wants to open a URL:\n\n${( uri.toString())}`,
243
+ primaryButton: ( localizeWithPath(
244
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
245
+ { key: 'enableAndReload', comment: ['&& denotes a mnemonic'] },
246
+ "&&Enable and Open"
247
+ ))
248
+ });
249
+ if (!result.confirmed) {
250
+ this.telemetryService.publicLog2('uri_invoked/enable_extension/cancel', { extensionId: extensionIdentifier.id });
251
+ return;
252
+ }
253
+ this.telemetryService.publicLog2('uri_invoked/enable_extension/accept', { extensionId: extensionIdentifier.id });
254
+ await this.extensionEnablementService.setEnablement([extension], 8 );
255
+ }
256
+ if (this.extensionService.canAddExtension(toExtensionDescription(extension))) {
257
+ await this.waitUntilExtensionIsAdded(extensionIdentifier);
258
+ await this.handleURL(uri, { ...options, trusted: true });
259
+ }
260
+ else {
261
+ this.telemetryService.publicLog2('uri_invoked/activate_extension/start', { extensionId: extensionIdentifier.id });
262
+ const result = await this.dialogService.confirm({
263
+ message: ( localizeWithPath(
264
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
265
+ 'reloadAndHandle',
266
+ "Extension '{0}' is not loaded. Would you like to reload the window to load the extension and open the URL?",
267
+ extension.manifest.displayName || extension.manifest.name
268
+ )),
269
+ detail: `${extension.manifest.displayName || extension.manifest.name} (${extensionIdentifier.id}) wants to open a URL:\n\n${( uri.toString())}`,
270
+ primaryButton: ( localizeWithPath(
271
+ 'vs/workbench/services/extensions/browser/extensionUrlHandler',
272
+ { key: 'reloadAndOpen', comment: ['&& denotes a mnemonic'] },
273
+ "&&Reload Window and Open"
274
+ ))
275
+ });
276
+ if (!result.confirmed) {
277
+ this.telemetryService.publicLog2('uri_invoked/activate_extension/cancel', { extensionId: extensionIdentifier.id });
278
+ return;
279
+ }
280
+ this.telemetryService.publicLog2('uri_invoked/activate_extension/accept', { extensionId: extensionIdentifier.id });
281
+ this.storageService.store(URL_TO_HANDLE, JSON.stringify(uri.toJSON()), 1 , 1 );
282
+ await this.hostService.reload();
283
+ }
284
+ }
285
+ async waitUntilExtensionIsAdded(extensionId) {
286
+ if (!(await this.extensionService.getExtension(extensionId.id))) {
287
+ await ( new Promise((c, e) => {
288
+ const disposable = this.extensionService.onDidChangeExtensions(async () => {
289
+ try {
290
+ if (await this.extensionService.getExtension(extensionId.id)) {
291
+ disposable.dispose();
292
+ c();
293
+ }
294
+ }
295
+ catch (error) {
296
+ e(error);
297
+ }
298
+ });
299
+ }));
300
+ }
301
+ }
302
+ garbageCollect() {
303
+ const now = ( new Date()).getTime();
304
+ const uriBuffer = ( new Map());
305
+ this.uriBuffer.forEach((uris, extensionId) => {
306
+ uris = uris.filter(({ timestamp }) => now - timestamp < FIVE_MINUTES);
307
+ if (uris.length > 0) {
308
+ uriBuffer.set(extensionId, uris);
309
+ }
310
+ });
311
+ this.uriBuffer = uriBuffer;
312
+ }
313
+ didUserTrustExtension(id) {
314
+ if (( this.userTrustedExtensionsStorage.has(id))) {
315
+ return true;
316
+ }
317
+ return this.getConfirmedTrustedExtensionIdsFromConfiguration().indexOf(id) > -1;
318
+ }
319
+ getConfirmedTrustedExtensionIdsFromConfiguration() {
320
+ const trustedExtensionIds = this.configurationService.getValue(USER_TRUSTED_EXTENSIONS_CONFIGURATION_KEY);
321
+ if (!Array.isArray(trustedExtensionIds)) {
322
+ return [];
323
+ }
324
+ return trustedExtensionIds;
325
+ }
326
+ dispose() {
327
+ this.disposable.dispose();
328
+ this.extensionHandlers.clear();
329
+ this.uriBuffer.clear();
330
+ }
331
+ };
332
+ ExtensionUrlHandler = ( __decorate([
333
+ ( __param(0, IURLService)),
334
+ ( __param(1, IExtensionService)),
335
+ ( __param(2, IDialogService)),
336
+ ( __param(3, INotificationService)),
337
+ ( __param(4, IExtensionManagementService)),
338
+ ( __param(5, IWorkbenchExtensionEnablementService)),
339
+ ( __param(6, IHostService)),
340
+ ( __param(7, IExtensionGalleryService)),
341
+ ( __param(8, IStorageService)),
342
+ ( __param(9, IConfigurationService)),
343
+ ( __param(10, IProgressService)),
344
+ ( __param(11, ITelemetryService)),
345
+ ( __param(12, IProductService))
346
+ ], ExtensionUrlHandler));
41
347
  let ExtensionUrlBootstrapHandler = class ExtensionUrlBootstrapHandler {
42
348
  static { ExtensionUrlBootstrapHandler_1 = this; }
43
349
  static { this._cache = []; }
@@ -104,4 +410,4 @@ class ManageAuthorizedExtensionURIsAction extends Action2 {
104
410
  }
105
411
  }
106
412
  registerAction2(ManageAuthorizedExtensionURIsAction);
107
- export { IExtensionUrlHandler };
413
+ export { ExtensionUrlHandler, IExtensionUrlHandler };
@@ -1,7 +1,7 @@
1
1
  import { FileOperationError } from 'monaco-editor/esm/vs/platform/files/common/files.js';
2
2
  import { createDecorator } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
3
3
  import { VSBuffer } from 'monaco-editor/esm/vs/base/common/buffer.js';
4
- import { isUndefinedOrNull } from 'monaco-editor/esm/vs/base/common/types.js';
4
+ import { isUndefinedOrNull, areFunctions } from 'monaco-editor/esm/vs/base/common/types.js';
5
5
  const ITextFileService = ( createDecorator('textFileService'));
6
6
  class TextFileOperationError extends FileOperationError {
7
7
  static isTextFileOperationError(obj) {
@@ -13,6 +13,10 @@ class TextFileOperationError extends FileOperationError {
13
13
  this.options = options;
14
14
  }
15
15
  }
16
+ function isTextFileEditorModel(model) {
17
+ const candidate = model;
18
+ return areFunctions(candidate.setEncoding, candidate.getEncoding, candidate.save, candidate.revert, candidate.isDirty, candidate.getLanguageId);
19
+ }
16
20
  function stringToSnapshot(value) {
17
21
  let done = false;
18
22
  return {
@@ -42,4 +46,4 @@ function toBufferOrReadable(value) {
42
46
  }
43
47
  };
44
48
  }
45
- export { ITextFileService, TextFileOperationError, stringToSnapshot, toBufferOrReadable };
49
+ export { ITextFileService, TextFileOperationError, isTextFileEditorModel, stringToSnapshot, toBufferOrReadable };