From 1e590fb634aeee48c889bcb0edcda8e6e616db2c Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 14 Apr 2016 16:17:17 +0200 Subject: [PATCH] output: fix extensions output channel --- .../api/node/extHostOutputService.ts | 77 +++++++++++++------ .../workbench/parts/output/common/output.ts | 4 +- .../parts/output/common/outputServices.ts | 10 +-- 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/vs/workbench/api/node/extHostOutputService.ts b/src/vs/workbench/api/node/extHostOutputService.ts index 1d9cd3bb9d3..e30f2d1e047 100644 --- a/src/vs/workbench/api/node/extHostOutputService.ts +++ b/src/vs/workbench/api/node/extHostOutputService.ts @@ -5,43 +5,47 @@ 'use strict'; import {TPromise} from 'vs/base/common/winjs.base'; -import {onUnexpectedError} from 'vs/base/common/errors'; import {Remotable, IThreadService} from 'vs/platform/thread/common/thread'; -import {IOutputService, OUTPUT_EDITOR_INPUT_ID, IOutputChannel} from 'vs/workbench/parts/output/common/output'; -import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService'; +import {Registry} from 'vs/platform/platform'; +import {IOutputService, IOutputChannel, OUTPUT_PANEL_ID, Extensions, IOutputChannelRegistry} from 'vs/workbench/parts/output/common/output'; +import {IPartService} from 'vs/workbench/services/part/common/partService'; +import {IPanelService} from 'vs/workbench/services/panel/common/panelService'; export class ExtHostOutputChannel implements vscode.OutputChannel { private _proxy: MainThreadOutputService; - private _outputChannel: IOutputChannel; + private _name: string; + private _label: string; private _disposed: boolean; constructor(name: string, proxy: MainThreadOutputService, label?: string) { + this._name = name; + this._label = label; this._proxy = proxy; - this._outputChannel = proxy.getOutputChannel(name, label); } get name(): string { - return this._outputChannel.id; + return this._name; } dispose(): void { if (!this._disposed) { - this._outputChannel.clear(); - this._disposed = true; + this._proxy.clear(this._name).then(() => { + this._disposed = true; + }); } } append(value: string): void { - this._outputChannel.append(value); + this._proxy.append(this._name, this._label, value); } appendLine(value: string): void { - this._outputChannel.append(value + '\n'); + this.append(value + '\n'); } clear(): void { - this._outputChannel.clear(); + this._proxy.clear(this._name); } show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void { @@ -49,11 +53,11 @@ export class ExtHostOutputChannel implements vscode.OutputChannel { preserveFocus = columnOrPreserveFocus; } - this._outputChannel.show(preserveFocus); + this._proxy.reveal(this._name, preserveFocus); } hide(): void { - this._proxy.close(this._outputChannel.id); + this._proxy.close(this._name); } } @@ -79,24 +83,47 @@ export class ExtHostOutputService { export class MainThreadOutputService { private _outputService: IOutputService; - private _editorService: IWorkbenchEditorService; + private _partService: IPartService; + private _panelService: IPanelService; - constructor( @IOutputService outputService: IOutputService, @IWorkbenchEditorService editorService: IWorkbenchEditorService) { + constructor(@IOutputService outputService: IOutputService, + @IPartService partService: IPartService, + @IPanelService panelService: IPanelService + ) { this._outputService = outputService; - this._editorService = editorService; + this._partService = partService; + this._panelService = panelService; } - public getOutputChannel(channelId: string, channelLabel?: string): IOutputChannel { - return this._outputService.getChannel(channelId, channelLabel); + public append(channelId: string, label: string, value: string): TPromise { + this._getChannel(channelId, label).append(value); + return undefined; } - public close(channel: string): TPromise { - let editors = this._editorService.getVisibleEditors(); - for (let editor of editors) { - if (editor.input.getId() === OUTPUT_EDITOR_INPUT_ID) { - this._editorService.closeEditor(editor).done(null, onUnexpectedError); - return undefined; - } + public clear(channelId: string): TPromise { + this._getChannel(channelId).clear(); + return undefined; + } + + public reveal(channelId: string, preserveFocus: boolean): TPromise { + this._getChannel(channelId).show(preserveFocus); + return undefined; + } + + private _getChannel(channelId: string, label?: string): IOutputChannel { + if (!Registry.as(Extensions.OutputChannels).getChannels().some(channel => channel.id === channelId)) { + Registry.as(Extensions.OutputChannels).registerChannel(channelId, label || channelId); } + + return this._outputService.getChannel(channelId); + } + + public close(channelId: string): TPromise { + const panel = this._panelService.getActivePanel(); + if (panel && panel.getId() === OUTPUT_PANEL_ID && channelId === this._outputService.getActiveChannel().id ) { + this._partService.setPanelHidden(true); + } + + return undefined; } } diff --git a/src/vs/workbench/parts/output/common/output.ts b/src/vs/workbench/parts/output/common/output.ts index 4bdf301efa9..73d0fda4f93 100644 --- a/src/vs/workbench/parts/output/common/output.ts +++ b/src/vs/workbench/parts/output/common/output.ts @@ -56,9 +56,9 @@ export interface IOutputService { /** * Given the channel id returns the output channel instance. - * If label is passed then the output channel registry is not queried for the label of the channel. + * Channel should be first registered via OutputChannelRegistry. */ - getChannel(id: string, label?: string): IOutputChannel; + getChannel(id: string): IOutputChannel; /** * Returns the currently active channel. diff --git a/src/vs/workbench/parts/output/common/outputServices.ts b/src/vs/workbench/parts/output/common/outputServices.ts index 7d6506fefd9..40184e873c9 100644 --- a/src/vs/workbench/parts/output/common/outputServices.ts +++ b/src/vs/workbench/parts/output/common/outputServices.ts @@ -60,17 +60,13 @@ export class OutputService implements IOutputService { return this._onActiveOutputChannel.event; } - public getChannel(id: string, label?: string): IOutputChannel { - if (!label ) { - const channelData = Registry.as(Extensions.OutputChannels).getChannels().filter(channelData => channelData.id === id).pop(); - // If channel is not registered use the id as the label (extensions do not register output channels via registry) - label = channelData ? channelData.label : id; - } + public getChannel(id: string): IOutputChannel { + const channelData = Registry.as(Extensions.OutputChannels).getChannels().filter(channelData => channelData.id === id).pop(); const self = this; return { id, - label, + label: channelData ? channelData.label : id, get output() { return self.getOutput(id); },