1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/registry/common/platform';
import { IOutputService, IOutputChannel, OUTPUT_VIEW_ID, OutputChannelUpdateMode } from 'vs/workbench/contrib/output/common/output';
import { Extensions, IOutputChannelRegistry } from 'vs/workbench/services/output/common/output';
import { MainThreadOutputServiceShape, MainContext, ExtHostOutputServiceShape, ExtHostContext } from '../common/extHost.protocol';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { UriComponents, URI } from 'vs/base/common/uri';
import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { IViewsService } from 'vs/workbench/common/views';
import { isNumber } from 'vs/base/common/types';
@extHostNamedCustomer(MainContext.MainThreadOutputService)
export class MainThreadOutputService extends Disposable implements MainThreadOutputServiceShape {
private static _extensionIdPool = new Map<string, number>();
private readonly _proxy: ExtHostOutputServiceShape;
private readonly _outputService: IOutputService;
private readonly _viewsService: IViewsService;
constructor(
extHostContext: IExtHostContext,
@IOutputService outputService: IOutputService,
@IViewsService viewsService: IViewsService
) {
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<any>(this._outputService.onActiveOutputChannel, Event.filter(this._viewsService.onDidChangeViewVisibility, ({ id }) => id === OUTPUT_VIEW_ID))(() => setVisibleChannel()));
setVisibleChannel();
}
public async $register(label: string, log: boolean, file: UriComponents, languageId: string, extensionId: string): Promise<string> {
const idCounter = (MainThreadOutputService._extensionIdPool.get(extensionId) || 0) + 1;
MainThreadOutputService._extensionIdPool.set(extensionId, idCounter);
const id = `extension-output-${extensionId}-#${idCounter}`;
Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).registerChannel({ id, label, file: URI.revive(file), log, languageId });
this._register(toDisposable(() => this.$dispose(id)));
return id;
}
public async $update(channelId: string, mode: OutputChannelUpdateMode, till?: number): Promise<void> {
const channel = this._getChannel(channelId);
if (channel) {
if (mode === OutputChannelUpdateMode.Append) {
channel.update(mode);
} else if (isNumber(till)) {
channel.update(mode, till);
}
}
}
public async $reveal(channelId: string, preserveFocus: boolean): Promise<void> {
const channel = this._getChannel(channelId);
if (channel) {
this._outputService.showChannel(channel.id, preserveFocus);
}
}
public async $close(channelId: string): Promise<void> {
if (this._viewsService.isViewVisible(OUTPUT_VIEW_ID)) {
const activeChannel = this._outputService.getActiveChannel();
if (activeChannel && channelId === activeChannel.id) {
this._viewsService.closeView(OUTPUT_VIEW_ID);
}
}
}
public async $dispose(channelId: string): Promise<void> {
const channel = this._getChannel(channelId);
if (channel) {
channel.dispose();
}
}
private _getChannel(channelId: string): IOutputChannel | undefined {
return this._outputService.getChannel(channelId);
}
}
|