@codingame/monaco-vscode-extensions-service-override
Version:
VSCode public API plugged on the monaco editor - extensions service-override
78 lines (74 loc) • 3.58 kB
JavaScript
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
import { ProgressLocation } from '@codingame/monaco-vscode-api/vscode/vs/platform/progress/common/progress';
import { IProgressService } from '@codingame/monaco-vscode-api/vscode/vs/platform/progress/common/progress.service';
import { ExtHostContext, MainContext } from '@codingame/monaco-vscode-api/vscode/vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';
import { ICommandService } from '@codingame/monaco-vscode-api/vscode/vs/platform/commands/common/commands.service';
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
import { onUnexpectedExternalError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
import { toAction } from '@codingame/monaco-vscode-api/vscode/vs/base/common/actions';
import { NotificationPriority } from '@codingame/monaco-vscode-api/vscode/vs/platform/notification/common/notification';
var MainThreadProgress_1;
let MainThreadProgress = class MainThreadProgress {
static {
MainThreadProgress_1 = this;
}
static {
this.URGENT_PROGRESS_SOURCES = ["vscode.github-authentication", "vscode.microsoft-authentication"];
}
constructor(extHostContext, progressService, _commandService) {
this._commandService = _commandService;
this._progress = ( new Map());
this._proxy = ( extHostContext.getProxy(ExtHostContext.ExtHostProgress));
this._progressService = progressService;
}
dispose() {
this._progress.forEach(handle => handle.resolve());
this._progress.clear();
}
async $startProgress(handle, options, extensionId) {
const task = this._createTask(handle);
if (options.location === ProgressLocation.Notification && extensionId) {
const sourceIsUrgent = MainThreadProgress_1.URGENT_PROGRESS_SOURCES.includes(extensionId);
const notificationOptions = {
...options,
priority: sourceIsUrgent ? NotificationPriority.URGENT : NotificationPriority.DEFAULT,
location: ProgressLocation.Notification,
secondaryActions: [toAction({
id: extensionId,
label: ( localize(2641, "Manage Extension")),
run: () => this._commandService.executeCommand("_extensions.manage", extensionId)
})]
};
options = notificationOptions;
}
try {
this._progressService.withProgress(options, task, () => this._proxy.$acceptProgressCanceled(handle));
} catch (err) {
onUnexpectedExternalError(err);
}
}
$progressReport(handle, message) {
const entry = this._progress.get(handle);
entry?.progress.report(message);
}
$progressEnd(handle) {
const entry = this._progress.get(handle);
if (entry) {
entry.resolve();
this._progress.delete(handle);
}
}
_createTask(handle) {
return progress => {
return ( new Promise(resolve => {
this._progress.set(handle, {
resolve,
progress
});
}));
};
}
};
MainThreadProgress = MainThreadProgress_1 = __decorate([extHostNamedCustomer(MainContext.MainThreadProgress), ( __param(1, IProgressService)), ( __param(2, ICommandService))], MainThreadProgress);
export { MainThreadProgress };