Skip to content

Commit 6cb2531

Browse files
committed
Exthost Output channels: generate id on the renderer side
1 parent 744e89f commit 6cb2531

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/vs/workbench/api/electron-browser/mainThreadOutputService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { UriComponents, URI } from 'vs/base/common/uri';
1616
@extHostNamedCustomer(MainContext.MainThreadOutputService)
1717
export class MainThreadOutputService implements MainThreadOutputServiceShape {
1818

19+
private static _idPool = 1;
20+
1921
private readonly _outputService: IOutputService;
2022
private readonly _partService: IPartService;
2123
private readonly _panelService: IPanelService;
@@ -35,9 +37,10 @@ export class MainThreadOutputService implements MainThreadOutputServiceShape {
3537
// Leave all the existing channels intact (e.g. might help with troubleshooting)
3638
}
3739

38-
public $register(id: string, label: string, file?: UriComponents): TPromise<void> {
40+
public $register(label: string, file?: UriComponents): TPromise<string> {
41+
const id = 'extension-output-#' + (MainThreadOutputService._idPool++);
3942
Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).registerChannel({ id, label, file: file ? URI.revive(file) : null, log: false });
40-
return TPromise.as(null);
43+
return TPromise.as(id);
4144
}
4245

4346
public $append(channelId: string, value: string): TPromise<void> {

src/vs/workbench/api/node/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ export interface MainThreadMessageServiceShape extends IDisposable {
301301
}
302302

303303
export interface MainThreadOutputServiceShape extends IDisposable {
304-
$register(channelId: string, label: string, file?: UriComponents): Thenable<void>;
304+
$register(label: string, file?: UriComponents): Thenable<string>;
305305
$append(channelId: string, value: string): Thenable<void>;
306306
$clear(channelId: string): Thenable<void>;
307307
$reveal(channelId: string, preserveFocus: boolean): Thenable<void>;

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@ import * as vscode from 'vscode';
99
import { URI } from 'vs/base/common/uri';
1010
import { posix } from 'path';
1111
import { OutputAppender } from 'vs/platform/output/node/outputAppender';
12-
import { TPromise } from 'vs/base/common/winjs.base';
1312

1413
export abstract class AbstractExtHostOutputChannel implements vscode.OutputChannel {
1514

16-
private static _idPool = 1;
17-
18-
protected readonly _id: string;
15+
protected readonly _id: Thenable<string>;
1916
private readonly _name: string;
2017
protected readonly _proxy: MainThreadOutputServiceShape;
21-
protected _registerationPromise: Thenable<void> = TPromise.as(null);
2218
private _disposed: boolean;
2319

24-
constructor(name: string, proxy: MainThreadOutputServiceShape) {
25-
this._id = 'extension-output-#' + (AbstractExtHostOutputChannel._idPool++);
20+
constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
2621
this._name = name;
2722
this._proxy = proxy;
23+
this._id = proxy.$register(this.name, file);
2824
}
2925

3026
get name(): string {
@@ -40,17 +36,17 @@ export abstract class AbstractExtHostOutputChannel implements vscode.OutputChann
4036

4137
clear(): void {
4238
this.validate();
43-
this._registerationPromise.then(() => this._proxy.$clear(this._id));
39+
this._id.then(id => this._proxy.$clear(id));
4440
}
4541

4642
show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
4743
this.validate();
48-
this._registerationPromise.then(() => this._proxy.$reveal(this._id, typeof columnOrPreserveFocus === 'boolean' ? columnOrPreserveFocus : preserveFocus));
44+
this._id.then(id => this._proxy.$reveal(id, typeof columnOrPreserveFocus === 'boolean' ? columnOrPreserveFocus : preserveFocus));
4945
}
5046

5147
hide(): void {
5248
this.validate();
53-
this._registerationPromise.then(() => this._proxy.$close(this._id));
49+
this._id.then(id => this._proxy.$close(id));
5450
}
5551

5652
protected validate(): void {
@@ -61,8 +57,8 @@ export abstract class AbstractExtHostOutputChannel implements vscode.OutputChann
6157

6258
dispose(): void {
6359
if (!this._disposed) {
64-
this._registerationPromise
65-
.then(() => this._proxy.$dispose(this._id))
60+
this._id
61+
.then(id => this._proxy.$dispose(id))
6662
.then(() => this._disposed = true);
6763
}
6864
}
@@ -71,26 +67,26 @@ export abstract class AbstractExtHostOutputChannel implements vscode.OutputChann
7167
export class ExtHostOutputChannel extends AbstractExtHostOutputChannel {
7268

7369
constructor(name: string, proxy: MainThreadOutputServiceShape) {
74-
super(name, proxy);
75-
this._registerationPromise = proxy.$register(this._id, name);
70+
super(name, null, proxy);
7671
}
7772

7873
append(value: string): void {
7974
this.validate();
80-
this._registerationPromise.then(() => this._proxy.$append(this._id, value));
75+
this._id.then(id => this._proxy.$append(id, value));
8176
}
8277
}
8378

8479
export class ExtHostLoggingOutputChannel extends AbstractExtHostOutputChannel {
8580

81+
private static _namePool = 1;
8682
private _appender: OutputAppender;
8783

8884
constructor(name: string, outputDir: string, proxy: MainThreadOutputServiceShape) {
89-
super(name, proxy);
90-
const file = URI.file(posix.join(outputDir, `${this._id}.log`));
91-
this._appender = new OutputAppender(this._id, file.fsPath);
92-
this._registerationPromise = proxy.$register(this._id, this.name, file);
85+
const fileName = `${ExtHostLoggingOutputChannel._namePool++}-${name}`;
86+
const file = URI.file(posix.join(outputDir, `${fileName}.log`));
9387

88+
super(name, file, proxy);
89+
this._appender = new OutputAppender(fileName, file.fsPath);
9490
}
9591

9692
append(value: string): void {

0 commit comments

Comments
 (0)