UNPKG

@codingame/monaco-vscode-extensions-service-override

Version:

VSCode public API plugged on the monaco editor - extensions service-override

135 lines (131 loc) 6.41 kB
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6'; import { Registry } from '@codingame/monaco-vscode-api/vscode/vs/platform/registry/common/platform'; import { OUTPUT_VIEW_ID, Extensions, OutputChannelUpdateMode } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/output/common/output'; import { IOutputService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/output/common/output.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 { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri'; import { Disposable, MutableDisposable, toDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle'; import { Event } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event'; import { IViewsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/views/common/viewsService.service'; import { isNumber } from '@codingame/monaco-vscode-api/vscode/vs/base/common/types'; import { IConfigurationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/configuration/common/configuration.service'; import { StatusbarAlignment } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/statusbar/browser/statusbar'; import { IStatusbarService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/statusbar/browser/statusbar.service'; import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls'; var MainThreadOutputService_1; let MainThreadOutputService = class MainThreadOutputService extends Disposable { static { MainThreadOutputService_1 = this; } static { this._extensionIdPool = ( new Map()); } constructor( extHostContext, outputService, viewsService, configurationService, statusbarService ) { super(); this._outputStatusItem = this._register(( new MutableDisposable())); this._outputService = outputService; this._viewsService = viewsService; this._configurationService = configurationService; this._statusbarService = statusbarService; 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._outputStatusItem.value = undefined; }; 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, source: { 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) { return; } const viewsToShowQuietly = this._configurationService.getValue("workbench.view.showQuietly") ?? {}; if (!this._viewsService.isViewVisible(OUTPUT_VIEW_ID) && viewsToShowQuietly[OUTPUT_VIEW_ID]) { this._showChannelQuietly(channel); return; } this._outputService.showChannel(channel.id, preserveFocus); } _showChannelQuietly(channel) { const statusProperties = { name: ( localize(2638, "Show Output")), text: "$(output)", ariaLabel: ( localize(2639, "Show {0} Output Channel", channel.label)), command: `workbench.action.output.show.${channel.id}`, tooltip: ( localize(2640, "Show {0} Output Channel", channel.label)), kind: "prominent" }; if (!this._outputStatusItem.value) { this._outputStatusItem.value = this._statusbarService.addEntry(statusProperties, "status.view.showQuietly", StatusbarAlignment.RIGHT, { location: { id: "status.notifications", priority: Number.NEGATIVE_INFINITY }, alignment: StatusbarAlignment.LEFT }); } else { this._outputStatusItem.value.update(statusProperties); } } 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)), ( __param(3, IConfigurationService)), ( __param(4, IStatusbarService))], MainThreadOutputService); export { MainThreadOutputService };