From 1cd23628b3a09af9475dc8ea5c8cc1f5eef368f5 Mon Sep 17 00:00:00 2001 From: Simon McEnlly Date: Fri, 5 Nov 2021 13:20:39 +1000 Subject: [PATCH] Address some feedback from pull request: https://github.com/microsoft/vscode/pull/136402 --- src/vs/vscode.d.ts | 8 -------- src/vs/vscode.proposed.d.ts | 15 +++++++++++++++ src/vs/workbench/api/common/extHostOutput.ts | 17 ++++++++++++----- .../workbench/api/node/extHostOutputService.ts | 8 ++++---- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 8a2c3fd7f36..49a3c7df912 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -5661,14 +5661,6 @@ declare module 'vscode' { */ clear(): void; - /* - * Replaces the existing contents of the channel with the given value. - * - * *Note*: this method should only be used by extensions with smaller output - * channel text sizes. Use of `append` methods is preferred. - */ - replaceAll(value: string): void; - /** * Reveal this channel in the UI. * diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index b4af49f2c96..244df84bc85 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -2833,4 +2833,19 @@ declare module 'vscode' { } //#endregion + + //#region https://github.com/microsoft/vscode/issues/132183 + export interface OutputChannel { + + /* + * Replaces the existing contents of the channel with the given value. + * + * *Note*: this method should only be used by extensions with smaller output + * channel text sizes. Use of `append` methods is preferred. + */ + replaceAll(value: string): void; + + } + + //#endregion } diff --git a/src/vs/workbench/api/common/extHostOutput.ts b/src/vs/workbench/api/common/extHostOutput.ts index f633e4b1376..b357acffddb 100644 --- a/src/vs/workbench/api/common/extHostOutput.ts +++ b/src/vs/workbench/api/common/extHostOutput.ts @@ -12,6 +12,7 @@ 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'; +import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'; export abstract class AbstractExtHostOutputChannel extends Disposable implements vscode.OutputChannel { @@ -20,18 +21,20 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements protected readonly _proxy: MainThreadOutputServiceShape; private _disposed: boolean; private _offset: number; + private _extension: IExtensionDescription | undefined; protected readonly _onDidAppend: Emitter = this._register(new Emitter()); readonly onDidAppend: Event = this._onDidAppend.event; - constructor(name: string, log: boolean, file: URI | undefined, extensionId: string | undefined, proxy: MainThreadOutputServiceShape) { + constructor(name: string, log: boolean, file: URI | undefined, extension: IExtensionDescription | undefined, proxy: MainThreadOutputServiceShape) { super(); this._name = name; this._proxy = proxy; - this._id = proxy.$register(this.name, log, file, extensionId); + this._id = proxy.$register(this.name, log, file, extension?.identifier.value); this._disposed = false; this._offset = 0; + this._extension = extension; } get name(): string { @@ -59,6 +62,10 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements } replaceAll(value: string): void { + if (this._extension) { + checkProposedApiEnabled(this._extension); + } + this.validate(); const till = this._offset; this._offset += value ? VSBuffer.fromString(value).byteLength : 0; @@ -94,8 +101,8 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel { - constructor(name: string, extensionId: string, proxy: MainThreadOutputServiceShape) { - super(name, false, undefined, extensionId, proxy); + constructor(name: string, extension: IExtensionDescription, proxy: MainThreadOutputServiceShape) { + super(name, false, undefined, extension, proxy); } override append(value: string): void { @@ -164,7 +171,7 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape { if (!name) { throw new Error('illegal argument `name`. must not be falsy'); } - return new ExtHostPushOutputChannel(name, extension.identifier.value, this._proxy); + return new ExtHostPushOutputChannel(name, extension, this._proxy); } createOutputChannelFromLogFile(name: string, file: URI): vscode.OutputChannel { diff --git a/src/vs/workbench/api/node/extHostOutputService.ts b/src/vs/workbench/api/node/extHostOutputService.ts index fdec4a891ee..471b92a40d4 100644 --- a/src/vs/workbench/api/node/extHostOutputService.ts +++ b/src/vs/workbench/api/node/extHostOutputService.ts @@ -44,8 +44,8 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel { private _appender: OutputAppender; - constructor(name: string, appender: OutputAppender, extensionId: string, proxy: MainThreadOutputServiceShape) { - super(name, false, URI.file(appender.file), extensionId, proxy); + constructor(name: string, appender: OutputAppender, extension: IExtensionDescription, proxy: MainThreadOutputServiceShape) { + super(name, false, URI.file(appender.file), extension, proxy); this._appender = appender; } @@ -122,11 +122,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.identifier.value, this._proxy); + return new ExtHostOutputChannelBackedByFile(name, appender, extension, this._proxy); } catch (error) { // Do not crash if logger cannot be created this.logService.error(error); - return new ExtHostPushOutputChannel(name, extension.identifier.value, this._proxy); + return new ExtHostPushOutputChannel(name, extension, this._proxy); } } }