Skip to content

Commit 85294e4

Browse files
committed
output: move append() to IOutputChannel
1 parent 8317c45 commit 85294e4

8 files changed

Lines changed: 61 additions & 44 deletions

File tree

src/vs/workbench/api/node/extHostOutputService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MainThreadOutputService {
8888
}
8989

9090
public append(channel: string, value: string): TPromise<void> {
91-
this._outputService.append(channel, value);
91+
this._outputService.getOutputChannel(channel).append(value);
9292
return undefined;
9393
}
9494

src/vs/workbench/parts/extensions/electron-browser/extensionsWidgets.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
1515
import { IOutputService } from 'vs/workbench/parts/output/common/output';
1616
import { IExtensionService, IMessage } from 'vs/platform/extensions/common/extensions';
1717
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
18-
import { IExtensionsService, ExtensionsLabel, IExtension, IExtensionManifest } from 'vs/workbench/parts/extensions/common/extensions';
18+
import { IExtensionsService, ExtensionsLabel, ExtensionsChannelId, IExtension, IExtensionManifest } from 'vs/workbench/parts/extensions/common/extensions';
1919
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
2020
import { getOutdatedExtensions } from 'vs/workbench/parts/extensions/common/extensionsUtil';
2121

@@ -115,7 +115,8 @@ export class ExtensionsStatusbarItem implements IStatusbarItem {
115115
const name = extension && extension.name;
116116
const message = name ? `${ name }: ${ m.message }` : m.message;
117117

118-
this.outputService.append(ExtensionsLabel, message);
118+
const outputChannel = this.outputService.getOutputChannel(ExtensionsChannelId);
119+
outputChannel.append(message);
119120
this.outputService.showOutput(ExtensionsLabel, true);
120121
});
121122
});

src/vs/workbench/parts/git/browser/gitOutput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class GitOutput implements ext.IWorkbenchContribution {
4747
}
4848

4949
private onOutput(output: string): void {
50-
this.outputService.append('Git', output);
50+
this.outputService.getOutputChannel('Git').append(output);
5151
}
5252

