@codingame/monaco-vscode-extensions-service-override
Version:
VSCode public API plugged on the monaco editor - extensions service-override
78 lines (75 loc) • 3.86 kB
JavaScript
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
import { OUTPUT_VIEW_ID, Extensions, OutputChannelUpdateMode } from 'vscode/vscode/vs/workbench/services/output/common/output';
import { IOutputService } from 'vscode/vscode/vs/workbench/services/output/common/output.service';
import { ExtHostContext, MainContext } from 'vscode/vscode/vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';
import { URI } from 'vscode/vscode/vs/base/common/uri';
import { Disposable, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
import { Event } from 'vscode/vscode/vs/base/common/event';
import { IViewsService } from 'vscode/vscode/vs/workbench/services/views/common/viewsService.service';
import { isNumber } from 'vscode/vscode/vs/base/common/types';
var MainThreadOutputService_1;
let MainThreadOutputService = class MainThreadOutputService extends Disposable {
static { MainThreadOutputService_1 = this; }
static { this._extensionIdPool = ( new Map()); }
constructor(extHostContext, outputService, viewsService) {
super();
this._outputService = outputService;
this._viewsService = viewsService;
this._proxy = ( extHostContext.getProxy(ExtHostContext.ExtHostOutputService));
const setVisibleChannel = () => {
const visibleChannel = this._viewsService.isViewVisible(OUTPUT_VIEW_ID) ? this._outputService.getActiveChannel() : undefined;
this._proxy.$setVisibleChannel(visibleChannel ? visibleChannel.id : null);
};
this._register(Event.any(this._outputService.onActiveOutputChannel, Event.filter(this._viewsService.onDidChangeViewVisibility, ({ id }) => id === OUTPUT_VIEW_ID))(() => setVisibleChannel()));
setVisibleChannel();
}
async $register(label, file, languageId, extensionId) {
const idCounter = (MainThreadOutputService_1._extensionIdPool.get(extensionId) || 0) + 1;
MainThreadOutputService_1._extensionIdPool.set(extensionId, idCounter);
const id = `extension-output-${extensionId}-#${idCounter}-${label}`;
const resource = URI.revive(file);
( Registry.as(Extensions.OutputChannels)).registerChannel({ id, label, file: resource, log: false, languageId, extensionId });
this._register(toDisposable(() => this.$dispose(id)));
return id;
}
async $update(channelId, mode, till) {
const channel = this._getChannel(channelId);
if (channel) {
if (mode === OutputChannelUpdateMode.Append) {
channel.update(mode);
}
else if (isNumber(till)) {
channel.update(mode, till);
}
}
}
async $reveal(channelId, preserveFocus) {
const channel = this._getChannel(channelId);
if (channel) {
this._outputService.showChannel(channel.id, preserveFocus);
}
}
async $close(channelId) {
if (this._viewsService.isViewVisible(OUTPUT_VIEW_ID)) {
const activeChannel = this._outputService.getActiveChannel();
if (activeChannel && channelId === activeChannel.id) {
this._viewsService.closeView(OUTPUT_VIEW_ID);
}
}
}
async $dispose(channelId) {
const channel = this._getChannel(channelId);
channel?.dispose();
}
_getChannel(channelId) {
return this._outputService.getChannel(channelId);
}
};
MainThreadOutputService = MainThreadOutputService_1 = __decorate([
extHostNamedCustomer(MainContext.MainThreadOutputService),
( __param(1, IOutputService)),
( __param(2, IViewsService))
], MainThreadOutputService);
export { MainThreadOutputService };