mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
#132183 clean up
- Use FileOutputChannelModel for OutputChannelBackedByFile - Rename replaceAll to replace - simplify exthost output service and channel impl - enhance update api
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { ExtHostOutputService2 } from 'vs/workbench/api/node/extHostOutputService';
|
||||
import { ExtHostOutputService } from 'vs/workbench/api/node/extHostOutputService';
|
||||
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService';
|
||||
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
|
||||
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
|
||||
@@ -34,7 +34,7 @@ registerSingleton(ILogService, ExtHostLogService);
|
||||
registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths);
|
||||
|
||||
registerSingleton(IExtHostDebugService, ExtHostDebugService);
|
||||
registerSingleton(IExtHostOutputService, ExtHostOutputService2);
|
||||
registerSingleton(IExtHostOutputService, ExtHostOutputService);
|
||||
registerSingleton(IExtHostSearch, NativeExtHostSearch);
|
||||
registerSingleton(IExtHostTask, ExtHostTask);
|
||||
registerSingleton(IExtHostTerminalService, ExtHostTerminalService);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { URI } from 'vs/base/common/uri';
|
||||
import { join } from 'vs/base/common/path';
|
||||
import { toLocalISOString } from 'vs/base/common/date';
|
||||
import { Promises, SymlinkSupport } from 'vs/base/node/pfs';
|
||||
import { AbstractExtHostOutputChannel, ExtHostPushOutputChannel, ExtHostOutputService, LazyOutputChannel } from 'vs/workbench/api/common/extHostOutput';
|
||||
import { AbstractExtHostOutputChannel, ExtHostOutputService as BaseExtHostOutputService } from 'vs/workbench/api/common/extHostOutput';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
@@ -17,6 +17,8 @@ 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';
|
||||
import { OutputChannelUpdateMode } from 'vs/workbench/contrib/output/common/output';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
class OutputAppender {
|
||||
|
||||
@@ -41,23 +43,34 @@ class OutputAppender {
|
||||
|
||||
class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
|
||||
|
||||
private _appender: OutputAppender;
|
||||
private _offset: number;
|
||||
private readonly _appender: OutputAppender;
|
||||
|
||||
constructor(name: string, appender: OutputAppender, extension: IExtensionDescription, proxy: MainThreadOutputServiceShape) {
|
||||
super(name, false, URI.file(appender.file), extension, proxy);
|
||||
constructor(name: string, appender: OutputAppender, extensionId: string, proxy: MainThreadOutputServiceShape) {
|
||||
super(name, false, URI.file(appender.file), extensionId, proxy);
|
||||
this._offset = 0;
|
||||
this._appender = appender;
|
||||
}
|
||||
|
||||
override append(value: string): void {
|
||||
super.append(value);
|
||||
append(value: string): void {
|
||||
this.incrementOffset(value);
|
||||
this._appender.append(value);
|
||||
if (this.visible) {
|
||||
this.update();
|
||||
this._appender.flush();
|
||||
this._id.then(id => this._proxy.$update(id, OutputChannelUpdateMode.Append));
|
||||
}
|
||||
}
|
||||
|
||||
override replaceAll(value: string): void {
|
||||
super.replaceAll(value, true);
|
||||
clear(): void {
|
||||
const till = this._offset;
|
||||
this._appender.flush();
|
||||
this._id.then(id => this._proxy.$update(id, OutputChannelUpdateMode.Clear, till));
|
||||
}
|
||||
|
||||
replace(value: string): void {
|
||||
const till = this._offset;
|
||||
this.incrementOffset(value);
|
||||
this._id.then(id => this._proxy.$update(id, OutputChannelUpdateMode.Replace, till));
|
||||
this._appender.append(value);
|
||||
if (this.visible) {
|
||||
this._appender.flush();
|
||||
@@ -69,24 +82,16 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
|
||||
super.show(columnOrPreserveFocus, preserveFocus);
|
||||
}
|
||||
|
||||
override clear(): void {
|
||||
this._appender.flush();
|
||||
super.clear();
|
||||
private incrementOffset(value: string) {
|
||||
this._offset += VSBuffer.fromString(value).byteLength;
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
this._appender.flush();
|
||||
this._id.then(id => this._proxy.$update(id));
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
export class ExtHostOutputService extends BaseExtHostOutputService {
|
||||
|
||||
private _logsLocation: URI;
|
||||
private _namePool: number = 1;
|
||||
private readonly _channels: Map<string, AbstractExtHostOutputChannel> = new Map<string, AbstractExtHostOutputChannel>();
|
||||
|
||||
private visibleChannelId: string | null = null;
|
||||
|
||||
constructor(
|
||||
@IExtHostRpcService extHostRpc: IExtHostRpcService,
|
||||
@@ -97,27 +102,7 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
this._logsLocation = initData.logsLocation;
|
||||
}
|
||||
|
||||
override $setVisibleChannel(visibleChannelId: string | null): void {
|
||||
this.visibleChannelId = visibleChannelId;
|
||||
for (const [id, channel] of this._channels) {
|
||||
channel.visible = id === this.visibleChannelId;
|
||||
}
|
||||
}
|
||||
|
||||
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, extension);
|
||||
extHostOutputChannel.then(channel => channel._id.then(id => {
|
||||
this._channels.set(id, channel);
|
||||
channel.visible = id === this.visibleChannelId;
|
||||
}));
|
||||
return new LazyOutputChannel(name, extHostOutputChannel);
|
||||
}
|
||||
|
||||
private async _doCreateOutChannel(name: string, extension: IExtensionDescription): Promise<AbstractExtHostOutputChannel> {
|
||||
protected override 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);
|
||||
@@ -127,11 +112,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, extension, 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, extension, this._proxy);
|
||||
}
|
||||
return super.doCreateOutChannel(name, extension);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user