This commit is contained in:
Sandeep Somavarapu
2021-07-06 11:57:15 +02:00
parent 3918b3e0fe
commit b38186b046
6 changed files with 30 additions and 19 deletions

View File

@@ -17,6 +17,7 @@ import { IViewsService } from 'vs/workbench/common/views';
export class MainThreadOutputService extends Disposable implements MainThreadOutputServiceShape {
private static _idPool = 1;
private static _extensionIdPool = new Map<string, number>();
private readonly _proxy: ExtHostOutputServiceShape;
private readonly _outputService: IOutputService;
@@ -41,8 +42,16 @@ export class MainThreadOutputService extends Disposable implements MainThreadOut
setVisibleChannel();
}
public $register(label: string, log: boolean, file?: UriComponents): Promise<string> {
const id = 'extension-output-#' + (MainThreadOutputService._idPool++);
public $register(label: string, log: boolean, file?: UriComponents, extensionId?: string): Promise<string> {
let id: string;
if (extensionId) {
const idCounter = (MainThreadOutputService._extensionIdPool.get(extensionId) || 0) + 1;
MainThreadOutputService._extensionIdPool.set(extensionId, idCounter);
id = `extension-output-${extensionId}-#${idCounter}`;
} else {
id = `extension-output-#${(MainThreadOutputService._idPool++)}`;
}
Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).registerChannel({ id, label, file: file ? URI.revive(file) : undefined, log });
this._register(toDisposable(() => this.$dispose(id)));
return Promise.resolve(id);

View File

@@ -632,7 +632,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostProgress.withProgress(extension, options, task);
},
createOutputChannel(name: string): vscode.OutputChannel {
return extHostOutputService.createOutputChannel(name);
return extHostOutputService.createOutputChannel(name, extension);
},
createWebviewPanel(viewType: string, title: string, showOptions: vscode.ViewColumn | { viewColumn: vscode.ViewColumn, preserveFocus?: boolean }, options?: vscode.WebviewPanelOptions & vscode.WebviewOptions): vscode.WebviewPanel {
return extHostWebviewPanels.createWebviewPanel(extension, viewType, title, showOptions, options);

View File

@@ -433,7 +433,7 @@ export interface MainThreadMessageServiceShape extends IDisposable {
}
export interface MainThreadOutputServiceShape extends IDisposable {
$register(label: string, log: boolean, file?: UriComponents): Promise<string>;
$register(label: string, log: boolean, file?: UriComponents, extensionId?: string): Promise<string>;
$append(channelId: string, value: string): Promise<void> | undefined;
$update(channelId: string): Promise<void> | undefined;
$clear(channelId: string, till: number): Promise<void> | undefined;

View File

@@ -11,6 +11,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { VSBuffer } from 'vs/base/common/buffer';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
export abstract class AbstractExtHostOutputChannel extends Disposable implements vscode.OutputChannel {
@@ -23,12 +24,12 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
protected readonly _onDidAppend: Emitter<void> = this._register(new Emitter<void>());
readonly onDidAppend: Event<void> = this._onDidAppend.event;
constructor(name: string, log: boolean, file: URI | undefined, proxy: MainThreadOutputServiceShape) {
constructor(name: string, log: boolean, file: URI | undefined, extensionId: string | undefined, proxy: MainThreadOutputServiceShape) {
super();
this._name = name;
this._proxy = proxy;
this._id = proxy.$register(this.name, log, file);
this._id = proxy.$register(this.name, log, file, extensionId);
this._disposed = false;
this._offset = 0;
}
@@ -86,8 +87,8 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {
constructor(name: string, proxy: MainThreadOutputServiceShape) {
super(name, false, undefined, proxy);
constructor(name: string, extensionId: string, proxy: MainThreadOutputServiceShape) {
super(name, false, undefined, extensionId, proxy);
}
override append(value: string): void {
@@ -100,7 +101,7 @@ export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {
class ExtHostLogFileOutputChannel extends AbstractExtHostOutputChannel {
constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
super(name, true, file, proxy);
super(name, true, file, undefined, proxy);
}
override append(value: string): void {
@@ -148,12 +149,12 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
$setVisibleChannel(channelId: string): void {
}
createOutputChannel(name: string): vscode.OutputChannel {
createOutputChannel(name: string, extension: IExtensionDescription): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
}
return new ExtHostPushOutputChannel(name, this._proxy);
return new ExtHostPushOutputChannel(extension.identifier.value, name, this._proxy);
}
createOutputChannelFromLogFile(name: string, file: URI): vscode.OutputChannel {

View File

@@ -17,6 +17,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { createRotatingLogger } from 'vs/platform/log/node/spdlogLog';
import { Logger } from 'spdlog';
import { ByteSize } from 'vs/platform/files/common/files';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
class OutputAppender {
@@ -43,8 +44,8 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
private _appender: OutputAppender;
constructor(name: string, appender: OutputAppender, proxy: MainThreadOutputServiceShape) {
super(name, false, URI.file(appender.file), proxy);
constructor(name: string, appender: OutputAppender, extensionId: string, proxy: MainThreadOutputServiceShape) {
super(name, false, URI.file(appender.file), extensionId, proxy);
this._appender = appender;
}
@@ -95,17 +96,17 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
}
}
override createOutputChannel(name: string): vscode.OutputChannel {
override createOutputChannel(name: string, extension: IExtensionDescription): vscode.OutputChannel {
name = name.trim();
if (!name) {
throw new Error('illegal argument `name`. must not be falsy');
}
const extHostOutputChannel = this._doCreateOutChannel(name);
const extHostOutputChannel = this._doCreateOutChannel(name, extension);
extHostOutputChannel.then(channel => channel._id.then(id => this._channels.set(id, channel)));
return new LazyOutputChannel(name, extHostOutputChannel);
}
private async _doCreateOutChannel(name: string): Promise<AbstractExtHostOutputChannel> {
private async _doCreateOutChannel(name: string, extension: IExtensionDescription): Promise<AbstractExtHostOutputChannel> {
try {
const outputDirPath = join(this._logsLocation.fsPath, `output_logging_${toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '')}`);
const exists = await SymlinkSupport.existsDirectory(outputDirPath);
@@ -115,11 +116,11 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
const fileName = `${this._namePool++}-${name.replace(/[\\/:\*\?"<>\|]/g, '')}`;
const file = URI.file(join(outputDirPath, `${fileName}.log`));
const appender = await OutputAppender.create(fileName, file.fsPath);
return new ExtHostOutputChannelBackedByFile(name, appender, this._proxy);
return new ExtHostOutputChannelBackedByFile(name, appender, extension.identifier.value, this._proxy);
} catch (error) {
// Do not crash if logger cannot be created
this.logService.error(error);
return new ExtHostPushOutputChannel(name, this._proxy);
return new ExtHostPushOutputChannel(name, extension.identifier.value, this._proxy);
}
}
}