mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
- Do not send replace content from ext host
- implement replaceAll in the model - cancel all model update operations on replace request - queue append operation after replace - clean ups
This commit is contained in:
@@ -447,7 +447,7 @@ export interface MainThreadOutputServiceShape extends IDisposable {
|
||||
$append(channelId: string, value: string): Promise<void> | undefined;
|
||||
$update(channelId: string): Promise<void> | undefined;
|
||||
$clear(channelId: string, till: number): Promise<void> | undefined;
|
||||
$replaceAll(channelId: string, till: number, value: string): Promise<void> | undefined;
|
||||
$replaceAll(channelId: string, till: number, value?: string): Promise<void> | undefined;
|
||||
$reveal(channelId: string, preserveFocus: boolean): Promise<void> | undefined;
|
||||
$close(channelId: string): Promise<void> | undefined;
|
||||
$dispose(channelId: string): Promise<void> | undefined;
|
||||
|
||||
@@ -6,14 +6,12 @@
|
||||
import { MainContext, MainThreadOutputServiceShape, ExtHostOutputServiceShape } from './extHost.protocol';
|
||||
import type * as vscode from 'vscode';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
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';
|
||||
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
|
||||
|
||||
export abstract class AbstractExtHostOutputChannel extends Disposable implements vscode.OutputChannel {
|
||||
|
||||
@@ -22,17 +20,16 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
|
||||
protected readonly _proxy: MainThreadOutputServiceShape;
|
||||
private _disposed: boolean;
|
||||
private _offset: number;
|
||||
private _extension: IExtensionDescription;
|
||||
private readonly _extension: IExtensionDescription;
|
||||
|
||||
protected readonly _onDidAppend: Emitter<void> = this._register(new Emitter<void>());
|
||||
readonly onDidAppend: Event<void> = this._onDidAppend.event;
|
||||
public visible: boolean = false;
|
||||
|
||||
constructor(name: string, log: boolean, file: URI | undefined, extension: IExtensionDescription, proxy: MainThreadOutputServiceShape) {
|
||||
super();
|
||||
|
||||
this._name = name;
|
||||
this._proxy = proxy;
|
||||
this._id = proxy.$register(this.name, log, file, extension?.identifier.value);
|
||||
this._id = proxy.$register(this.name, log, file, extension.identifier.value);
|
||||
this._disposed = false;
|
||||
this._offset = 0;
|
||||
this._extension = extension;
|
||||
@@ -44,11 +41,7 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
|
||||
|
||||
append(value: string): void {
|
||||
this.validate();
|
||||
this._offset += value ? VSBuffer.fromString(value).byteLength : 0;
|
||||
}
|
||||
|
||||
update(): void {
|
||||
this._id.then(id => this._proxy.$update(id));
|
||||
this.incrementOffset(value);
|
||||
}
|
||||
|
||||
appendLine(value: string): void {
|
||||
@@ -62,13 +55,11 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
|
||||
this._id.then(id => this._proxy.$clear(id, till));
|
||||
}
|
||||
|
||||
replaceAll(value: string): void {
|
||||
checkProposedApiEnabled(this._extension);
|
||||
|
||||
this.validate();
|
||||
replaceAll(value: string, donotSendValue?: boolean): void {
|
||||
this.validate(true);
|
||||
const till = this._offset;
|
||||
this._offset += value ? VSBuffer.fromString(value).byteLength : 0;
|
||||
this._id.then(id => this._proxy.$replaceAll(id, till, value));
|
||||
this.incrementOffset(value);
|
||||
this._id.then(id => this._proxy.$replaceAll(id, till, donotSendValue ? undefined : value));
|
||||
}
|
||||
|
||||
show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
|
||||
@@ -81,12 +72,19 @@ export abstract class AbstractExtHostOutputChannel extends Disposable implements
|
||||
this._id.then(id => this._proxy.$close(id));
|
||||
}
|
||||
|
||||
protected validate(): void {
|
||||
protected validate(checkProposedApi?: boolean): void {
|
||||
if (checkProposedApi) {
|
||||
checkProposedApiEnabled(this._extension);
|
||||
}
|
||||
if (this._disposed) {
|
||||
throw new Error('Channel has been closed');
|
||||
}
|
||||
}
|
||||
|
||||
private incrementOffset(value: string) {
|
||||
this._offset += value ? VSBuffer.fromString(value).byteLength : 0;
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
super.dispose();
|
||||
|
||||
@@ -107,19 +105,9 @@ export class ExtHostPushOutputChannel extends AbstractExtHostOutputChannel {
|
||||
override append(value: string): void {
|
||||
super.append(value);
|
||||
this._id.then(id => this._proxy.$append(id, value));
|
||||
this._onDidAppend.fire();
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostLogFileOutputChannel extends AbstractExtHostOutputChannel {
|
||||
|
||||
constructor(name: string, file: URI, proxy: MainThreadOutputServiceShape) {
|
||||
super(name, true, file, nullExtensionDescription, proxy);
|
||||
}
|
||||
|
||||
override append(value: string): void {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class LazyOutputChannel implements vscode.OutputChannel {
|
||||
@@ -173,16 +161,6 @@ export class ExtHostOutputService implements ExtHostOutputServiceShape {
|
||||
return new ExtHostPushOutputChannel(name, extension, this._proxy);
|
||||
}
|
||||
|
||||
createOutputChannelFromLogFile(name: string, file: URI): vscode.OutputChannel {
|
||||
name = name.trim();
|
||||
if (!name) {
|
||||
throw new Error('illegal argument `name`. must not be falsy');
|
||||
}
|
||||
if (!file) {
|
||||
throw new Error('illegal argument `file`. must not be falsy');
|
||||
}
|
||||
return new ExtHostLogFileOutputChannel(name, file, this._proxy);
|
||||
}
|
||||
}
|
||||
|
||||
export interface IExtHostOutputService extends ExtHostOutputService { }
|
||||
|
||||
@@ -12,7 +12,6 @@ import { Promises, SymlinkSupport } from 'vs/base/node/pfs';
|
||||
import { AbstractExtHostOutputChannel, ExtHostPushOutputChannel, ExtHostOutputService, LazyOutputChannel } from 'vs/workbench/api/common/extHostOutput';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { MutableDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { createRotatingLogger } from 'vs/platform/log/node/spdlogLog';
|
||||
import { Logger } from 'spdlog';
|
||||
@@ -52,18 +51,17 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
|
||||
override append(value: string): void {
|
||||
super.append(value);
|
||||
this._appender.append(value);
|
||||
this._onDidAppend.fire();
|
||||
if (this.visible) {
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
override replaceAll(value: string): void {
|
||||
super.replaceAll(value, true);
|
||||
this._appender.append(value);
|
||||
this._appender.flush();
|
||||
super.replaceAll(value);
|
||||
}
|
||||
|
||||
override update(): void {
|
||||
this._appender.flush();
|
||||
super.update();
|
||||
if (this.visible) {
|
||||
this._appender.flush();
|
||||
}
|
||||
}
|
||||
|
||||
override show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
|
||||
@@ -75,6 +73,11 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
|
||||
this._appender.flush();
|
||||
super.clear();
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
this._appender.flush();
|
||||
this._id.then(id => this._proxy.$update(id));
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
@@ -82,7 +85,8 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
private _logsLocation: URI;
|
||||
private _namePool: number = 1;
|
||||
private readonly _channels: Map<string, AbstractExtHostOutputChannel> = new Map<string, AbstractExtHostOutputChannel>();
|
||||
private readonly _visibleChannelDisposable = new MutableDisposable();
|
||||
|
||||
private visibleChannelId: string | null = null;
|
||||
|
||||
constructor(
|
||||
@IExtHostRpcService extHostRpc: IExtHostRpcService,
|
||||
@@ -93,12 +97,10 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
this._logsLocation = initData.logsLocation;
|
||||
}
|
||||
|
||||
override $setVisibleChannel(channelId: string): void {
|
||||
if (channelId) {
|
||||
const channel = this._channels.get(channelId);
|
||||
if (channel) {
|
||||
this._visibleChannelDisposable.value = channel.onDidAppend(() => channel.update());
|
||||
}
|
||||
override $setVisibleChannel(visibleChannelId: string | null): void {
|
||||
this.visibleChannelId = visibleChannelId;
|
||||
for (const [id, channel] of this._channels) {
|
||||
channel.visible = id === this.visibleChannelId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +110,10 @@ export class ExtHostOutputService2 extends ExtHostOutputService {
|
||||
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)));
|
||||
extHostOutputChannel.then(channel => channel._id.then(id => {
|
||||
this._channels.set(id, channel);
|
||||
channel.visible = id === this.visibleChannelId;
|
||||
}));
|
||||
return new LazyOutputChannel(name, extHostOutputChannel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user