5353
public dispose(): void {

src/vs/workbench/parts/output/common/output.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const MAX_OUTPUT_LENGTH = 10000 /* Max. number of output lines to show in
4343
*/
4444
export interface IOutputEvent {
4545
output: string;
46-
channel?: string;
46+
channelId?: string;
4747
}
4848

4949
export var IOutputService = createDecorator<IOutputService>(OUTPUT_SERVICE_ID);
@@ -53,10 +53,8 @@ export var IOutputService = createDecorator<IOutputService>(OUTPUT_SERVICE_ID);
5353
*/
5454
export interface IOutputService {
5555
serviceId: ServiceIdentifier<any>;
56-
/**
57-
* Appends output to the given channel.
58-
*/
59-
append(channel: string, output: string): void;
56+
57+
getOutputChannel(id: string): IOutputChannel;
6058

6159
/**
6260
* Returns the received output.
@@ -110,6 +108,10 @@ export interface IOutputService {
110108

111109
export interface IOutputChannel {
112110

111+
/**
112+
* Appends output to the channel.
113+
*/
114+
append(output: string): void;
113115

114116
}
115117

src/vs/workbench/parts/output/common/outputEditorInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class OutputEditorInput extends StringEditorInput {
8686
}
8787

8888
private onOutputReceived(e: IOutputEvent): void {
89-
if (this.outputSet && e.channel === this.channel) {
89+
if (this.outputSet && e.channelId === this.channel) {
9090
if (e.output) {
9191
this.bufferedOutput = strings.appendWithLimit(this.bufferedOutput, e.output, MAX_OUTPUT_LENGTH);
9292
this.scheduleOutputAppend();

src/vs/workbench/parts/output/common/outputServices.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {IInstantiationService} from 'vs/platform/instantiation/common/instantiat
1313
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
1414
import {Registry} from 'vs/platform/platform';
1515
import {EditorOptions} from 'vs/workbench/common/editor';
16-
import {IOutputEvent, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH} from 'vs/workbench/parts/output/common/output';
16+
import {IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH} from 'vs/workbench/parts/output/common/output';
1717
import {OutputEditorInput} from 'vs/workbench/parts/output/common/outputEditorInput';
1818
import {OutputPanel} from 'vs/workbench/parts/output/browser/outputPanel';
1919
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
@@ -60,24 +60,31 @@ export class OutputService implements IOutputService {
6060
return this._onActiveOutputChannel.event;
6161
}
6262

63-
public append(channel: string, output: string): void {
63+
public getOutputChannel(id: string): IOutputChannel {
64+
return {
65+
append: (output: string) => this.append(id, output),
66+
clear: () => this.clearOutput(id)
67+
};
68+
}
69+
70+
private append(channelId: string, output: string): void {
6471

6572
// Initialize
66-
if (!this.receivedOutput[channel]) {
67-
this.receivedOutput[channel] = '';
73+
if (!this.receivedOutput[channelId]) {
74+
this.receivedOutput[channelId] = '';
6875

69-
this._onOutputChannel.fire(channel); // emit event that we have a new channel
76+
this._onOutputChannel.fire(channelId); // emit event that we have a new channel
7077
}
7178

7279
// Sanitize
7380
output = strings.removeAnsiEscapeCodes(output);
7481

7582
// Store
7683
if (output) {
77-
this.receivedOutput[channel] = strings.appendWithLimit(this.receivedOutput[channel], output, MAX_OUTPUT_LENGTH);
84+
this.receivedOutput[channelId] = strings.appendWithLimit(this.receivedOutput[channelId], output, MAX_OUTPUT_LENGTH);
7885
}
7986

80-
this._onOutput.fire({ output: output, channel });
87+
this._onOutput.fire({ output: output, channelId: channelId });
8188
}
8289

8390
public getOutput(channel: string): string {
@@ -95,7 +102,7 @@ export class OutputService implements IOutputService {
95102
public clearOutput(channel: string): void {
96103
this.receivedOutput[channel] = '';
97104

98-
this._onOutput.fire({ channel: channel, output: null /* indicator to clear output */ });
105+
this._onOutput.fire({ channelId: channel, output: null /* indicator to clear output */ });
99106
}
100107

101108
public showOutput(channel: string, preserveFocus?: boolean): TPromise<IEditor> {

src/vs/workbench/parts/tasks/electron-browser/task.contribution.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,21 @@ class ConfigureTaskRunnerAction extends Action {
182182
}
183183
let contentPromise: TPromise<string>;
184184
if (selection.autoDetect) {
185-
this.outputService.showOutput(TaskService.OutputChannel);
186-
this.outputService.append(TaskService.OutputChannel, nls.localize('ConfigureTaskRunnerAction.autoDetecting', 'Auto detecting tasks for {0}', selection.id) + '\n');
185+
this.outputService.showOutput(TaskService.OutputChannelId);
186+
const outputChannel = this.outputService.getOutputChannel(TaskService.OutputChannelId);
187+
outputChannel.append(nls.localize('ConfigureTaskRunnerAction.autoDetecting', 'Auto detecting tasks for {0}', selection.id) + '\n');
187188
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, new SystemVariables(this.editorService, this.contextService));
188189
contentPromise = detector.detect(false, selection.id).then((value) => {
189190
let config = value.config;
190191
if (value.stderr && value.stderr.length > 0) {
191192
value.stderr.forEach((line) => {
192-
this.outputService.append(TaskService.OutputChannel, line + '\n');
193+
outputChannel.append(line + '\n');
193194
});
194195
this.messageService.show(Severity.Warning, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Using default template. Consult the task output for details.'));
195196
return selection.content;
196197
} else if (config) {
197198
if (value.stdout && value.stdout.length > 0) {
198-
value.stdout.forEach(line => this.outputService.append(TaskService.OutputChannel, line + '\n'));
199+
value.stdout.forEach(line => outputChannel.append(line + '\n'));
199200
}
200201
let content = JSON.stringify(config, null, '\t');
201202
content = [
@@ -287,7 +288,7 @@ class ShowLogAction extends AbstractTaskAction {
287288
}
288289

289290
public run(): Promise {
290-
return this.outputService.showOutput(TaskService.OutputChannel);
291+
return this.outputService.showOutput(TaskService.OutputChannelId);
291292
}
292293
}
293294

@@ -452,7 +453,7 @@ interface TaskServiceEventData {
452453
class TaskService extends EventEmitter implements ITaskService {
453454
public serviceId = ITaskService;
454455
public static SERVICE_ID: string = 'taskService';
455-
public static OutputChannel:string = 'tasks';
456+
public static OutputChannelId:string = 'tasks';
456457
public static OutputChannelLabel:string = nls.localize('tasks', "Tasks");
457458

458459
private modeService: IModeService;
@@ -545,8 +546,9 @@ class TaskService extends EventEmitter implements ITaskService {
545546
}
546547
}
547548
if (isAffected) {
548-
this.outputService.append(TaskService.OutputChannel, nls.localize('TaskSystem.invalidTaskJson', 'Error: The content of the tasks.json file has syntax errors. Please correct them before executing a task.\n'));
549-
this.outputService.showOutput(TaskService.OutputChannel, true);
549+
const outputChannel = this.outputService.getOutputChannel(TaskService.OutputChannelId);
550+
outputChannel.append(nls.localize('TaskSystem.invalidTaskJson', 'Error: The content of the tasks.json file has syntax errors. Please correct them before executing a task.\n'));
551+
this.outputService.showOutput(TaskService.OutputChannelId, true);
550552
return TPromise.wrapError({});
551553
}
552554
}
@@ -594,7 +596,7 @@ class TaskService extends EventEmitter implements ITaskService {
594596
if (config.buildSystem === 'service') {
595597
result = new LanguageServiceTaskSystem(<LanguageServiceTaskConfiguration>config, this.telemetryService, this.modeService);
596598
} else if (this.isRunnerConfig(config)) {
597-
result = new ProcessRunnerSystem(<FileConfig.ExternalTaskRunnerConfiguration>config, variables, this.markerService, this.modelService, this.telemetryService, this.outputService, TaskService.OutputChannel, clearOutput);
599+
result = new ProcessRunnerSystem(<FileConfig.ExternalTaskRunnerConfiguration>config, variables, this.markerService, this.modelService, this.telemetryService, this.outputService, TaskService.OutputChannelId, clearOutput);
598600
}
599601
if (result === null) {
600602
this._taskSystemPromise = null;
@@ -618,9 +620,10 @@ class TaskService extends EventEmitter implements ITaskService {
618620
if (stderr && stderr.length > 0) {
619621
stderr.forEach((line) => {
620622
result = false;
621-
this.outputService.append(TaskService.OutputChannel, line + '\n');
623+
const outputChannel = this.outputService.getOutputChannel(TaskService.OutputChannelId);
624+
outputChannel.append(line + '\n');
622625
});
623-
this.outputService.showOutput(TaskService.OutputChannel, true);
626+
this.outputService.showOutput(TaskService.OutputChannelId, true);
624627
}
625628
return result;
626629
}
@@ -784,7 +787,7 @@ class TaskService extends EventEmitter implements ITaskService {
784787
this.messageService.show(Severity.Error, nls.localize('TaskSystem.unknownError', 'An error has occurred while running a task. See task log for details.'));
785788
}
786789
if (showOutput) {
787-
this.outputService.showOutput(TaskService.OutputChannel, true);
790+
this.outputService.showOutput(TaskService.OutputChannelId, true);
788791
}
789792
}
790793
}
@@ -832,7 +835,7 @@ if (Env.enableTasks) {
832835

833836
// Output channel
834837
let outputChannelRegistry = <IOutputChannelRegistry>Registry.as(OutputExt.OutputChannels);
835-
outputChannelRegistry.registerChannel(TaskService.OutputChannel, TaskService.OutputChannelLabel);
838+
outputChannelRegistry.registerChannel(TaskService.OutputChannelId, TaskService.OutputChannelLabel);
836839

837840
(<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(TaskServiceParticipant);
838841

src/vs/workbench/parts/tasks/node/processRunnerSystem.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
3939
private markerService: IMarkerService;
4040
private modelService: IModelService;
4141
private outputService: IOutputService;
42-
private outputChannel: string;
42+
private outputChannelId: string;
4343
private telemetryService: ITelemetryService;
4444

4545
private validationStatus: ValidationStatus;
@@ -57,7 +57,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
5757
this.variables = variables;
5858
this.markerService = markerService;
5959
this.modelService = modelService;
60-
this.outputChannel = outputChannel;
60+
this.outputChannelId = outputChannel;
6161
this.outputService = outputService;
6262
this.telemetryService = telemetryService;
6363

@@ -77,7 +77,7 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
7777
this.defaultTestTaskIdentifier = parseResult.defaultTestTaskIdentifier;
7878

7979
if (!this.validationStatus.isOK()) {
80-
this.outputService.showOutput(this.outputChannel, true);
80+
this.outputService.showOutput(this.outputChannelId, true);
8181
}
8282
}
8383

@@ -177,10 +177,12 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
177177
throw err;
178178
} else if (err instanceof Error) {
179179
let error = <Error>err;
180-
this.outputService.append(this.outputChannel, error.message);
180+
const outputChannel = this.outputService.getOutputChannel(this.outputChannelId);
181+
outputChannel.append(error.message);
181182
throw new TaskError(Severity.Error, error.message, TaskErrors.UnknownError);
182183
} else {
183-
this.outputService.append(this.outputChannel, err.toString());
184+
const outputChannel = this.outputService.getOutputChannel(this.outputChannelId);
185+
outputChannel.append(err.toString());
184186
throw new TaskError(Severity.Error, nls.localize('TaskRunnerSystem.unknownError', 'A unknown error has occurred while executing a task. See task output log for details.'), TaskErrors.UnknownError);
185187
}
186188
}
@@ -267,7 +269,8 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
267269
return this.handleError(task, error);
268270
}, (progress: LineData) => {
269271
let line = Strings.removeAnsiEscapeCodes(progress.line);
270-
this.outputService.append(this.outputChannel, line + '\n');
272+
const outputChannel = this.outputService.getOutputChannel(this.outputChannelId);
273+
outputChannel.append(line + '\n');
271274
watchingProblemMatcher.processLine(line);
272275
if (delayer === null) {
273276
delayer = new Async.Delayer(3000);
@@ -304,7 +307,8 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
304307
return this.handleError(task, error);
305308
}, (progress) => {
306309
let line = Strings.removeAnsiEscapeCodes(progress.line);
307-
this.outputService.append(this.outputChannel, line + '\n');
310+
const outputChannel = this.outputService.getOutputChannel(this.outputChannelId);
311+
outputChannel.append(line + '\n');
308312
startStopProblemMatcher.processLine(line);
309313
});
310314
return { promise };
@@ -321,16 +325,16 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
321325
if (error.error && !error.terminated) {
322326
let args:string = this.configuration.args ? this.configuration.args.join(' ') : '';
323327
this.log(nls.localize('TaskRunnerSystem.childProcessError', 'Failed to launch external program {0} {1}.', this.configuration.command, args));
324-
this.outputService.append(this.outputChannel, error.error.message);
328+
this.outputService.getOutputChannel(this.outputChannelId).append(error.error.message);
325329
makeVisible = true;
326330
}
327331

328332
if (error.stdout) {
329-
this.outputService.append(this.outputChannel, error.stdout);
333+
this.outputService.getOutputChannel(this.outputChannelId).append(error.stdout);
330334
makeVisible = true;
331335
}
332336
if (error.stderr) {
333-
this.outputService.append(this.outputChannel, error.stderr);
337+
this.outputService.getOutputChannel(this.outputChannelId).append(error.stderr);
334338
makeVisible = true;
335339
}
336340
makeVisible = this.checkTerminated(task, error) || makeVisible;
@@ -398,14 +402,14 @@ export class ProcessRunnerSystem extends EventEmitter implements ITaskSystem {
398402
}
399403

400404
public log(value: string): void {
401-
this.outputService.append(this.outputChannel, value + '\n');
405+
this.outputService.getOutputChannel(this.outputChannelId).append(value + '\n');
402406
}
403407

404408
private showOutput(): void {
405-
this.outputService.showOutput(this.outputChannel, true);
409+
this.outputService.showOutput(this.outputChannelId, true);
406410
}
407411

408412
private clearOutput(): void {
409-
this.outputService.clearOutput(this.outputChannel);
413+
this.outputService.clearOutput(this.outputChannelId);
410414
}
411415
}

0 commit comments

Comments
 (0)